range

Why a range_iterator when a range is reversed?

て烟熏妆下的殇ゞ 提交于 2019-12-07 05:04:52
问题 I can subscript a range object: >>> r = range(4) >>> r range(0, 4) >>> r[3] 3 >>> for i in r: print(i) 0 1 2 3 >>> list(r) [0, 1, 2, 3] But, if I call reversed on the same range object: >>> r = reversed(range(4)) >>> r <range_iterator object at memaddr> >>> for i in r: print(i) 3 2 1 0 >>> r[3] TypeError: 'range_iterator' object is not subscriptable # ? >>> range(r) TypeError: 'range_iterator' cannot be interpreted as an integer # ? >>> list(r) [] # ? uhmm Hmm... Acting kinda like a generator

How to find first free start times from reservations in Postgres

巧了我就是萌 提交于 2019-12-07 04:23:05
问题 People work from 10:00AM to 21:00PM except Sundays and public holidays. Jobs for them are reserved at 15 minute intervals. Job duration is from 15 minutes to 4 hours. Whole job must fit to single day. How to find first nearest free start times which are not reserved for given duration in Postgres 9.3 starting from current date and time ? For example, Mary has already reservation at 12:30 .. 16:00 and John has already reservation at 12:00 to 13:00 Reservat table contains reservations, yksus2

How to test whether two time ranges overlap?

冷暖自知 提交于 2019-12-07 04:19:00
问题 I need to implement booking functionality and ensure that bookings don't overlap in a Rails app. The cover? and between? methods aren't quite what I need. I have to ensure uniqueness of a time range when compared to other potential ranges on the same model, and do it efficiently. I THINK it can be done using overlaps?. The problem is that this returns TRUE for something like this: (1..5).overlaps?(5..9) => true If I compared a booking that ended right when another started ( 3:30 - 4:00 versus

d3.js: limit size of brush

家住魔仙堡 提交于 2019-12-07 03:35:57
问题 Is there a way to limit the size of a brush, even though the extent is larger? I put together a brush with only an x-scale that can be moved and resized. I would like to be able to limit the extent to which it can be resized by the user (basically only up to a certain point). In the following example, the brush function stops updating when the brush gets bigger than half the maximum extent. The brush itself, though, can still be extended. Is there a way to prevent this from happening? Or is

Generating a random number between multiple ranges

不打扰是莪最后的温柔 提交于 2019-12-07 01:58:43
问题 I understand how to make a random number which is between two numbers: 1 + (int)(Math.random() * ((10 - 1) + 1)) or Min + (int)(Math.random() * ((Max - Min) + 1)) But how do I go about generating a random number which falls into multiple ranges? For example: number can be between 1 to 10 or between 50 to 60 回答1: I'd go with something like this, to allow you to do it with as many ranges as you like: import java.util.ArrayList; import java.util.List; import java.util.Random; class

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

怎甘沉沦 提交于 2019-12-06 23:15:31
问题 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 selected, including the line numbers. I would like to change this behaviour to only include the contents of the <pre> . I have set up a function that captures Ctrl+A and prevents the default

Iterate over an infinite sequence in Ruby

◇◆丶佛笑我妖孽 提交于 2019-12-06 20:59:55
问题 I am trying to solve Project Euler problem #12: The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten terms would be: 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ... Let us list the factors of the first seven triangle numbers: 1: 1 3: 1,3 6: 1,2,3,6 10: 1,2,5,10 15: 1,3,5,15 21: 1,3,7,21 28: 1,2,4,7,14,28 We can see that 28 is the first triangle number to have over five divisors. What is the

Keep text selected when focus input

感情迁移 提交于 2019-12-06 19:39:17
问题 This question has already been asked but until now there is no working answer so I am tempting to open it again hopefully we can find a hack to it. I have a contentEditable paragraph and a text input, when I select some text and click the input, the selection is gone. So I've tried to save the selection on input mousedown and to restore it back on mouseup and yeah it works ( as expected in firefox) But... in chrome the input lose focus :( See it in action ( use chrome ) : https://jsfiddle.net

Can Range.Value2 & Range.Formula have different values in C#, not VBA?

白昼怎懂夜的黑 提交于 2019-12-06 16:21:55
I want to create a UDF which is like GetPath(parameter) , where parameter can be a cell reference like "B1" , or a string what the GetPath does, based on input, it will call web service to get path for input e.g. formula of cell A1=GetPath(B1) , cell B1 has some string, the function should return path and put it in cell A1, i.e. "Value2" of A1 should be path of B1. Now in C#, when I did sth FormulaCell.Value2 = path , its formula changes, too but I want "Formula" & "Value2" to be different. I know this is possible in VBA, but I am using C#. Anyone knows how to accomplish this? thanks I googled

Converting PHP date range to MYSQL individual dates

核能气质少年 提交于 2019-12-06 15:24:39
I have an availability calendar in which I am currently adding in dates one by one, and using a mysql query to determine if there exists a row with a certain date and changing the class of the day to "booked" (Red). I would like to enter in a range into my form, and process it through php (or mysql) into multiple, individual dates. My date format is M/D/YYYY, or MM/DD/YYYY, both are accepted. Unfortunately, when I built my calendar, I did not use the date format in sql for entries, but used varchar. Is there a way to enter into my form for example 1/1/2014-1/3/2014 and have php convert that to