Skip to content

Instantly share code, notes, and snippets.

View jml's full-sized avatar

Jonathan Lange jml

View GitHub Profile
@jml
jml / comparedb.py
Created September 17, 2012 16:46
Compare dependency databases
#!/usr/bin/python
import argparse
import os
import sys
# TODO: Figure out how to match up libraries with versions properly so we can
# find out really for real which libraries are fouund by one but not the
# other.
library(ggplot2)
# Generated with lp:txpkgme
#
# $ ./bin/py ./bin/parse-subunit-output --format csv /PATH/TO/SCOREBOARD/OUTPUT
#
# Scoreboard output is obtained by running retry-all-apps on emim.
scoreboard <- read.csv("~/Desktop/scoreboard-2012-09-20.csv")
commercial <- scoreboard[which(scoreboard$error != "UNPACKAGEABLE" & scoreboard$state == 'Published' & scoreboard$queue == "commercial"),]
qplot(commercial$backend, fill=commercial$error, xlab="Backend") +
scale_fill_discrete(
@jml
jml / first.py
Created September 28, 2012 19:08
Think Stats 1.4 -- high on functions
from datetime import timedelta
from functools import partial, wraps
from itertools import ifilter, imap
from operator import attrgetter, not_
import survey
def caller(method_name, *args, **kwargs):
def call_obj(obj):
return getattr(obj, method_name)(*args, **kwargs)
@jml
jml / gist:4040065
Created November 8, 2012 16:59
Twisted talk

Doing without

XXX - intro text goes here

The joy of order

When you write Python code, one prevailing, deep, unassailled assumption is that a line of code within a block is only ever executed after the preceding line is finished.

from parsley import makeGrammar
grammar = """
ws = ' ' | '\t' | '\r' | '\n'
keyword = ~ws+ letterOrDigit
"""
g = makeGrammar(grammar, {})
jml@grace:~/src/todotxtpy$ PYTHONPATH=~/src/parsley/ testr run
running=python -m subunit.run discover .
^CTraceback (most recent call last):
File "/usr/lib/python2.7/runpy.py", line 162, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/usr/local/lib/python2.7/dist-packages/python_subunit-0.0.8-py2.7.egg/subunit/run.py", line 84, in <module>
stdout=sys.stdout)
File "/usr/local/lib/python2.7/dist-packages/testtools/run.py", line 182, in __init__
@jml
jml / gist:4572369
Last active December 11, 2015 08:18
=== modified file 'testtools/testsuite.py'
--- testtools/testsuite.py 2013-01-18 09:17:19 +0000
+++ testtools/testsuite.py 2013-01-19 11:05:50 +0000
@@ -147,6 +147,29 @@
return [(suite_id, suite_or_case)]
+def filtered_tests(suite_or_case, predicate):
+ """Remove tests from suite_or case where predicate(case) returns True.
+
def powerset(iterable):
"powerset([1,2,3]) --> () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,2,3)"
s = list(iterable)
return chain.from_iterable(combinations(s, r) for r in range(len(s)+1))
@jml
jml / gist:5505671
Last active December 16, 2015 22:19
def numeric_to_float(numeric):
if numeric.negative_p():
mulitiplier = -1.0
else:
mulitiplier = 1.0
return mulitiplier * numeric.num() / numeric.denom()
@jml
jml / gist:6022577
Created July 17, 2013 17:22
Napoleon of Notting Hill

"I know of a magic wand, but it is a wand that only one or two may rightly use, and only seldom. It is a fairy wand of great fear, stronger than those who use it—often frightful, often wicked to use. But whatever is touched with it is never again wholly common; whatever is touched with it takes a magic from outside the world. If I touch, with this fairy wand, the railways and the roads of Notting Hill, men will love them, and be afraid of them for ever."

"What the devil are you talking about?" asked the King.

"It has made mean landscapes magnificent, and hovels outlast cathedrals," went on the madman. "Why should it not make lamp-posts fairer than Greek lamps; and an omnibus-ride like a painted ship? The touch of it is the finger of a strange perfection."

"What is your wand?" cried the King, impatiently.

"There it is," said Wayne; and pointed to the floor, where his sword lay flat and shining.