Skip to content

Instantly share code, notes, and snippets.

@winhamwr
winhamwr / gist:205450
Created October 8, 2009 21:55
Celery /etc/init.d script to keep celeryd running
#!/bin/sh
USER=%(user)s
NAME=celeryd
VIRTUALENV=%(virtualenv_dir)s
PROJECT_ROOT=%(project_root)s
DAEMON=$VIRTUALENV/bin/celeryd
PIDFILE=$PROJECT_ROOT/$NAME.pid
LOGFILE=$PROJECT_ROOT/$NAME.log
@eculver
eculver / A generic cache manager.
Created April 20, 2010 17:55
A generic cache manager
import random
from django.db import models
from django.core.cache import cache
class CacheManager(models.Manager):
'''Generic Cache Manager based on the concept of generator ids to
handle invalidation of collections.
'''
def _test_model(self, obj):
#!/usr/bin/env python
import os
import sys
import subprocess
def simplify_pg_index_line(line):
"""
Given a postgres index file line returns it's simplified form.
Returns None for comments
import time
from contextlib import contextmanager
@contextmanager
def easyprofile(msg):
before = time.time()
yield
print '%s took %0.2fsec' % (msg, time.time() - before)
@samchandra
samchandra / gist:591363
Created September 22, 2010 08:30
Creating transparent UIWebView as UITableViewCell
// Creating UITableView Cell
// Transparent UIWebView
CGRect cellFrame = CGRectMake(0, 0, 320, 100);
cell = [[[UITableViewCell alloc] initWithFrame:cellFrame] autorelease];
CGRect labelFrame = CGRectMake(5,5,310,90);
UIWebView *textWebView = [[[UIWebView alloc] initWithFrame:labelFrame] autorelease];
textWebView.backgroundColor = [UIColor clearColor];
[textWebView setOpaque:NO];
@jacobian
jacobian / virtualenv-example.rb
Created October 5, 2010 21:36
My first Chef definition: create a virtualenv. Be nice.
# An example of the below
virtualenv "/home/dvcsmirrors/hg" do
owner "root"
group "dvcsmirrors"
mode 0775
packages "Mercurial" => "1.6.3",
"hgsubversion" => "1.1.2"
end
@ericflo
ericflo / 00_logging.py
Created October 25, 2010 07:49
Log structured data about events that happen in your system (in JSON format for maximum flexibility).
# 00 prepended to filename so this shows up first in the list of gists.
import socket
import time
import simplejson
from django.conf import settings
def log_event(logger, event, request=None, data=None,
@HenrikJoreteg
HenrikJoreteg / straight_include.py
Created December 15, 2010 16:06
A Django Template tag for including files that you don't want to parse as templates
"""
Straight Include template tag by @HenrikJoreteg
Django templates don't give us any way to escape template tags.
So if you ever need to include client side templates for ICanHaz.js (or anything else that
may confuse django's templating engine) You can is this little snippet.
Just use it as you would a normal {% include %} tag. It just won't process the included text.
@staer
staer / MultiAuthentication.py
Created January 21, 2011 19:13
Custom Django-Piston authentication backend that can handle multiple types of auth methods
# Class that can help django-piston process multiple types of authentication
# Example usage:
#
# from piston.authentication import HttpBasicAuthentication
# from somewhere import OtherCustomAuthModule
#
# httpAuth = HttpBasicAuthentication(realm="CycleCloud")
# otherAuth = OtherCustomAuthModule()
#
# auth = MultiAuthentication([httpAuth, otherAuth])
@eculver
eculver / Projects with beautiful websites
Created February 10, 2011 18:54
Projects with beautiful websites
Vows: http://vowsjs.org/
SASS: http://sass-lang.com/
SSHGuard (pretty decent layout): http://www.sshguard.net/
Django Haystack: http://haystacksearch.org/
twelvesouth (products not project, but still): http://www.twelvesouth.com/