This file contains hidden or 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 itertools | |
from PIL import Image | |
img = Image.new("RGB", (10, 10)) | |
pixels = img.load() | |
for i, j in itertools.product(xrange(10), xrange(10)): | |
if (i + j) % 2 == 0: | |
pixels[i, j] = (0, 0, 0) | |
else: |
This file contains hidden or 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
#!/usr/bin/env python | |
# -*- encoding: utf-8 -*- | |
import re | |
import datetime | |
import subprocess | |
import sys | |
query_date = datetime.datetime.today() - datetime.timedelta(days=3) | |
query_date = query_date.strftime("%d-%b") |
This file contains hidden or 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 crazy_computation(expression, values): | |
""" | |
given expression = ["a", "+", "b", "-", "c"] and values = {"a": [1, 2, 3], "b": [4, 5, 6], "c": [7, 8, 9]}, | |
return [-2, -1, 0] | |
""" | |
# taking care of the cases when one of the two first operands is a list | |
if not isinstance(expression[0], basestring): | |
intermediate = crazy_computation(expression[0], values) |
This file contains hidden or 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 Event(object): | |
def __init__(self): | |
self.subscribers = [] | |
def subscribe(self, callback): | |
self.subscribers.append(callback) | |
def notify(self, *args, **kwargs): | |
for subscriber in self.subscribers: |
This file contains hidden or 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 HomeMixin(object): | |
def __init__(self, home, *args, **kwargs): | |
super(HomeMixin, self).__init__(*args, **kwargs) | |
self.home = home | |
class PenMixin(object): | |
def __init__(self, pen, *args, **kwargs): | |
super(PenMixin, self).__init__(*args, **kwargs) | |
self.pen = pen |
This file contains hidden or 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 Base(object): | |
def __init__(self, pen, home): | |
super(Base, self).__init__() | |
class HomeMixin(Base): | |
def __init__(self, pen, home): | |
super(HomeMixin, self).__init__(pen, home) | |
self.home = home | |
class PenMixin(Base): |
This file contains hidden or 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 _mturk_flatten(obj): | |
if isinstance(obj, basestring): | |
return {"": obj} | |
elif isinstance(obj, collections.Mapping): | |
iterable = obj.items() | |
elif isinstance(obj, collections.Iterable): | |
iterable = enumerate(obj) | |
else: | |
return {"": obj} | |
This file contains hidden or 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 urlparse | |
>>> urlparse.parse_qs("mp3=http%3A//hwzhiyin.com/uploadfile/1369168835.mp3&loop=1&autoplay=1") | |
{'mp3': ['http://hwzhiyin.com/uploadfile/1369168835.mp3'], 'loop': ['1'], 'autoplay': ['1']} |
This file contains hidden or 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
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAmQ/rFiiq8EeN2eXpZ06umK+zgXLY1J6+cKl/Uiobp46Tok4tZjdFGjyerUgFh7X+H+m6OQULpTJGwwpHvwg4cxOhq7TDyN/+5ypxS2KccxRkBAEEPuHia8o0VsddQCISwV+FBf49exdeha++SL10da8gmx/u3W/LaAopItKLbcQQClBNdHhsuSesx6NeECsPehCZC4Hvf2o614A3KtFcOOI421oCwtcu19r28qzlnTcBTJDeAY/KT7EVXahBVzd3Ve9cdyoaW2dzyu8QsAvQsgMeyc3BGDlhNyBUz/4sEDd7SAHW4Jop+5uTeBQwOYI3sfygMckjNudW+2VtrJAlrQ== |
This file contains hidden or 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 pyramid_zodbconn | |
import ZODB.serialize | |
def unwrap(request): | |
conn = pyramid_zodbconn.get_connection(request) | |
db = conn.db() | |
storage = db.storage | |
storage = getattr(storage, "_BlobStorage__storage", storage) |