range

python time range validator

核能气质少年 提交于 2019-11-27 15:55:47
I have 2 parameters in DB: start and stop. value for them can be eg 07:00-23:00 or 23:00-07:00 (start after 07, stop after 23 or start after 23, stop after 07) In that time, a status must be 0 or 1, let's say it's LED How to create unified logic controller that won't mess up after/before midnight? My poor implementation (wont work) is below. Actually, I've tried many-many variations and still ended up where I currently am.. if curtime >= vv_time_trig1 and curtime <= vv_time_trig2: logger.info("turning socket on") logger.debug("#1") #check current status #if current is 0 #turn socket on if

Limit the value of a MySQL datatype to a specific range (preferably not ENUM)

一曲冷凌霜 提交于 2019-11-27 15:44:11
I want to limit the datatype value that can be stored within a field to a specific range of integer values: [0,10]. On user input within a PHP script I validate and sanitise the data to make sure it is within the range 0 to 10. However, is there a way to ensure this remains true within the votes table itself via some sort of datatype or constraint? At the moment I store the int value within an UNSIGNED TINYINT which of course has the range of 0-255. I am aware of ENUM as an option. However, I have read that it is not advisable when using numbers: http://komlenic.com/244/8-reasons-why-mysqls

Clear a selection in Firefox

青春壹個敷衍的年華 提交于 2019-11-27 15:28:21
I have this function function smth() { var container = null; var newContainer = null; if (window.getSelection) { // all browsers, except IE before version 9 alert("first if"); var selectionRange = window.getSelection(); if (selectionRange.rangeCount > 0) { var range = selectionRange.getRangeAt(0); container = range.commonAncestorContainer; newContainer = container; } } else { if (document.selection) { // Internet Explorer alert("second if"); var textRange = document.selection.createRange(); container = textRange.parentElement(); } } if (newContainer) { return newContainer.nodeName; } else {

Javascript Highlight Selected Range Button

回眸只為那壹抹淺笑 提交于 2019-11-27 14:32:28
I'm attempting to create a study tool for a page that allows a user to select any text on the page and click a button. This click then formats the selected text with a yellow background. I can make this work inside of a single tag, but if the range of selection is across multiple tags (for instance, the first LI in an unordered list along with half of the second), I have difficulty applying the style. I can't just wrap the selection with a span here unfortunately. Basically, I want the effects associated with contentEditable and execCommand without actually making anything editable on the page

Generate N random numbers within a range with a constant sum

喜欢而已 提交于 2019-11-27 14:28:12
I want to generate N random numbers drawn from a specif distribution (e.g uniform random) between [a,b] which sum to a constant C. I have tried a couple of solutions I could think of myself, and some proposed on similar threads but most of them either work for a limited form of problem or I can't prove the outcome still follows the desired distribution. What I have tried: Generage N random numbers, divide all of them by the sum of them and multiply by the desired constant. This seems to work but the result does not follow the rule that the numbers should be within [a:b]. Generage N-1 random

Python 3 range Vs Python 2 range

房东的猫 提交于 2019-11-27 14:26:46
I recently started learning python 3. In python 2 range() function can be used to assign list elements. >>> A = [] >>> A = range(0,6) >>> print A [0, 1, 2, 3, 4, 5] where as in python 3 when range() function is used this is happening >>> A = [] >>> A = range(0,6) >>> print(A) range(0, 6) why is this happening? why did python do this change? Is it a boon or a bane ? Sam Hartman Python 3 uses iterators for a lot of things where python 2 used lists .The docs give a detailed explanation including the change to range . The advantage is that Python 3 doesn't need to allocate the memory if you're

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

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-27 14:18:12
问题 This question already has answers here : Determine Whether Integer Is Between Two Other Integers? (8 answers) Closed last year . Suppose I want to check if x belongs to range 0 to 0.5. How can I do it? 回答1: 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!) 回答2: print 'yes' if 0 < x < 0.5 else

Range-for-loops and std::vector<bool>

隐身守侯 提交于 2019-11-27 14:16:57
Why does this code work std::vector<int> intVector(10); for(auto& i : intVector) std::cout << i; And this doesn't? std::vector<bool> boolVector(10); for(auto& i : boolVector) std::cout << i; In the latter case, I get an error error: invalid initialization of non-const reference of type ‘std::_Bit_reference&’ from an rvalue of type ‘std::_Bit_iterator::reference {aka std::_Bit_reference}’ for(auto& i : boolVector) Quentin Because std::vector<bool> is not a container ! std::vector<T> 's iterators usually dereference to a T& , which you can bind to your own auto& . std::vector<bool> , however,

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

痞子三分冷 提交于 2019-11-27 14:13:01
问题 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

Function To Create Regex Matching a Number Range

北城以北 提交于 2019-11-27 14:11:39
I am working with the Amazon Mechanical Turk API and it will only allow me to use regular expressions to filter a field of data. I would like to input an integer range to a function, such as 256-311 or 45-1233, and return a regex that would match only that range. A regex matching 256-321 would be: \b((25[6-9])|(2[6-9][0-9])|(3[0-1][0-9])|(32[0-1]))\b That part is fairly easy, but I am having trouble with the loop to create this regex. I am trying to build a function defined like this: function getRangeRegex( int fromInt, int toInt) { return regexString; } I looked all over the web and I am