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
function argList(args) { | |
return Array.prototype.slice.call(args); | |
} | |
function reduce0(fn, l, init) { | |
for(var i = 0; i < l.length; i++) { | |
init = fn(init, l[i]); | |
} | |
return init; | |
} |
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
"use strict"; | |
var H_PADDING = 10; | |
var V_PADDING = 10; | |
var ROWS = 20, COLUMNS = 20; | |
function app(processing) { | |
var midX, midY, colWidth, rowHeight; | |
var colors = { |
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
function empty() { | |
return function() { | |
return false; | |
}; | |
} | |
function singleton(e0) { | |
return function(e) { | |
return e0 === e; | |
}; |
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
"use strict"; | |
var H_PADDING = 10; | |
var V_PADDING = 10; | |
var ROWS = 20, | |
COLUMNS = 20; | |
var KEYCODES = { | |
37: "left", | |
38: "up", |
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
from decimal import Decimal | |
def _wrap_converter(fn): | |
def _wrapper(elem): | |
try: | |
return fn(elem) | |
except Exception as e: | |
msg = "Failed to convert value {0}: {1}".format( | |
elem, e) | |
raise ValueError(msg) |
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
(defn deep-merge-with | |
"Like merge-with, but preserves shared key paths, recursively." | |
[f & maps] | |
(letfn [(merge-elem [m e] | |
(let [k (key e) v (val e) src (m k)] | |
(if src | |
(if (and (map? src) (map? v)) | |
(assoc m k (merge2 src v)) | |
(assoc m k (f src v))) | |
(assoc m k v)))) |
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
def categorize(fn, coll): | |
"""Like group_by, but fn returns multiple keys""" | |
acc = {} | |
for e in coll: | |
keys = fn(e) | |
for key in keys: | |
if key not in acc: | |
acc[key] = [] | |
acc[key].append(e) |
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
SPECIAL_DELIM = [("[{}[".format("="*n), "]{}]".format("="*n)) for n in range(10)] | |
def type_of(v, *types): | |
return any(isinstance(v, t) for t in types) | |
def get_delim(s): | |
if '"' not in s: and "\n" not in s: | |
return ('"', '"') | |
for op, cl in SPECIAL_DELIM: | |
if op not in s and cl not in s: |
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
import copy | |
class ReducedException(Exception): | |
def __init__(self, reduced_value): | |
super(ReducedException, self).__init__() | |
self.reduced_value = reduced_value | |
def conj(coll, *es): | |
"""Conjoin elements to coll. Works correctly for most collection types""" |
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 Enumerable(object): | |
def map(self, fn): | |
acc = [] | |
self.each(lambda xs: acc.append(fn(xs))) | |
return self.__class__(acc) | |
collect = map | |
def filter(self, pred): | |
acc = [] |
OlderNewer