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
http://en.wikipedia.org/wiki/Church_numerals#Church_pairs (example) | |
fst (pair a b) | |
\p.p (\x.\y.x) ((\x.\y.\z.z x y) a b) | |
\p.p (\x.\y.x) (\z.z a b) | |
??? | |
(\z.z a b) (\x.\y.x) | |
(\x.\y.x) a b | |
a |
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
################################################# | |
# currying and partial application in python # | |
# based on code from Simon Willison's geocoders # | |
################################################# | |
# curries fn, a function of exactly 2 parameters | |
def partial2(fn): | |
def inner1(arg2): | |
def inner2(arg1): | |
return fn(arg1, arg2) |
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
/* | |
* usage example: | |
* $('body').zIndices() | |
* | |
* Returns a hash with z-indices as keys whose corresponding | |
* values are elements with that z-index set. Any z-index <z> | |
* having more than one element will also be in the hash | |
* under the key '!<z>' (to be sorted together near the top), | |
* as well as the regular key, '<z>'. | |
*/ |
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 really_in(y, xs): | |
if y is not True and y is not False: | |
'''thanks http://www.reddit.com/r/Python/comments/asmwr/python_boolean_coercion_gotchas/c0j7cd7?context=3''' | |
return y in xs | |
for x in xs: | |
if y is x: return True | |
return False | |
True in [1, 2, 3] # -> True |
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 test_filtered_really_in_2(y, xs): | |
def pred(e): return e is y | |
return filter(pred, xs) |
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
# if there are any others who don't care much for try ... catch AttributeError | |
def hasmethods(obj, *meth_names): | |
return all( | |
hasattr( | |
# if it calls like a method it's a method | |
getattr(obj, m, None), | |
'__call__' | |
) for m in meth_names | |
) |
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 urllib import urlopen | |
from xml.dom import minidom | |
import re | |
REGIONAL_REPORT_FEED = 'http://www.surfline.com/rss/region.cfm?id=2958' | |
GOOD_WORDS = re.compile(r'good|epic|solid|fun', re.IGNORECASE) | |
HEIGHTS = re.compile(r'\d+') | |
GOOD_HEIGHT = 4 | |
def is_of_interest(title): |
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
// note: currently, this only works for an individual track, e.g. the main track on | |
// http://soundcloud.com/tall-cans/el-pico-acoustic-ratatat-cover | |
// | |
// bookmarklet: | |
// (function($)%20{var%20$play%20=%20$(%27.controls%20a.play:first%27),poll%20=%20true;function%20startPolling()%20{setInterval(function()%20{if%20(poll)%20{if%20(!$play.hasClass(%27playing%27))%20{$play.trigger(%27click%27,%20true);}}},%20500);}$play.bind(%27click%27,%20function(e,%20loop)%20{if%20(typeof%20loop%20===%20%27undefined%27%20||%20!loop)%20{poll%20=%20!$play.hasClass(%27playing%27);}});startPolling();}(jQuery)); | |
(function($) { | |
var $play = $('.controls a.play:first'), | |
poll = true; | |
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($)%20{var%20$play%20=%20$(%27.controls%20a.play:first%27),poll%20=%20true;function%20startPolling()%20{setInterval(function()%20{if%20(poll)%20{if%20(!$play.hasClass(%27playing%27))%20{$play.trigger(%27click%27,%20true);}}},%20500);}$play.bind(%27click%27,%20function(e,%20loop)%20{if%20(typeof%20loop%20===%20%27undefined%27%20||%20!loop)%20{poll%20=%20!$play.hasClass(%27playing%27);}});startPolling();}(jQuery)); |
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
var obj = {foo: 4, bar: 7}; | |
// returns an array of keys: [ 'foo', 'bar' ] | |
Object.keys(obj); | |
var arr = [3, 6, 9]; | |
// returns a new array: [ 4, 7 ] | |
arr.map(function(n) { return n + 1; }); |
OlderNewer