Skip to content

Instantly share code, notes, and snippets.

@wickman
wickman / case_class.py
Created March 7, 2011 01:02
case-class like thing in python
# E.g. TaskClass = CaseClass('name', 'owner', 'pid')
# task1 = TaskClass(name = "hello", owner = "brian", pid = 15)
# task2 = TaskClass(name = "world", owner = "brian", pid = 13)
# tasks = [task1, task2]
#
# filter(lambda task: task.where(owner = "brian"), tasks) => [task1, task2]
# filter(lambda task: task.where(owner = "brian", pid = 13), tasks) => [task2]
#
# matcher = TaskClass(pid = 13)
# filter(lambda task: task.match(matcher), tasks) => [task2]
@wickman
wickman / gist:1236753
Created September 23, 2011 04:38
bottle bug
class BottleServer(object):
@staticmethod
def route(*args, **kwargs):
def annotated(function):
if hasattr(function, '__routes__'):
function.__routes__.append( (args, kwargs) )
else:
function.__routes__ = [(args, kwargs)]
return function
return annotated
@wickman
wickman / bottle_test.py
Created September 23, 2011 19:39
bottle bug simplest example
import bottle
bottle.debug(True)
class BottleServer(object):
def __init__(self):
self.app = bottle.Bottle()
self.setup_routes()
def hello(self, **kw):
@wickman
wickman / INSTALL.md
Created April 12, 2012 22:54
installing Pants

Installing / troubleshooting pants

Requirements

Most of the commons python environment has been developed against CPython 2.6. Things mostly work with CPython 2.7 and recent efforts have been made to improve CPython 3.x and PyPy compatibility. We've explicitly ignored anything prior to CPython 2.6 and in fact generally discourage use against anything less than CPython 2.6.5 as there are known bugs that we're unwilling to fix. We've never even tried running against Jython or

@wickman
wickman / README.md
Created April 12, 2012 22:55
Python development in Pants (tutorial)

Python development using Pants

brian wickman - @wickman

[TOC]

Why use Pants for Python development?

Pants makes the manipulation and distribution of hermetically sealed Python environments

@wickman
wickman / gist:2484405
Created April 24, 2012 22:45
class decorator to inherit documentation from abstract base class
from abc import ABCMeta, abstractmethod
def documented_by(documenting_abc):
def document(cls):
cls_dict = cls.__dict__.copy()
for attr in documenting_abc.__abstractmethods__:
cls_dict[attr].__doc__ = getattr(documenting_abc, attr).__doc__
return type(cls.__name__, cls.__mro__[1:], cls_dict)
return document
@wickman
wickman / clock.py
Created October 5, 2012 16:24
threaded fake clock in python
from abc import ABCMeta, abstractmethod
import threading
class ClockInterface(object):
__metaclass__ = ABCMeta
@abstractmethod
def time(self):
pass
@wickman
wickman / bootstrap_python.sh
Last active December 17, 2015 04:29
python distro bootstrapper for osx
INSTALL_ROOT=$HOME/Python
CPY=$INSTALL_ROOT/CPython
PYPY=$INSTALL_ROOT/PyPy
SANDBOX=$(mktemp -d /tmp/python.XXXXXX)
CURL='wget --no-check-certificate'
mkdir -p $INSTALL_ROOT
@wickman
wickman / gist:6587345
Created September 16, 2013 22:16
holy shit, open source aurora client
mba=science=; PANTS_VERBOSE=1 ./pants src/python/twitter/aurora/client/bin:aurora_client
Build operating on targets: OrderedSet([PythonBinary(src/python/twitter/aurora/client/bin/BUILD:aurora_client)])
Building PythonBinary PythonBinary(src/python/twitter/aurora/client/bin/BUILD:aurora_client):
Building PythonBinary PythonBinary(src/python/twitter/aurora/client/bin/BUILD:aurora_client):
Dumping library: PythonLibrary(src/python/twitter/aurora/client/bin/BUILD:aurora_client_source)
Dumping library: PythonLibrary(src/python/twitter/common/app/BUILD:app)
Dumping library: PythonLibrary(src/python/twitter/common/BUILD:common)
Dumping library: PythonLibrary(src/python/twitter/common/collections/BUILD:collections)
Dumping library: PythonLibrary(src/python/twitter/common/config/BUILD:config)
Dumping library: PythonLibrary(src/python/twitter/common/lang/BUILD:lang)
@wickman
wickman / README.md
Created January 3, 2014 19:52
pex.pex README

Pex.pex: Usage

PEX files are single-file lightweight virtual Python environments.

pex.pex is a utility that:

  • creates PEX files
  • provides a single use run-environment

Installation