Basics:
"three numbers" -> "\d{3}"
"an optional dot" -> "\.?"
"a letter and two numbers, three times" -> "(\w\d\d){3}"
So that can come together to form this:
"one to three numbers and an optional dot, four times" -> "(\d{1,3}\.?){4}"
Basics:
"three numbers" -> "\d{3}"
"an optional dot" -> "\.?"
"a letter and two numbers, three times" -> "(\w\d\d){3}"
So that can come together to form this:
"one to three numbers and an optional dot, four times" -> "(\d{1,3}\.?){4}"
function Point(x, y) { | |
this.x = x; | |
this.y = y; | |
} | |
function Vector(degrees, length) { | |
this.degrees = degrees; // -180 to 180 | |
this.length = length; | |
this.radians = degrees * Math.PI / 180; | |
'really simple ORM for RethinkDB objects' | |
import inflect | |
import re | |
import rethinkdb as r | |
p = inflect.engine() | |
class DocumentMetaClass(type): | |
def __new__(meta, classname, bases, attrs): | |
if '_table' not in attrs: |
function inRange(min, max, value) { | |
return (min == null || min <= value) && | |
(max == null || max >= value) | |
} | |
// evalutation of inRange(1, 2, 1.5) | |
(1 == null || 1 <= 1) && (2 == null || 2 >= 1) | |
(false || true) && (false || true) | |
true && true | |
true |
//// SLICE //// | |
// first we need an object | |
x = [1, 2, 3] | |
// slicing gets a new value, without modifying the old one | |
x.slice(0, 2) == [1, 2] // true | |
x == [1, 2, 3] // true | |
// so we can call it multiple times and x is never mutated | |
x.slice(0, 2) |
(defn euclidian [a b] | |
(Math/sqrt (+ | |
(Math/pow (- (a 0) (b 0)) 2) | |
(Math/pow (- (a 1) (b 1)) 2)))) |
$ history | awk '{a[$2]++ } END{for(i in a){print a[i] " " i}}' | sort -rn | head -n 20 | |
2502 git # Developing - everything is managed with git | |
1046 t # Taskwarrior alias | |
589 vim # I use vim constantly | |
303 rm # Sometimes files just need to go | |
269 cd # moving around | |
258 ./manage.py # Django management | |
253 pip # installing/uninstalling/freezing python packages | |
240 curl # useful for developing APIs | |
235 mv # ... and sometimes files need to move |
// reducer | |
function reduce(arr, func, init) { | |
for (var i = 0; i < arr.length; i++) { | |
init = func(init, arr[i], i, arr); | |
} | |
return init | |
} |
# define our higher-order function | |
def more_verboser(func): | |
def inner(x): | |
val = func(x) | |
print val | |
return val | |
return inner | |
# defined without decorator |
# Big O notation is "worst case" time of an algorithm: | |
# - O is used as a function | |
# - n the input (mostly assumed to be an integer) | |
# - any transformations done to n (say 2n) are representative of the operations inside the algorithm | |
# | |
# so take the following: | |
def count_to_n(n): | |
"count up to n (obviously contrived)" | |
# do some preparation work |