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
fs = [lambda x: x*x, lambda y: y+y, lambda z: str(z)] | |
comp = lambda fs, arg: reduce(lambda x, y: y(x), fs, arg) | |
comp(fs, 5) # returns '50', i.e. str((5*5)+(5*5)) |
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 partial | |
def pass_result_to(wrap_with): | |
def wrapper(f): | |
def wrapper_(*args, **kwargs): | |
return wrap_with(f(*args, **kwargs)) | |
return wrapper_ | |
return wrapper |
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
# -*- coding: utf-8 -*- | |
def maybe_call_super(cls, instance, method): | |
next_mro_obj = super(cls, instance) | |
method = getattr(next_mro_obj, method, None) | |
if method: | |
method() | |
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 MagicValue(object): | |
def __eq__(self, obj): | |
return type(self) is type(obj) | |
def __nonzero__(self): | |
return False | |
def __hash__(self): | |
return id(self) |
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
# -*- coding: utf-8 -*- | |
from datetime import datetime, timedelta | |
import itertools | |
import redis | |
import logging | |
from django.core.cache import cache | |
log = logging.getLogger('db.connection') |
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
$ cat n_line.py | |
# -*- coding: utf-8 -*- | |
from itertools import islice | |
from cStringIO import StringIO | |
_content = """1st line | |
2nd line | |
3rd line | |
4th line | |
5th line""" |
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
#! /bin/sh | |
### BEGIN INIT INFO | |
# Provides: redis-server | |
# Required-Start: $syslog | |
# Required-Stop: $syslog | |
# Should-Start: $local_fs | |
# Should-Stop: $local_fs | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: redis-server - Persistent key-value db |
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 random | |
from itertools import islice | |
def dev_urandom(): | |
while True: | |
yield random.randint(0, 9) | |
def random_phone_number(): | |
return '+7' + "".join(map(str, islice(dev_urandom(), 0, 10))) |
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
=== modified file '__init__.py' | |
--- __init__.py 2008-01-20 20:07:02 +0000 | |
+++ __init__.py 2010-08-04 04:51:49 +0000 | |
@@ -141,11 +141,11 @@ | |
# bzr grep foo -- -i file | |
# and pass the -i through to grep. | |
+ files = [] | |
+ options = [u'--color=always'] | |
+ |
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
# -*- coding: utf-8 -*- | |
class A(object): | |
def do(self, x): | |
print ' A.foo(%s)' % (x,) | |
class B(object): | |
def do(self, x): | |
print ' B.foo(%s)' % (x,) |
NewerOlder