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 sys | |
from sqlalchemy import create_engine, event | |
from sqlalchemy.orm import sessionmaker | |
import model | |
if sys.version_info >= (2, 7): | |
import unittest as unittest2 |
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 re | |
import tulip | |
import tulipiostream | |
loop = tulip.get_event_loop() | |
LENGTH_PATTERN = re.compile(b'Content-Length: (\d*)\\r\\n') |
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 timeit | |
import tornloop | |
import tulip | |
loop = tornloop.TornadoLoop() | |
tulip.set_event_loop(loop) | |
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 timeit | |
import tulip | |
loop = tulip.get_event_loop() | |
def async_func(value): | |
p = tulip.Future() |
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 link(f, other): | |
'''Resolve other with the current Future.''' | |
def on_done(f): | |
e = f.exception() | |
if e: | |
other.set_exception(e) | |
else: | |
other.set_result(f.result()) |
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 _lookup(pos): | |
def composition(*args): | |
return args[pos] | |
return composition | |
def _apply(func, *funcs): | |
def composition(*args): | |
return func(*(f(*args) for f in funcs)) | |
return composition |
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 cPickle | |
import json | |
import ujson | |
import msgpack | |
d = { | |
'words': """ | |
Lorem ipsum dolor sit amet, consectetur adipiscing | |
elit. Mauris adipiscing adipiscing placerat. | |
Vestibulum augue augue, |
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
""" | |
remconsole.py | |
A Python console you can embed in a program and attach to remotely. | |
To spawn a Python console in a script do the following in any scope | |
of any module: | |
import remconsole | |
remconsole.spawn_server() |
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 operator import lt | |
def insertion_sort(data, cmp_func=lt): | |
for i in xrange(1, len(data)): | |
if cmp_func(data[i], data[i - 1]): | |
el = data.pop(i) | |
j = i - 1 | |
while j > 0 and cmp_func(el, data[j - 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
import sys | |
import os | |
def _packages_path(): | |
t = os.path.join(os.path.dirname(__file__), '..') | |
return os.path.abspath(t) | |
SITE_PACKAGES = os.path.join(_packages_path(), 'Lib', 'site-packages') | |
_PACKAGING_MODS = os.path.join(_packages_path(), 'Lib', 'packaging') |