Skip to content

Instantly share code, notes, and snippets.

View dirn's full-sized avatar
🤔

Andy Dirnberger dirn

🤔
View GitHub Profile
@dirn
dirn / example.py
Created June 11, 2012 05:25
Switches example
"""Build a script with Switches"""
from switches import command, commandline
@command
def spam(eggs):
"""This function prints the value of eggs"""
print eggs
@dirn
dirn / enableconfig.sh
Created September 17, 2012 22:04
Enable environment settings for collectstatic on Heroku
# https://devcenter.heroku.com/articles/django-assets
heroku labs:enable user-env-compile -a [app_name]
@dirn
dirn / gist:3943102
Last active October 12, 2015 00:27
Sublime Text 2 Settings
{
"color_scheme": "Packages/Tomorrow-Night-Bright.tmTheme",
"detect_indentation": false,
"ensure_newline_at_eof_on_save": true,
"find_selected_text": true,
"fold_buttons": false,
"folder_exclude_patterns":
[
"_build",
"__pycache__",
@dirn
dirn / anagrams.py
Last active December 15, 2015 02:49
PyCon Anagrams
#!/usr/bin/env python
"""Checks for anagrams in stdin.
Example: $ curl -sL http://thumb.tk/8Qdr | python anagrams.py
"""
import itertools
import sys
@dirn
dirn / example.py
Last active December 16, 2015 18:39
`len()`, old vs new
>>> class A:
... pass
...
>>> class B(object):
... pass
...
>>> class C:
... def __len__(self):
... return 0
...
@dirn
dirn / flattr.py
Last active December 18, 2015 02:58
Flatten
__all__ = ('flatten',)
from collections import Iterable
sentinel = []
def flatten(to_flatten):
flat = _flatten(to_flatten, lambda x: x)
while iterable(flat) and flat and callable(flat[0]):
@dirn
dirn / pre-commit
Last active December 18, 2015 05:19 — forked from spulec/pre-commit
#!/usr/bin/env python
import os
import re
import subprocess
import sys
modified = re.compile('^(?:M|A)(\s+)(?P<name>.*)')
CHECKS = [
@dirn
dirn / compat.py
Last active December 18, 2015 15:49
Stripped down Python 2 and 3 compatibility module, parts borrowed from six and Jinja2
import sys
PY2 = sys.version_info[0] == 2
if PY2:
_iteritems = 'iteritems'
_iterkeys = 'iterkeys'
_itervalues = 'itervalues'
exec('def reraise(tp, value, tb=None):\n raise tp, value, tb')
@dirn
dirn / descriptor_tests.py
Created June 24, 2013 01:11
Descriptor tests
import unittest
from weakref import WeakKeyDictionary
class Skippable(object):
def __init__(self, field_name):
self.data = WeakKeyDictionary()
self.field_name = field_name
def __get__(self, instance, owner):
from collections import deque
import curses
from random import randrange, shuffle
from time import sleep
def display(stdscr, state):
stdscr.addstr(0, 0, ' '.join(state))
stdscr.addstr(1, 0, ' ' * (len(state) // 2) + '\u2191')