Skip to content

Instantly share code, notes, and snippets.

View dhermes's full-sized avatar

Danny Hermes dhermes

View GitHub Profile
@dhermes
dhermes / github_repo_regex.py
Created February 20, 2013 04:01
Github Repo Regex
re.compile('^(http|https|git)://(www|)github.com/'
'(?P<organization>([^/]+))/'
'(?P<repository>((?!(\.git|/)).)+)'
'(.git)?/?$')
@dhermes
dhermes / index.html
Last active December 18, 2015 01:09
<!DOCTYPE html>
<meta charset="utf-8">
<link rel="stylesheet" href="http://cmx.io/v/0.1/cmx.css">
<script src="http://cmx.io/v/0.1/cmx.js" charset="utf-8"></script>
<style>.cmx-user-scene4 .cmx-text-border .cmx-path {stroke: orange}</style>
<body>
<div style="max-width:900px; -webkit-transform:rotate(0deg)">
<scene id="scene1">
<actor t="translate(71,19) rotate(-2)" pose="-11,9|-5,117|-11,99|-11,89|-11,79|-11,59|-16,34|-21,9|-6,34|-1,9|-18,79|-18,59|-6,79|-1,59">
$ 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]