range

How do I create a range object when I know just the character offsets?

守給你的承諾、 提交于 2019-11-29 00:52:18
问题 So I have a div that contains a block of text, previously the user has selected some text in this block and I created a range object from this selection. I stored the offset of the selected text's starting and ending points but I am having problems re-creating the range (so i can manipulate it). "quotables" is the div that holds all the text. I dont know what I am doing wrong. var theRange = rangy.createRange(); var node = $('.quotables').html(); theRange.setStart(node, 14); theRange.setEnd

What is the easiest way to generate random integers within a range in Swift?

让人想犯罪 __ 提交于 2019-11-28 23:09:15
The method I've devised so far is this: func randRange (lower : Int , upper : Int) -> Int { let difference = upper - lower return Int(Float(rand())/Float(RAND_MAX) * Float(difference + 1)) + lower } This generates random integers between lower and upper inclusive. Here's a somewhat lighter version of it: func randRange (lower: Int , upper: Int) -> Int { return lower + Int(arc4random_uniform(UInt32(upper - lower + 1))) } This can be simplified even further if you decide this function works with unsigned values only: func randRange (lower: UInt32 , upper: UInt32) -> UInt32 { return lower +

How to find whether a number belongs to a particular range in Python? [duplicate]

大城市里の小女人 提交于 2019-11-28 22:21:09
This question already has an answer here: Determine Whether Integer Is Between Two Other Integers? 8 answers Suppose I want to check if x belongs to range 0 to 0.5. How can I do it? No, you can't do that. range() expects integer arguments. If you want to know if x is inside this range try some form of this: print 0.0 <= x <= 0.5 Be careful with your upper limit. If you use range() it is excluded ( range(0, 5) does not include 5!) print 'yes' if 0 < x < 0.5 else 'no' range() is for generating arrays of consecutive integers >>> s = 1.1 >>> 0<= s <=0.2 False >>> 0<= s <=1.2 True I would use the

Can't restore selection after HTML modify, even if it's the same HTML

試著忘記壹切 提交于 2019-11-28 22:05:18
I'm trying to store a selection of a contentEditable element and restore it later. I want to observe the paste event and store the HTML as it was before, clear the html and then manually insert the pasted text with some changes at the selected position. Take a look at this example: jsfiddle.net/gEhjZ When you select a part of the text, hit store , remove the selection again and hit restore , it's working as expected. But when you first hit store , then replace the HTML with the exact same HTML by hitting overwrite html and then try to restore , nothing happens. I thought that using .cloneRange

How to wrap around a range

旧巷老猫 提交于 2019-11-28 19:23:27
Angles in my program are expressed in 0 to 2pi. I want a way to add two angles and have it wrap around the 2pi to 0 if the result is higher than 2pi. Or if I subtracted an angle from an angle and it was below 0 it would wrap around 2pi. Is there a way to do this? Thanks. What you are looking for is the modulus. The fmod function will not work because it calculates the remainder and not the arithmetic modulus. Something like this should work: inline double wrapAngle( double angle ) { double twoPi = 2.0 * 3.141592865358979; return angle - twoPi * floor( angle / twoPi ); } Edit: The remainder is

Excel VBA - select a dynamic cell range

不想你离开。 提交于 2019-11-28 18:02:52
I want to be able to dynamically select a range of cells (the heading row), where the row is 1 but the columns with be for 1 to last column, where "A" is the first Column and where "M" is the last column. I know how to find the last column, but I don't know how to modified the below range to input the first and last column as "A" and "M". Range("A1:M1").Select If you want to select a variable range containing all headers cells: Dim sht as WorkSheet Set sht = This Workbook.Sheets("Data") 'Range(Cells(1,1),Cells(1,Columns.Count).End(xlToLeft)).Select '<<< NOT ROBUST sht.Range(sht.Cells(1,1),sht

Count the number of Ks between 0 and N

巧了我就是萌 提交于 2019-11-28 17:39:56
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) What we have: There are solutions for each of them (available if you search for it). Usually, O(log N)

Vim yanking range of lines

心不动则不痛 提交于 2019-11-28 16:15:35
问题 I'm a C# developer who has just recently decided to expand my knowledge of the tools available to me. The first tool I've decided to learn is Vi/Vim. Everything has been going well so far, but there are a couple of questions I can't seem to find the answer to: Lets say I wanted to yank a range of lines. I know there are many ways of doing so, but I would like to do it by line number. I figured it would be similar to how the substitute commands work, something like 81,91y . Is there a way to

Select range of lines in Notepad++

▼魔方 西西 提交于 2019-11-28 16:14:04
问题 Is there a way to select range of lines in Notepad++? I would like to write two numbers - from and to, say: from 10000 to 25000. I've got this large MySQL dump file and I can select it only by using some function. 回答1: Easiest way: Ctrl + G , go to line 10,000. Menu > Edit > Begin/End select . Ctrl + G , go to line 25,000. Menu > Edit > Begin/End select . You now have your range selected. Or, simply right click for "Begin/End select" option. 回答2: I was trying to figure the same thing out

built-in range or numpy.arange: which is more efficient?

泄露秘密 提交于 2019-11-28 16:11:11
When iterating over a large array with a range expression, should I use Python's built-in range function, or numpy's arange to get the best performance? My reasoning so far: arange probably resorts to a native implementation and might be faster therefore. On the other hand, arange returns a full array, which occupies memory, so there might be an overhead. Python 3's range expression is a generator, which does not hold all the values in memory. bmu For large arrays numpy should be the faster solution. In numpy you should use combinations of vectorized calculations, ufuncs and indexing to solve