Skip to content

Instantly share code, notes, and snippets.

@jough
jough / keybase.md
Created July 14, 2014 21:57
Keybase Identity

Keybase proof

I hereby claim:

  • I am jough on github.
  • I am jough (https://keybase.io/jough) on keybase.
  • I have a public key whose fingerprint is BC93 C7ED 0B99 A4D0 4256 19AC AA10 4337 A886 2B15

To claim this, I am signing this object:

@jough
jough / circular_slice
Created September 9, 2013 21:28
Circular list slicing - pass in a list, a `page`, and how many items you want per page - get a nice sliced list of length `per_page` back.
def circular_slice(list_to_slice, page=1, per_page=5):
"""
Circular list slicing - pass in a list, a `page`, and
how many items you want per page - get a nice
sliced list of length `per_page` back.
>>> l = [x for x in xrange(0, 10)]
>>> circular_slice(l, per_page=4, page=1)
[0, 1, 2, 3]
>>> circular_slice(l, per_page=4, page=2)
@jough
jough / exhaust_data
Created September 9, 2013 21:24
Exhaust data from a Python dict with lists values (ordered or otherwise) to zipper sequences together into a single list.
from collections import OrderedDict
content = []
data = OrderedDict()
data['key1'] = [1, 2, 3, 4, 5]
data['key2'] = [6, 7, 8, 9, 10]
data['key3'] = ['A', 'B', 'C', 'D']
data['key4'] = [11, 12]
def exhaust_data(content, previous_key=None):