Skip to content

Instantly share code, notes, and snippets.

View dcolish's full-sized avatar

Dan dcolish

View GitHub Profile
@dcolish
dcolish / hacks.py
Created September 15, 2011 04:13
More crazy importing
import imp
import sys
class ErrorlessImport(object):
def find_module(self, name, path):
try:
return TrueLoader(
imp.load_module, name, *imp.find_module(name, path))
@dcolish
dcolish / puller.py
Created November 11, 2011 05:45
Zmq Tests
from zmq import Context, PULL
ctx = Context()
sock = ctx.socket(PULL)
sock.connect("tcp://localhost:5555")
counter = 1
try:
with open('test.txt', 'w+') as f:
while True:
msg = sock.recv()
@dcolish
dcolish / pycontracts.py
Created November 18, 2011 05:57
Contract style params for python
from functools import wraps
from inspect import getcallargs
def assert_params(*contracts):
_contracts = []
for contract in contracts:
_contracts.append((contract, compile(contract, '', 'eval')))
def decorator(fn):
@dcolish
dcolish / swig-pypy.diff
Created November 28, 2011 21:04
Lame patch for less broken pypy support in swig
diff --git a/Lib/python/pyrun.swg b/Lib/python/pyrun.swg
index d730a2d..b9bef17 100644
--- a/Lib/python/pyrun.swg
+++ b/Lib/python/pyrun.swg
@@ -1056,8 +1056,9 @@ SWIG_This(void)
/* #define SWIG_PYTHON_SLOW_GETSET_THIS */
-/* TODO: I don't know how to implement the fast getset in Python 3 right now */
-#if PY_VERSION_HEX>=0x03000000
@dcolish
dcolish / xapian_wrap.cc.diff
Created November 28, 2011 21:26
pypy support for xapian-bindings 1.2.7
--- python/modern/xapian_wrap.cc 2011-11-28 13:23:58.000000000 -0800
+++ python/modern/xapian_wrap.cc 2011-11-28 13:24:32.000000000 -0800
@@ -2211,7 +2211,7 @@
/* #define SWIG_PYTHON_SLOW_GETSET_THIS */
/* TODO: I don't know how to implement the fast getset in Python 3 right now */
-#if PY_VERSION_HEX>=0x03000000
+#if ((PY_VERSION_HEX>=0x03000000) || defined(PYPY_VERSION))
#define SWIG_PYTHON_SLOW_GETSET_THIS
#endif
class Mock(object):
def __init__(self, *args, **kwargs):
pass
def __getattr__(self, name):
return Mock()
m = Mock()
print m.awesome
@dcolish
dcolish / cow_dict.py
Created December 16, 2011 01:15
COW Shared Key Dicts
class CowDict(dict):
_shared = {}
def __init__(self):
self._shared = CowDict._shared
self._local = {}
def __getitem__(self, key):
value = self._local.get(key) or self._shared.get(key)
if value:
@dcolish
dcolish / gist:1819360
Created February 13, 2012 19:28
requires as a string
requires = ''
with open('requirements.txt') as f:
requires = f.read()
setup(...,
install_requires=requires,
)
@dcolish
dcolish / rpctest.py
Created February 25, 2012 23:13
Crypto zmq.rpc
import sys
from Crypto.Cipher import Blowfish
from zmq.rpc.simplerpc import (
RPCService,
RPCServiceProxy,
rpc_method,
Serializer
)
class Values:
def __init__(self, defaults=None):
if defaults:
for (attr, val) in defaults.items():
setattr(self, attr, val)
def __str__(self):
return str(self.__dict__)