Skip to content

Instantly share code, notes, and snippets.

@tomviner
tomviner / spottylotty.py
Created September 9, 2011 15:43
Spotify Ticket Lottery
from __future__ import division
import sys
import math
import random
# http://www.spotify.com/us/jobs/tech/ticket-lottery/
def bc(n, k, f=math.factorial):
"""Binomial coefficient in terms of Factorials
(n) = ____n!____
@jaymzcd
jaymzcd / assign_file.py
Created July 13, 2011 11:23
Assign slugs and images based on a models fields - commands to use with a django shell
def assign_file_to_model(module, model_class=None, file_field='main_image', source_field='body', skip_existing=True, verbose=False):
""" We tend to have "main image" fields on models that hold a primary image used
across the sites for things like list pages and headers. Often on import of
existing data we have images mangled within copy or lists. """
import urllib2
from posixpath import basename
from BeautifulSoup import BeautifulSoup as Soup
from django.db import IntegrityError
======================================================
Setting up Django using Apache/mod_wsgi on Ubuntu 8.10
======================================================
This article will cover setting up Django using Apache/mod_wsgi on Ubuntu
8.10. The article is targeted at a production environment, but keep in mind
this is a more generalized environment. You may have different requirements,
but this article should at least provide the stepping stones.
The article will use distribution packages where nesscary. As of 8.10 the