Skip to content

Instantly share code, notes, and snippets.

View dhermes's full-sized avatar

Danny Hermes dhermes

View GitHub Profile
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
$ git checkout --detach HEAD
...
$ git branch
* (detached from HEAD)
master
$ git branch -m master master-dirty
$ git branch
* (detached from HEAD)
master-dirty
$ git branch master origin/master
$ tox
GLOB sdist-make: /Users/dhermes/google_contracting/gcloud-python/setup.py
py26 inst-nodeps: /Users/dhermes/google_contracting/gcloud-python/.tox/dist/gcloud-0.02.2.zip
py26 runtests: PYTHONHASHSEED='189486614'
py26 runtests: commands[0] | nosetests
............
----------------------------------------------------------------------
Ran 12 tests in 1.541s
OK
@dhermes
dhermes / indent_docstrings.py
Last active August 29, 2015 14:06
An `ast` parser which (mostly) correctly indents Python docstrings.
import __builtin__
import ast
import collections
import shutil
import sys
import tempfile
TRIPLE_QUOTES = ('"""', '\'\'\'')
# Also see: http://stackoverflow.com/a/17478618/1068170
@dhermes
dhermes / itertools_example.py
Last active August 29, 2015 14:07
itertools-product-example
>>> import itertools
>>> for pair in itertools.product((0, 1), repeat=2):
... print pair
...
(0, 0)
(0, 1)
(1, 0)
(1, 1)
>>> len(list(itertools.product((0, 1), repeat=5)))
32
def fits_criterion(digit_list):
for i in xrange(10):
if digit_list.count(i) != digit_list[i]:
return False
return True
for first5 in xrange(10**4, 10**5):
first5_list = map(int, str(first5))
for last5 in itertools.product((0, 1), repeat=5):
digit_list = first5_list + list(last5) # last5 is a tuple
if fits_criterion(digit_list):
print digit_list
[6, 2, 1, 0, 0, 0, 1, 0, 0, 0]
"""Plugin for pylint to suppress warnings on tests.
Turns off the following pylint errors/warnings:
- Docstring checks in test modules.
- Too few public methods on test classes.
- Too many public methods on subclasses of unittest.TestCase.
- Invalid names on all functions/methods.
- Private attribute mangling outside __init__ method.
- Invalid variable name assignment.
"""