Skip to content

Instantly share code, notes, and snippets.

View mmalone's full-sized avatar

Michael Malone mmalone

View GitHub Profile
class FollowerDescriptor(object):
"""
A descriptor which provides access to a user's followers.
"""
def __get__(self, instance, cls):
if not instance:
raise AttributeError('Manager must be accessed via instance')
class RelationshipManager(models.Manager):
def get_query_set(self):
class FriendDescriptor(object):
"""
A descriptor that provides access to a user's friends.
"""
def __get__(self, instance, cls):
if not instance:
raise AttributeError('Manager must be accessed via instance')
Relationship = get_model('friends', 'Relationship')
from django.core.management.base import BaseCommand, CommandError
from django.db.models.loading import get_apps
from django.conf import settings
import simpledb
class Command(BaseCommand):
help = ("Sync all of the SimpleDB domains.")
def handle(self, *args, **options):
import csv
import sys
def csv_to_openstv(filename):
reader = csv.reader(open(filename))
candidates = reader.next()
stv = []
stv.append('%s __seats__' % len(candidates))
for line, row in enumerate(reader):
row = [i for i in row if i]
======================================================
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
from django.views import debug
view_settings = dict(((k.lower(), v) for (k, v) in
debug.get_safe_settings().iteritems()))
def settings(request):
"""
Provides a 'settings' context variable that is a subset of the
Django settings module (the 'safe' settings).
"""
#!/usr/bin/perl
use strict;
use LWP::UserAgent;
my $url = "http://www.reversehttp.net/reversehttp";
my $label = int rand 100000;
warn "Open http://demo$label.www.reversehttp.net/\n";
my $ua = LWP::UserAgent->new;
class AssetTagDescriptor(object):
"""
A descriptor which provides access to an asset's tags.
"""
pre_save_manager_name = '__asset_tag_pre_save_manager_descriptor'
def __get__(self, instance, cls=None):
if not instance:
raise AttributeError('Manager must be accessed via instance')
from app.models import Tag
- simple
- public over private
- personal vanity
- internet is global
- permalinks
- one important item per page
- don't break the browser
- don't wanker in technology
- a medium is not a grande
- break convention for your users
"""
Copyright (c) 2008-2009, Nathan Borror, and modified heavily by Eric Florenzano
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this