range

How to produce a range with step n in bash? (generate a sequence of numbers with increments)

╄→гoц情女王★ 提交于 2019-11-28 16:08:08
The way to iterate over a range in bash is for i in {0..10}; do echo $i; done What would be the syntax for iterating over the sequence with a step? Say, I would like to get only even number in the above example. chaos I'd do for i in `seq 0 2 10`; do echo $i; done (though of course seq 0 2 10 will produce the same output on its own). Note that seq allows floating-point numbers (e.g., seq .5 .25 3.5 ) but bash's brace expansion only allows integers. Bash 4 's brace expansion has a step feature: for {0..10..2}; do .. done No matter if Bash 2/3 (C-style for loop, see answers above) or Bash 4, I

How to know if today's date is in a date range?

谁都会走 提交于 2019-11-28 15:11:22
I have an event with start_time and end_time and want to check if the event is "in progress". That would be to check if today's date is in the range between the two dates. How would you do this in a function? Use === Actually, there is an operator that will do this. Make a Range and compare Time objects to it using the === operator. start = Time.now.to_i range = start..(start + 2) inside = start + 1 outside = start + 3 # ok, now... range === inside # true range === outside # false Update post-comment-flood: This version works well everywhere. (In Rails, in Ruby 1, and in Ruby 2.) The earlier

Designing non-overlapping date-time events

让人想犯罪 __ 提交于 2019-11-28 14:44:08
I have the following problem: Events have a "begin" and "end" time and an amount. I use MySQL DATETIME for both. Now if I have a constraint that says "no overlapping events" I need to make some checks etc. but how to design that? The user only needs 5-mins precision or so, but i want to do calculations with seconds since that is "simpler"/"cleaner" If I have an event (A) with start-end "YYYY-MM-DD 12:00:00"-"YYYY-MM-DD 14:00:00" and another (B) "YYYY-MM-DD 14:00:00"-"YYYY-MM-DD 16:15:00" -> they are non-overlapping even though they both contain 14:00:00. In order to determine that they are

range builder `r_` - slice with complex (but not imaginary) step; magnitude is used

瘦欲@ 提交于 2019-11-28 14:08:10
Playing with the NumPy concatenation and range building object r_ I stumbled over the following behavior: apparently, a complex step no matter whether real, imaginary or proper complex has its absolute value taken as the number of steps in a linspace like way. >>> import numpy as np >>> >>> np.r_[0:12:4] # start : stop : step array([0, 4, 8]) # that's expected >>> np.r_[0:12:4j] # start : stop : imaginary step array([ 0., 4., 8., 12.]) # that's in the docs >>> np.r_[0:12:4+0j] # real step of complex type ? array([ 0., 4., 8., 12.]) # this is not as far as I can tell # you can even do stuff

regex number range 1-17

前提是你 提交于 2019-11-28 13:49:56
Can someone tell me how to match a number between 1-17 with a regex: I tried [1-9]|1[0-7] but it matches 8 in the 18 for example because of the first part. Any ideas? I don't want to have leading zeros. edited: The problem is I'm trying to validate a UK postcode like to start with: KW1-17 (it could be KW1, KW2 up to KW17) ... and this is just the outward part. The postcode may be KW15 1BM or KW151BM so I can't just use anchors to match the whole string ... it becomes more complicated. You need to put anchors around the regex or it will match substrings: ^(?:[2-9]|1[0-7]?)$ I've also taken the

How do I fix the 'Out of range value adjusted for column' error?

一世执手 提交于 2019-11-28 13:17:23
I went into phpMyAdmin and changed the value for an integer(15)field to a 10-digit number, so everything should work fine. I entered the value '4085628851' and I am receiving the following error: Warning: #1264 Out of range value adjusted for column 'phone' at row 1 It then changes the value to '2147483647'. After some googling, I found this article that explains how to fix the problem. http://webomania.wordpress.com/2006/10/01/out-of-range-value-adjusted-for-column-error/ , but I don't know how to login to the Mysql shell. How do I login to the Mysql shell? How do I fix this error? martin

Java the range of int?

坚强是说给别人听的谎言 提交于 2019-11-28 13:12:27
I understand that int range in Java should be -2^31 to 2^31-1. But when I run this code snippet with 20: public class Factorial { public int factorial(int n) { int fac=1; for (int i=1; i<=n; i++) { fac *= i; System.out.println("Factorial of " + i + " is: " + fac); } return fac; } } The output: Factorial of 1 is: 1 Factorial of 2 is: 2 Factorial of 3 is: 6 Factorial of 4 is: 24 Factorial of 5 is: 120 Factorial of 6 is: 720 Factorial of 7 is: 5040 Factorial of 8 is: 40320 Factorial of 9 is: 362880 Factorial of 10 is: 3628800 Factorial of 11 is: 39916800 Factorial of 12 is: 479001600 Factorial of

Updated the vba code and still it gives me a subscript out of range error [duplicate]

自闭症网瘾萝莉.ら 提交于 2019-11-28 13:02:49
问题 This question already has answers here : Subscript out of range error in this Excel VBA script (3 answers) Closed 6 years ago . This code still gives me an out of subscript error Sub importData2() ChDir "C:\Users\Desktop\Java" Dim filenum(0 To 10) As Long filenum(0) = 052 filenum(1) = 060 filenum(2) = 064 filenum(3) = 068 filenum(4) = 070 filenum(5) = 072 filenum(6) = 074 filenum(7) = 076 filenum(8) = 178 filenum(9) = 180 filenum(10) = 182 Dim sh1 As Worksheet Dim rng As Range Set rng = Range

use a range as a dictionary key in Python, what option do I have?

跟風遠走 提交于 2019-11-28 12:52:41
问题 This is my first post and I'm quite new at programming, so I might not be able to convey my question appropriately, but I'll do my best! tries_dict = {1:'first', 2:'second', 3:'third', 4:'fourth', ub_tries:'last'} ub_tries = user input tries = 1 input ('\nCome on make your ' + tries_dict.get(tries) + guess: ') These 3 elements are part of a number guess game I created, and I included them in a while loop where tries += 1 after each wrong answer. As you can see, in my dictionary there are

jQuery-UI Date and Time-Range Picker

风格不统一 提交于 2019-11-28 12:38:32
I'm creating a page to manage the our times at the office (for example when we made home-office). This requires selecting a date and then time-range. I know about the Date-Picker from jQuery-UI, and there also seems to be something interesting for time picking. But since I need a start and end time, a UI to select date and time range would be perfect. Is there something you could recommend? Visit jQuery UI datepicker range example and click "view source". Combine with jquery timepicking solution found here . That should hopefully get you going in the right direction. Another interesting option