This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Convert between various representations of an IPv4 address. | |
`ip` refers to a dotted string, like: `'127.0.0.1'`. | |
`octets` are indexables, like `(127, 0, 0, 1)`. | |
`int` is the integer representation, like `2130706433`. | |
Written for Python 2.7. | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// # Block Grid | |
// | |
// Technique adapted from Foundation 5 for Bootstrap 3.0.3 to at least 3.3.1. | |
// https://github.com/zurb/foundation/blob/f755d8704123f86c281ede0b171881e2672f150d/scss/foundation/components/_block-grid.scss | |
// | |
// # Example Usage | |
// | |
// To produce a grid of 2 items per row on an extra-small screen, and 3 items | |
// per row on a small screen: | |
// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class throttle(object): | |
""" | |
Decorator that prevents a function from being called more than once every | |
time period. | |
To create a function that cannot be called more than once a minute: | |
@throttle(minutes=1) | |
def my_fun(): | |
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Return a delta object whose days, hours, minutes, seconds property add up to | |
* the amount of time between timeA and timeB. Assumes A happens before B. */ | |
var duration = function (timeA, timeB) { | |
var msPer = // milliseconds per various times | |
{ second: 1000 | |
, minute: 1000 * 60 | |
, hour: 1000 * 60 * 60 | |
, day: 1000 * 60 * 60 * 24 | |
}; | |
var delta = {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* N-ary cartesian product. | |
* Input: any number of lists | |
* Output: the cartesian product of the above lists as list of lists | |
* Example: cartesianProduct([1, 2], ['cat']) -> [ [1, 'cat'], [2, 'cat'] ] | |
*/ | |
var cartesianProduct = function () { | |
function addNextList (tuples, list) { | |
var result = []; | |
tuples.forEach(function (tuple) { | |
list.forEach(function (item) { |