This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Collections; | |
import java.util.Comparator; | |
import org.objectweb.asm.Label; | |
import org.objectweb.asm.MethodVisitor; | |
import org.objectweb.asm.tree.MethodNode; | |
import org.objectweb.asm.tree.TryCatchBlockNode; | |
/** | |
* Sorts the exception handlers in a method innermost-to-outermost. This | |
* allows the programmer to add handlers without worrying about ordering them |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""A simple addition to Python's optparse module supporting subcommands | |
like those found in the svn or hg CLIs. | |
To use it, instantiate the Subcommand class for every subcommand you | |
want to support. Each subcommand has a name, aliases, a help message, | |
and a separate OptionParser instance. Then pass a list of Subcommands | |
to the constructor of SubcommandsOptionParser to make a subcommand- | |
aware parser. Calling parse_args on that parser gives you the | |
subcommand invoked, the subcommand's arguments and options, and the | |
global options all in one fell swoop. See the smoke test at the bottom |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""A metaclass for enumerated types that really are types. | |
You can create enumerations with `enum(values, [name])` and they work | |
how you would expect them to. | |
>>> from enumeration import enum | |
>>> Direction = enum('north east south west', name='Direction') | |
>>> Direction.west | |
Direction.west | |
>>> Direction.west == Direction.west |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
"""Aliases for argparse positional arguments.""" | |
import argparse | |
class AliasedSubParsersAction(argparse._SubParsersAction): | |
class _AliasedPseudoAction(argparse.Action): | |
def __init__(self, name, aliases, help): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
"""Quickly get a temporary Ubuntu EC2 instance, SSH into it, and then | |
terminate the instance on logout. | |
""" | |
import boto | |
import subprocess | |
import time | |
# Set your AWS credentials. | |
EC2_ACCESS = '' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Plot time data from a Runmeter <http://www.abvio.com/runmeter/> | |
data export.""" | |
import csv | |
import sys | |
from collections import defaultdict | |
import datetime | |
def runmeter_read(path): | |
doc = csv.reader(open(path)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Simple but robust implementation of generator/coroutine-based | |
pipelines in Python. The pipelines may be run either sequentially | |
(single-threaded) or in parallel (one thread per pipeline stage). | |
This implementation supports pipeline bubbles (indications that the | |
processing for a certain item should abort). To use them, yield the | |
BUBBLE constant from any stage coroutine except the last. | |
In the parallel case, the implementation transparently handles thread | |
shutdown when the processing is complete and when a stage raises an |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff -r 6a862c34b61f fplib/CMakeLists.txt | |
--- a/fplib/CMakeLists.txt Mon Jul 12 18:14:59 2010 +0100 | |
+++ b/fplib/CMakeLists.txt Mon Jan 31 16:49:31 2011 -0800 | |
@@ -19,6 +19,7 @@ | |
IF(APPLE) | |
INCLUDE_DIRECTORIES(/opt/local/include/) | |
+LINK_DIRECTORIES(${LINK_DIRECTORIES} /opt/local/lib/) | |
ENDIF(APPLE) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""A couple of very simple utilities for reading and writing files | |
that contain multiple JSON values. Could be useful in situations where | |
you're generating a bunch of data for later processing and then, later, | |
you want to read it in an element at a time. | |
The json module doesn't really support streaming reads, though, so this | |
is limited by that. If you need real streaming, you probably want to use | |
something like ijson: | |
http://pypi.python.org/pypi/ijson/ | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def _make_id_getter(entity): | |
def getter(id, **kwargs): | |
includes = [] | |
for name in kwargs: | |
if not name.startswith('inc_'): | |
raise TypeError('got unexpected keyword argument...') | |
elif kwargs[name]: | |
includes.append(name[4:]) | |
return _do_mb_query(entity, id, includes) | |
getter.__name__ = 'get_%s_by_id' % entity |
OlderNewer