This file contains hidden or 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
#!/usr/bin/env coffee | |
esprima = require 'esprima' | |
isModule = (source) -> | |
esprima.parse(source).body.some (node) -> | |
node.type is 'ExpressionStatement' and | |
node.expression.type is 'CallExpression' and | |
node.expression.callee.type is 'Identifier' and |
This file contains hidden or 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
concat = (lists...) -> | |
[].concat(lists...) | |
_traverse = (list, path, f) -> | |
if list.length is 0 | |
f(path) | |
else | |
for item, idx in list | |
_traverse(concat(list.slice(0, idx), list.slice(idx + 1)), | |
concat(path, [item]), f) |
This file contains hidden or 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
DATE | |
TBD. Probably 2014-01-04 or 2014-01-05. | |
VENUE | |
TBD. Somewhere in Auckland, New Zealand. | |
This file contains hidden or 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
import time | |
def memoize(f): | |
memo = {} | |
def wrapper(*args): | |
if args not in memo: | |
memo[args] = f(*args) | |
return memo[args] | |
return wrapper |
This file contains hidden or 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
ROUND 1 | |
Darryn 2 v 0 James | |
Dan 2 v 0 Matt | |
Doug 0 v 2 David | |
ROUND 2 | |
Darryn 2 v 0 David | |
James 2 v 1 Dan |
This file contains hidden or 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
FILES = ( | |
'foo.txt', | |
'bar.txt', | |
'baz.txt', | |
) | |
def getmetadata(path): | |
return {'blah': True, 'quux': 42} |
This file contains hidden or 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
express = require 'express' | |
app = express() | |
app.param (name, arg) -> switch Object::toString.call arg | |
when '[object RegExp]' | |
(req, res, next, val) -> | |
if arg.test val then next() else next 'route' |
- avoid unnecessary state
- favor pure functions over impure functions
- functions should not have surprising side effects
- give things meaningful names, and avoid aliases
- don't swallow unexpected errors
This file contains hidden or 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
# Takes a box (an array) and a function, f, which takes a continuation. | |
# A sentinel is placed in the box, then f is invoked. When f calls its | |
# continuation, c, the box is inspected. Only if the sentinel is still | |
# in the box will c in turn call its continuation. | |
# | |
# If several asynchronous requests are made in quick succession, the | |
# responses may not be received in the order in which they were sent. | |
# This function makes it possible to define a function to be invoked | |
# *unless the request has been superseded by the time it completes*. | |
skip_continuation_if_superseded = (box, f) -> |