Skip to content

Instantly share code, notes, and snippets.

View vlazzle's full-sized avatar

Vlad Chernis vlazzle

  • San Diego
View GitHub Profile
def test_filtered_really_in_2(y, xs):
def pred(e): return e is y
return filter(pred, xs)
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
/*
* 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>'.
*/
#################################################
# 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)
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