range

Slow highlighting in Firefox

二次信任 提交于 2019-11-28 09:30:45
问题 We need to add anchors and highlights for some keywords/sentences in the html page. It turns out the highlighting is really slow in Firefox. In the following code, all ranges which need to be highlighted are stored in array hiliteRanges : for (var i = 0; i < hiliteRanges.length; i++){ document.designMode = "on"; var selHilites = window.getSelection(); if (selHilites.rangeCount > 0) selHilites.removeAllRanges(); selHilites.addRange(hiliteRanges[i]); var anchorId = 'index'+i; var insertedHTML =

Checking a number range with regular expressions

北城余情 提交于 2019-11-28 09:05:46
I'm using a regular expression to validate a certain format in a string. This string will become a rule for a game. Example: "DX 3" is OK according to the rule, but "DX 14" could be OK too... I know how to look at the string and find one or more "numbers", so the problem is that the regex will match 34 too, and this number is out of "range" for the rule... Am I missing something about the regex to do this? Or is this not possible at all? Unfortunately there's no easy way to define ranges in regex. If you are to use the range 1-23 you'll end up with a regex like this: ([1-9]|1[0-9]|2[0-3])

How to select a node in a range with webkit browsers?

佐手、 提交于 2019-11-28 09:05:29
问题 I'm currently working on a WYSIWYG solution and need a function to correctly select with a range a node (by this I mean the node itself, not only it's content) DOM lvl2 clearly have a function for this w3.org/ranges and define that range.selectNodeContents() // Select the contents within a node and range.selectNode() //Select a node and its contents The problem is that when selectNode() perfectly work with Firefox or even ie9, it seem to be impossible to achieve with any Webkit browser (at

Python - Optimisation of Perfect Number search

自闭症网瘾萝莉.ら 提交于 2019-11-28 09:00:07
问题 p = [] for x in range(1, 50000000): count = 0 for y in range(1, x // 2 + 1): if (x % y == 0): count += y if (count == x): p.append(x) This is my code to try and find all the perfect numbers that originate between 1 and 50000000. It works fine for the first 3 numbers, they are between 1 and 10000. But as it progresses it becomes extremely slow. Like maybe going through 1000 numbers every 10 seconds. Then eventually going through 10 numbers every 5 seconds. Now is there anyway I could make this

Array of indexes to array of ranges

二次信任 提交于 2019-11-28 08:34:57
Ranges in ruby are pretty cool. I end up with arrays such as this: geneRanges = [(234..25), (500..510), (1640..1653)] And subsequently have to remove bits of them. For that I: genePositions = geneRanges.collect {|range| range.entries }.flatten => [500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, 1640, 1641, 1642, 1643, 1644, 1645, 1646, 1647, 1648, 1649, 1650, 1651, 1652, 1653] They get manipulated, so some numbers get excluded, and others may be added. I may end up with this: [505, 506, 507, 600, 601, 602, 603, 1643, 1644, 1645, 1646, 1647, 1648, 1649, 1650, 1651, 1652, 1653, 1654] How

SQLite loop statements?

天大地大妈咪最大 提交于 2019-11-28 08:11:19
Is there any loop statements in SQLite like FOR .. in .. LOOP or something like that? I have two columns StartRange, EndRange and I need to insert whole sequence in other table. So if StartRange is 1 and EndRange is 3 it's necessary to make three inserts with value, contains 1, 2, 3 . You can do this sort of thing in straight SQL if you have an extra table that holds all the integers that you need. Suppose your StartRange and EndRange range between one and ten and you have a table like this: sqlite> select i from ints; i 1 . . . 10 This table simply contains all the possible integers that you

How can I expand a string like “1..15,16” into a list of numbers?

喜夏-厌秋 提交于 2019-11-28 07:58:53
问题 I have a Perl application that takes from command line an input as: application --fields 1-6,8 I am required to display the fields as requested by the user on command line. I thought of substituting '-' with '..' so that I can store them in array e.g. $str = "1..15,16" ; @arr2 = ( $str ) ; @arr = ( 1..15,16 ) ; print "@arr\n" ; print "@arr2\n" ; The problem here is that @arr works fine ( as it should ) but in @arr2 the entire string is not expanded as array elements. I have tried using escape

Javascript Array: get 'range' of items

不羁岁月 提交于 2019-11-28 07:58:39
Is there an equivalent for ruby's array[n..m] in Javascript ? For example: >> a = ['a','b','c','d','e','f','g'] >> a[0..2] => ['a','b','c'] Thanks Vivin Paliath Use the array.slice(begin [, end]) function. var a = ['a','b','c','d','e','f','g']; var sliced = a.slice(0, 3); //will contain ['a', 'b', 'c'] The last index is non-inclusive; to mimic ruby's behavior you have to increment the end value. So I guess slice behaves more like a[m...n] in ruby. a.slice(0, 3) Would be the equivalent of your function in your example. https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array

Using an Array of Ranges in VBA - Excel

房东的猫 提交于 2019-11-28 07:41:33
问题 Does VBA support using an array of range variables? dim rangeArray() as range dim count as integer dim i as integer count = 3 redim rangeArray(1 to count) for i = 1 to count msgbox rangeArray(i).cells(1,1).value next I can't get it to work in this type of application. I want to store a series of ranges in a certain order as a "master copy". I can then add, delete, sort or do whatever to this array and then just print it out to a series of ranges in excel. It doesn't seem like excel supports

Merging overlapping ranges in PHP arrays?

感情迁移 提交于 2019-11-28 07:37:00
I have an array in the following format: array( 0 => array(1, 5), 1 => array(4, 8), 2 => array(19, 24), 3 => array(6, 9), 4 => array(11, 17), ); Where each item is a X-to-Y range. What I would like to merge the overlapping ranges in the array, to get something more like this: array( 0 => array(1, 9), // 1-5, 4-8 and 6-9 are overlapping, so they are merged 1 => array(11, 17), 2 => array(19, 24), ); What would be the best way to accomplish this? Untested, but the idea here is to sort the data first by the first element, then merge subsequent elements with the previous one as long as possible.