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 / 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 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),
@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 / run.py
Created November 21, 2012 13:46
Sample Celery chain usage for processing pipeline
from celery import chain
from django.core.management.base import BaseCommand
from . import tasks
class Command(BaseCommand):
def handle(self, *args, **kwargs):
@codeinthehole
codeinthehole / decorators.py
Created February 7, 2013 16:39
Basic auth for Django snippet
import base64
from django.http import HttpResponse
from django.contrib.auth import authenticate
from django.conf import settings
def view_or_basicauth(view, request, *args, **kwargs):
# Check for valid basic auth header
if 'HTTP_AUTHORIZATION' in request.META:
@codeinthehole
codeinthehole / portforward.sh
Last active August 6, 2023 22:02
Bash helper function for easier port forwarding - should be added to your ~/.bashrc
# Easier port forwarding - usage:
#
# $ portforward project-app1 5432
#
# where 'project-app1' is an alias from ~/.ssh/config and 5432 is the remote
# port that you want to forward to.
function portforward() {
HOST=$1
REMOTE_PORT=$2
# Pick a random port and check it is free