range

Selection ranges in webkit (Safari/Chrome)

。_饼干妹妹 提交于 2019-11-30 07:18:58
I'm using a content-editable iframe to create a syntax-highlighter in javascript and one of the most important things is to be able to indent code properly. The following code works just as it should in Firefox: // Create one indent character var range = window.getSelection().getRangeAt(0); var newTextNode = document.createTextNode(Language.tabChar); range.insertNode(newTextNode); range.setStartAfter(newTextNode); It creates a tab char and moves the cursor to the right side of the character. In Chrome and Safari a character is inserted but the cursor won't move to the right of it. I inspected

Python: IndexError: list index out of range

不打扰是莪最后的温柔 提交于 2019-11-30 07:01:13
问题 I think I have my program completed, but... it doesn't work. I'm trying to write a program that simulates a lottery game, but when I try to check the user's guesses against the number of guesses on the ticket, I get an error that tells me the "list index is out of range". I think it has something to do with the part of the code where I assign the random digits to "a," "b", "c", etc. But I'm not sure. Here is the code in it's entirety: import random def main(): random.seed() #Prompts the user

Remove consecutive duplicates from dataframe

岁酱吖の 提交于 2019-11-30 06:49:34
I have a data frame that I want to remove duplicates that are consecutive (in base). I know rle may be helpful here but can't think of how to use it. The example output will help to illuminate what I'm asking for. Generate sample data: set.seed(12) samps <- sample(1:5, 20, T) dat <- data.frame(v1=LETTERS[samps], v2=month.abb[samps]) dat[10, 2] <- "Mar" Sample data: v1 v2 1 A Jan 2 E May 3 E May 4 B Feb 5 A Jan 6 A Jan 7 A Jan 8 D Apr 9 A Jan 10 A Mar 11 B Feb 12 E May 13 B Feb 14 B Feb 15 B Feb 16 C Mar 17 C Mar 18 C Mar 19 D Apr 20 A Jan Desired outcome: v1 v2 1 A Jan 3 E May 4 B Feb 7 A Jan

Count the number of Ks between 0 and N

心不动则不痛 提交于 2019-11-30 06:22:49
问题 Problem: I have seen questions like: count the number of 0s between 0 and N? count the number of 1s between 0 and N? count the number of 2s between 0 and N? ... ... These kinds of questions are very similar of asking to find the total number that Ks (i.e. K=0,1,2,...,9) are shown in number range [0, N] . Example: Input: K=2, N=35 Output: 14 Detail: list of 2 s between [0,35] : 2, 12, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 32 , note that 22 will be counted as twice (as 22 contains two 2 s)

boost::range::join for multiple ranges

跟風遠走 提交于 2019-11-30 04:57:16
I want to do the following: std::vector<int> a = {1,2,3}, b = {4,5,6}, c = {7,8,9}; for(auto&& i : join(a,b,c)) { i += 1 std::cout << i; // -> 2345678910 } I tried using boost::range::join , this works fine: auto r = boost::join(a,b); for(auto&& i : boost::join(r,c)) { i += 1; std::cout << i; // -> 2345678910 } Chaining joins, reading operations work: for(auto&& i : boost::join(boost::join(a,b),c)) std::cout << i; // -> 123456789 However , writing doesn't work: for(auto&& i : boost::join(boost::join(a,b),c)) { i += 1; // Fails :( std::cout << i; } My variadic join has the same problem, i.e.

How to select values within a provided index range from a List using LINQ

試著忘記壹切 提交于 2019-11-30 04:36:55
I am a LINQ newbie trying to use it to acheive the following: I have a list of ints:- List<int> intList = new List<int>(new int[]{1,2,3,3,2,1}); Now, I want to compare the sum of the first three elements [index range 0-2] with the last three [index range 3-5] using LINQ. I tried the LINQ Select and Take extension methods as well as the SelectMany method, but I cannot figure out how to say something like (from p in intList where p in Take contiguous elements of intList from index x to x+n select p).sum() I looked at the Contains extension method too, but that doesn't see to get me what I want.

How should I handle inclusive ranges in Python?

只愿长相守 提交于 2019-11-30 04:12:17
I am working in a domain in which ranges are conventionally described inclusively. I have human-readable descriptions such as from A to B , which represent ranges that include both end points - e.g. from 2 to 4 means 2, 3, 4 . What is the best way to work with these ranges in Python code? The following code works to generate inclusive ranges of integers, but I also need to perform inclusive slice operations: def inclusive_range(start, stop, step): return range(start, (stop + 1) if step >= 0 else (stop - 1), step) The only complete solution I see is to explicitly use + 1 (or - 1 ) every time I

jquery slider, time picker and reserved times..

耗尽温柔 提交于 2019-11-30 04:00:52
问题 I am using a jquery slider to pick a start and end time That is fine, but I need to add restrictions to it. Basically, I've got a window of availability that I need to chip away at. So in my example: http://madeeasyfor.me/stackoverflow/time_pick_test_1.html (I've commented the validation function so you can see the slider, the code has absolute paths to all scripts so feel free to get a view source dump for local use) I've got a 24 clock. With a dynamically generated PHP script, I want to add

Subtract Overlaps Between Two Ranges Without Sets

百般思念 提交于 2019-11-30 04:00:06
NO SETS! I can't use Sets because: The ranges will be too long. They will take up too much memory The creation of the sets themselves will take too long. Using only the endpoints of the of the ranges, is there an optimal way to subtract two lists of ranges? Example: r1 = (1, 1000), (1100, 1200) r2 = (30, 50), (60, 200), (1150, 1300) r1 - r2 = (1, 29), (51, 59), (201, 1000), (1100, 1149) Other info: r2 does not have to overlap r1 r1 and r2 will not have pairs that overlap other pairs. For instance, r1 will not have both (0,30) and (10, 25) Thanks. The interval package may provide all that you

Add element before/after text selection

落花浮王杯 提交于 2019-11-30 03:30:36
问题 I'm looking for function which allows me to build some element before or after selected text. Something similar like this one javascript replace selection all browsers but for adding some content before or after selection instead of replacing it, like after() and before() jQuery methods. Should I use some DOM selection method, if yes which one? Or does exist something easier to carry it out? 回答1: Here's a pair of functions to do this. Live example: http://jsfiddle.net/hjfVw/ Code: var