range

A pythonic way how to find if a value is between two values in a list

Having a sorted list and some random value, I would like to find in which range the value is. List goes like this: [0, 5, 10, 15, 20] And value is, say 8. The standard way would be to either go from start until we hit value that is bigger than ours (like in the example below), or to perform binary search. grid = [0, 5, 10, 15, 20] va...

Validate double value range and step

I'm trying to construct an algorithm that validates that a double value is a member of a range defined with min, max and step values. The problem is checking that the value obeys the step rule. For integers this can be easily done: boolean validate(int value, int min, int step, int max){ return value >= min && value ...

Interested in making a PHP script that increments IP address from defined starting address to defined ending address

Hi, I know I can do this easily by converting the IP addresses to decimal notation first using PHP built in functions like up2long and long2ip. I just want to be able to do the same using the standard IP address notation as an exercise. The problem I am thinking goes like this: Given an starting IP address, say 192.168.1.100, and an end...

Set textarea selection in Internet Explorer

I'm looking for a way to set a selection in a textarea in Internet Explorer. In other browsers, this works just fine: textarea.selectionStart = start; textarea.selectionEnd = end; In IE, I assume I have to use createRange and adjust the selection somehow, but I cannot figure out how. Extra bonus points for a link to a proper document...

Vim yanking range of lines

Hello Everyone! This is my first post on stack, so please bear with me. 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: 1...

How can I print the first to the fifth from last array elements in Perl?

I'm running the following code and I'm attempting to print the first element in the @rainbow array through the fifth-from-last element in the @rainbow array. This code works for any positive indices within the bounds of the array, but not for negative ones: @rainbow = ("a".."z"); @slice = @rainbow[1..-5]; print "@slice\n"; ...

Problem using rangelength for jQuery validation

Hi, I'm using the jQuery Validator Plugin. My code is like this: <input name="username" type="text" class="newtextbox required" rangelength="(4,16)"> The error message is "Please enter a value between NaN and 4 characters long". The actual error message that has to be is "Please enter a value between 4 and 16 characters long". I thi...

play the range of big WMV files by using ASP.NET

hi , I am developing a ASP.NET by using c#.net and have many WMV files and have to watch the range of the file which I gave.The size of files are too big also the users shouldn't download the all of the file , should download between the range which I give . Is there anybody to help me ? ...

Is there a reason that we cannot iterate on "reverse Range" in ruby?

I tried to iterate backwards with ruby using a Range and each. This way: (4..0).each do |i| puts i end ==> 4..0 Iteration through 0..4 writes the numbers. On the other Range r = 4..0 seems to be ok, r.first == 4, r.last == 0. Seems to be strange to me that the construct above does not produce the expected result. What is the a reaso...

Get range address in Excel using vb.net

I am trying to dynamically get the range of cells in Excel using VS 2005 vb.net. This works oRange = oSheet.Range(oSheet.Cells("A1"), ("U281")).Select, but "U281" will not always be the last cell in the range. So how would I dynamically get the last cell with data in it with the same format as U281. Thanks, Lora ...

How do I select all text contained in <pre> using jQuery?

Hi, I have a contentEditable iframe with line numbers and text. The line numbers are contained in a div and all text is in a <pre>-element. It looks like this: <body> <div id="line_numbers"> <div>1</div><div>2</div><div>3</div> </div> <pre> Text </pre> </body> Now, when someone presses Ctrl+A everything is selecte...

JavaScript selection/range framework

I've been working with selection/range objects, and because to the incredible amount of inconsistencies between browsers for specific selection/range stuff (even more than the DOM) I was wondering if there was a framework that would help me get through them. ...

How should I use Perl's scalar range operator?

What is the scalar ".." operator typical usage? Is it only selecting blocks of text? Interesting example by myself: sub get_next { print scalar($$..!$$), "\n"; } get_next for 1 .. 5; # prints numbers from 1 to 5 get_next for 1 .. 5; # prints numbers from 6 to 10 ...

Setting an Excel Range with an Array using Python and comtypes?

Using comtypes to drive Python, it seems some magic is happening behind the scenes that is not converting tuples and lists to VARIANT types: # RANGE(“C14:D21”) has values # Setting the Value on the Range with a Variant should work, but # list or tuple is not getting converted properly it seems >>>from comtypes.client import CreateObjec...

Functions for value intervals

I'm currently dealing with a lot of possibly indefinite date spans, ie. StartDate EndDate --------- --------- 01JAN1921 31DEC2009 10OCT1955 null ... where the other end of the interval might be unknown or not defined. I've been working on little functions for detecting overlap, whether an interval is a subinterval of a...

Identify groups of continuous numbers in a list

I'd like to identify groups of continuous numbers in a list, so that: myfunc([2, 3, 4, 5, 12, 13, 14, 15, 16, 17, 20]) returns: [(2,5), (12,17), 20] And was wondering what the best way to do this was (particularly if there's something inbuilt into Python). Edit: Note I originally forgot to mention that individual numbers should be...

Ruby on Rails query by datetime range ( last 24, 48, etc... hours )

I'm trying to build a query that will search for recent entries based on column 'last_login_at'. This is a datetime field with time zone (i.e. Time.zone.now) When I execute User.find(:all, :conditions => ["last_login_at < ?", 24.hours.ago]) I get nothing. Alternatively I can define today as Time.zone.today and yesterday as Time.zone...

How to overwrite the dots in a ruby range?

Is there any possibility to overwrite the dots in a ruby range?. My aim is, to manipulate the given objects before the range is created. I thought of something like this require 'rubygems' require 'active_support' #actual i have to call explicitly .to_date Date.today.to_date..1.month.since.to_date #this should give me a range with Da...

Excel VBA worksheet.names vs worksheet.range

Hi There The question I have is a quick one to do with the VBA object model. I have created a defined name/range on a worksheet called "bob", pointing to a single cell. I have a bunch of other name/ranges set up on this worksheet, which I didn't create. All the other ones work perfectly. The new one created by me does not work perfectly...

Even numbers in Python

Hello, Does anyone know if Python has an in-built function to work to print out even values. Like range() for example. Thanks ...