Skip to content

Instantly share code, notes, and snippets.

View samos123's full-sized avatar
🎯
Focusing

Sam Stoelinga samos123

🎯
Focusing
View GitHub Profile
@samos123
samos123 / models.py
Created February 28, 2012 14:22 — forked from treyhunner/models.py
Encrypt and decrypt Django model primary key values (useful for publicly viewable unique identifiers)
# This code is under the MIT license.
# Inspired by this StackOverflow question:
http://stackoverflow.com/questions/3295405/creating-django-objects-with-a-random-primary-key
import struct
from Crypto.Cipher import DES
from django.db import models
def base36encode(number):
@samos123
samos123 / tree.md
Created April 25, 2012 07:53 — forked from hrldcpr/tree.md
one-line tree in python

One-line Tree in Python

Using Python's built-in defaultdict we can easily define a tree data structure:

def tree(): return defaultdict(tree)

That's it!