Skip to content

Instantly share code, notes, and snippets.

View dirn's full-sized avatar
🤔

Andy Dirnberger dirn

🤔
View GitHub Profile
from kombu import Connection, Exchange, Queue
from kombu.mixins import ConsumerMixin
queue = Queue('hello', exchange=Exchange('hello', type='direct'),
routing_key='hello')
class Worker(ConsumerMixin):
def __init__(self, connection):
def balanced(s):
unmatched = 0
for c in s:
if c == ')':
if not unmatched:
return False
unmatched -= 1
elif c == '(':
unmatched += 1
return unmatched == 0
@dirn
dirn / BrBa.rst
Created September 29, 2013 15:16
Breaking Bad Pick Em

+-------------------+-------+------+ | Character | Lives | Dies | +===================+=======+======+ | Walter White | X | | +-------------------+-------+------+ | Skyler White | X | | +-------------------+-------+------+ | Jesse Pinkman | | X | + +-------+------+ | | Uncle Jack |

@dirn
dirn / .pylintrc
Created September 25, 2013 13:19
[MASTER]
# Specify a configuration file.
#rcfile=
# Python code to execute, usually for sys.path manipulation such as
# pygtk.require().
#init-hook=
# Profiled execution.
@dirn
dirn / pandigital.py
Created September 25, 2013 03:40
is_pandigital
def is_pandigital(*args, n=9):
values = set(''.join(map(str, args)))
return '0' not in values and len(values) == n
@dirn
dirn / andy.py
Last active December 21, 2015 22:59
String Concatenation
from itertools import chain, islice
s1 = '4K Media'
s2 = '53 W. 23rd St.'
s3 = ''.join(chain(islice(filter(str.isalnum, s1), 4),
islice(filter(str.isalnum, s2), 8)))
assert s3 == '4KMe53W23rdS'
@dirn
dirn / digits.py
Last active December 21, 2015 02:38
digits(n)
from math import floor, log
def digits(n):
yield from (n // (10 ** x) % 10 for x in range(floor(log(n, 10)), -1, -1))
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')
@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):
@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')