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 autoDeepMap(f): | |
"Decorates a function of one argument to automatically deep-map over multiple or iterable arguments" | |
def mapped(*args): | |
if len(args) != 1: | |
return [mapped(x) for x in args] | |
elif getattr(args[0], '__iter__', False): | |
return [mapped(x) for x in args[0]] | |
else: | |
return f(args[0]) | |
return mapped |
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 loc; | |
(function locdef() { | |
function findParam(name) { | |
return new RegExp(name + '=([^&#]*)'); | |
} | |
loc = { | |
updateParam : function updateParam(name, val) { | |
var l = location.href, | |
s = name + '=' + val; |
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
Brainwashing, by Scott Adams | |
Mar 19, 2009 | |
Suppose you hire a plumber to fix a leak. You pay him for his work and he leaves. A year later he | |
calls back and asks if you would consider giving him additional money because you continue to get | |
benefits from the repairs. In addition, he argues, you could help subsidize future customers that | |
would otherwise not be able to pay for his services. Would that seem appropriate? | |
Now imagine he calls back every few months for the rest of your life, asking the same frickin' | |
question every time. Would you be okay with that practice? |
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
All around, no flowers in bloom | |
Nor maple leaves in glare, | |
A solitary fisherman's hut alone | |
On the twilight shore | |
Of this autumn eve. | |
by Fujiwara no Teika (1162-1241) | |
translation by Toshihiko and Toyo Izutsu |
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 validate(schema): | |
def validator(validatee): | |
for x in schema: | |
isValid = schema[x] | |
if type(validatee[x]) == isValid: continue | |
elif type(isValid) != type and hasattr(isValid, '__call__'): | |
if isValid(validatee[x]): continue | |
return False | |
return True | |
return validator |
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 functools import wraps | |
def predecoration(decoration=None, has_params=False): | |
"Decorates a function as a pre-decorator" | |
def metadecorator(decoration): | |
"Takes a decoration to pre-apply to a func" | |
def cap_args(*dec_args, **dec_kwds): | |
"Captures decorator arguments" | |
def decorator_with_args(func): |
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 functools import wraps, partial | |
from inspect import getargspec | |
def _param_update(old_params, new_params): | |
args, kwds = old_params | |
if type(new_params) == tuple: | |
if len(new_params) == 2 and type(new_params[0]) == tuple and type(new_params[1]) == dict: | |
args = new_params[0] | |
kwds.update(new_params[1]) |
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
>>> x = {} | |
>>> x['x'] = x | |
>>> x | |
{'x': {...}} |
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 functools import wraps, partial | |
from inspect import getargspec | |
def _param_update(old_params, new_params): | |
args, kwargs = old_params | |
if type(new_params) == tuple: | |
if len(new_params) == 2 and type(new_params[0]) == tuple and type(new_params[1]) == dict: | |
args = new_params[0] | |
kwargs.update(new_params[1]) |
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
mapping = lambda d: lambda x: d.get(x, x) |
OlderNewer