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
from django.core.cache import cache
from django.conf import settings
from django.contrib.auth.models import User
ONLINE_THRESHOLD = getattr(settings, 'ONLINE_THRESHOLD', 60 * 15)
ONLINE_MAX = getattr(settings, 'ONLINE_MAX', 50)
def get_online_now(self):
return User.objects.filter(id__in=self.online_now_ids or [])
@onyxfish
onyxfish / fabfile.py
Created February 9, 2010 23:05
Chicago Tribune News Applications fabric deployment script
from fabric.api import *
"""
Base configuration
"""
env.project_name = '$(project)'
env.database_password = '$(db_password)'
env.site_media_prefix = "site_media"
env.admin_media_prefix = "admin_media"
env.newsapps_media_prefix = "na_media"
@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)
.mouse, #preview{
position: absolute;
background-repeat: no-repeat;
height: 22px;
min-width: 15px;
z-index: 100;
}
.mouse{
background-image: url('../images/cursor.png');
@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
"""
jQuery templates use constructs like:
{{if condition}} print something{{/if}}
This, of course, completely screws up Django templates,
because Django thinks {{ and }} mean something.
Wrap {% verbatim %} and {% endverbatim %} around those
blocks of jQuery templates and this will try its best