Skip to content

Instantly share code, notes, and snippets.

View hoffmann's full-sized avatar

Peter Hoffmann hoffmann

View GitHub Profile
@hoffmann
hoffmann / pycco.diff
Created October 14, 2010 20:50
Add erlang to pycco literal programming
diff --git a/pycco b/pycco
index aaabb7b..bbe1b04 100755
--- a/pycco
+++ b/pycco
@@ -163,6 +163,7 @@ languages = {
".py": { "name": "python", "symbol": "#" },
".scm": { "name": "scheme", "symbol": ";;" },
".lua": { "name": "lua", "symbol": "--" },
+ ".erl": { "name": "erlang", "symbol": "%%" },
}
def debug(s, *args, **kwargs):
c_frame = inspect.getouterframes(inspect.currentframe(), 1)[1][0]
c_args, c_varargs, c_varkw, c_locals = inspect.getargvalues(c_frame)
d = dict(c_locals)
if kwargs: d.update(kwargs)
print s.format(*args, **d)
def foo():
bar = 'world'
debug('hello {bar}')
"""
Implementation of the Extrinsic Visitor Pattern in Python with support
for Inheritance.
see: http://peter-hoffmann.com/2010/extrinsic-visitor-pattern-python-inheritance.html
"""
class Node(object): pass
class A(Node): pass
class B(Node): pass
import lxml.etree
def pprint(elem):
print lxml.etree.tostring(elem, pretty_print=True)
class Bind(object):
def __init__(self, path, converter=None, first=False):
'''
path -- xpath to select elements
converter -- run result through converter
first -- return only first element instead of a list of elements
import lxml.etree
def pprint(elem):
print lxml.etree.tostring(elem, pretty_print=True)
class Bind(object):
def __init__(self, path, converter=None, first=False):
'''
path -- xpath to select elements
converter -- run result through converter
first -- return only first element instead of a list of elements
import time
class Retry(object):
default_exceptions = (Exception)
def __init__(self, tries, exceptions=None, delay=0):
"""
Decorator for retrying function if exception occurs
tries -- num tries
exceptions -- exceptions to catch