Skip to content

Instantly share code, notes, and snippets.

@tkaemming
tkaemming / gist:21b26cee2788939399c4
Last active August 29, 2015 14:11
zookeeper asynchronous child retrieval
def children(zookeeper, path):
get_child_path = functools.partial(posixpath.join, path)
return [
(name, zookeeper.get_async(get_child_path(name)))
for name in zookeeper.get_children(path)
]
"""
Broken example.
"""
from cassandra.cluster import Cluster
from multiprocessing import Pool
size = 4
keyspace = 'system'
@tkaemming
tkaemming / gist:7269845
Created November 1, 2013 18:39
bound methods using descriptors
>>> class Widget(object):
... pass
...
>>> instance = Widget()
>>> method = lambda s: s
>>>
>>> method.__get__(None, Widget)()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unbound method <lambda>() must be called with Widget instance as first argument (got nothing instead)
@tkaemming
tkaemming / pool.py
Created September 26, 2013 20:18
getting around http://bugs.python.org/issue14881 in multiprocessing.dummy
def SafePool(*args, **kwargs): # XXX: Can't subclass directly
# XXX: http://bugs.python.org/issue14881
thread = threading.current_thread()
if not hasattr(thread, '_children'):
thread._children = weakref.WeakKeyDictionary()
return Pool(*args, **kwargs)
@tkaemming
tkaemming / gist:5640332
Created May 23, 2013 23:43
documentation on _threading_local
Help on module _threading_local:
NAME
_threading_local - Thread-local objects.
FILE
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/_threading_local.py
MODULE DOCS
http://docs.python.org/library/_threading_local
@tkaemming
tkaemming / test.py
Last active December 15, 2015 09:49
example behavior of parent/child loggers with propagate enabled
import logging
root = logging.getLogger()
root.setLevel(logging.WARNING)
stream = logging.StreamHandler()
stream.setLevel(logging.INFO)
root.addHandler(stream)
root.info('info to root') # this will not be handled
@tkaemming
tkaemming / out
Created February 8, 2013 01:19
lazy object magic methods
Traceback (most recent call last):
File "script.py", line 13, in <module>
assert int(lazy) == 1
TypeError: int() argument must be a string or a number, not 'SimpleLazyObject'
@tkaemming
tkaemming / Makefile
Last active December 11, 2015 02:48
makefile for bootstrapping a test cassandra server on ubuntu
CASSANDRA_SOURCE_LIST = /etc/apt/sources.list.d/cassandra.sources.list
curl:
apt-get install -y curl
repository-key: curl
curl -L http://debian.datastax.com/debian/repo_key | apt-key add -
$(CASSANDRA_SOURCE_LIST): repository-key
echo "deb http://debian.datastax.com/community stable main" > $(CASSANDRA_SOURCE_LIST)
@tkaemming
tkaemming / gist:4439569
Created January 3, 2013 00:02
string identity
ted@aventador % python ~
Python 2.7.2 (default, Jun 20 2012, 16:23:33)
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> f1 = 'foo'
>>> f2 = 'fo'
>>> f2 += 'o'
>>> id(f1), id(f2)
(4524784296, 4524782976)
>>> f1 is f2
"""
Requires ``terminal-notifier``: https://github.com/alloy/terminal-notifier
"""
import subprocess
import weechat
name = 'notify'
author = 'ted kaemming <[email protected]>'
version = '0.0.0'
license = 'mit'