Skip to content

Instantly share code, notes, and snippets.

View garyvdm's full-sized avatar

Gary van der Merwe garyvdm

  • Johannesburg, South Africa
View GitHub Profile
@garyvdm
garyvdm / test_tools.py
Created May 12, 2014 19:18
Alternative to nost.tools.with_setup decorator, which allows arguments to be returned form the setup function, and passed to the test and teardown functions.
def with_setup_args(setup, teardown=None):
"""Decorator to add setup and/or teardown methods to a test function::
@with_setup_args(setup, teardown)
def test_something():
" ... "
The setup function should return (args, kwargs) which will be passed to
test function, and teardown function.
@garyvdm
garyvdm / headtail
Last active August 29, 2015 13:58
head and tail a stream
#!/usr/bin/env python
import argparse
import sys
import collections
parser = argparse.ArgumentParser(description='Show the first 10, and last 10 lines of a file.')
parser.add_argument('infile', nargs='?', default=sys.stdin,
help='Input file. Defauts to stdin if not provided.')
parser.add_argument('outfile', nargs='?', default=sys.stdout,