Skip to content

Instantly share code, notes, and snippets.

View codeinthehole's full-sized avatar
🌏
The main difference between dinosaurs and us is we're building our own meteor.

David Winterbottom codeinthehole

🌏
The main difference between dinosaurs and us is we're building our own meteor.
View GitHub Profile
@codeinthehole
codeinthehole / pre-commit
Created March 3, 2012 20:14 — forked from spulec/pre-commit
Yipit Pre-commit Hook
#!/usr/bin/env python
import os
import re
import subprocess
import sys
modified = re.compile('^(?:M|A)(\s+)(?P<name>.*)')
CHECKS = [
@codeinthehole
codeinthehole / url_api.py
Created March 16, 2012 12:02
Desired API for a python URL object
import requests
from someurllib import URL
# 1. Build request URL
url = URL(host='maps.google.com')
url.path('/geocoding/xml/')
.param('q', 'Some address string')
.param('sensor', 'False')
.fragment('something')
import random
import time
def pick_winners(candidates, num_winners):
for i in range(num_winners):
time.sleep(1)
winner = random.choice(candidates)
print "Winner %d: %s" % (i+1, winner)
candidates.remove(winner)
print "\nSorry %s\n" % ", ".join(candidates)
@codeinthehole
codeinthehole / oscar-postcard.txt
Created May 17, 2012 14:53
First draft of copy for oscar marketing postcard.
Front Side:
Oscar - Bad-ass e-commerce for ninjas
Back side:
Oscar is a new e-commerce framework for generating electric synergy between your development rockstars and your marketing weasels
Features? No features, just endless possibilities:
* A fully recursive stack-driven, reverse-proxying domain generator
* Strict adherance to sandwich-driven development
#!/usr/bin/env python
import sys
import re
from xml.dom.minidom import parseString
def format_xml(xml_str):
xml_str = re.sub(r'\s*\n\s*', '', xml_str)
ugly = parseString(xml_str).toprettyxml(indent=' ')
regex = re.compile(r'>\n\s+([^<>\s].*?)\n\s+</', re.DOTALL)
@codeinthehole
codeinthehole / models.py
Created September 4, 2012 08:25
Models for store opening times
from django.db import models
from django.utils.translation import ugettext_lazy as _
class WeekdayOpeningPeriod(models.Model):
store = models.ForeignKey('stores.Store', related_name='opening_periods')
SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY = range(7)
weekday_choices = (
@codeinthehole
codeinthehole / models.py
Created September 13, 2012 16:04
Model for a simple notification
class Notification(models.Model):
recipient = models.ForeignKey('auth.User', related_name='notifications')
# HTML is allowed in this field as it can contain links
text = models.CharField(max_length=255)
# Some projects may want to categorise their notifications. You may want
# to use this field to show a different icons next to the notification.
category = models.CharField(max_length=255, null=True)
@codeinthehole
codeinthehole / models.py
Created September 13, 2012 16:11
Another model for a notification
class Notification(models.Model):
sender = models.ForeignKey('auth.User', null=True)
recipient = models.ForeignKey('auth.User', related_name='notifications')
subject = models.CharField(max_length=255)
body = models.TextField()
# Some projects may want to categorise their notifications. You may want
# to use this field to show a different icons next to the notification.
category = models.CharField(max_length=255, null=True)
@codeinthehole
codeinthehole / tasks.py
Created November 19, 2012 11:36
Task structure for a job-queue-based processing pipeline
from celery import celery
@celery.task
def fetch():
"""
Download files from FTP server
This tasks could be trigger by a cronjob to start the processing pipeline.
When file(s) downloaded successfully, create a set of partner_prepare jobs
@codeinthehole
codeinthehole / models.py
Created August 7, 2012 13:36
Models for double-book-keeping accounting for managed budgets.
from django.db import models
class Ledger(models.Model):
# There can only be one 'Labour' and 'Shop' ledger but lots of 'Budget'
# ledgers.
LABOUR, BUDGET, SHOP = 'Labour', 'Budget', 'Shop'
LEDGER_CHOICES = (
(LABOUR, LABOUR),
(BUDGET, BUDGET),