Skip to content

Instantly share code, notes, and snippets.

@m0n5t3r
m0n5t3r / gunicorn-upstart.conf.template
Created July 30, 2010 12:27
template for a gunicorn upstart job that can run several instances of a django application
# %(mysite)s - run %(mysite)s instances (default is the main production instance)
#
# This runs gunicorn-django for %(mysite)s; to install:
# * sudo ln -s <this file> /etc/init/%(mysite)s
# * sudo initctl reload-configuration
#
# it expects the following directory layout:
#
# /home/%(mysite)s/public_html
# \-env -> virtualenv
@gvangool
gvangool / admin_autoregister.py
Created August 1, 2010 08:20
Django-admin autoregister -- automatic model registration
""" Django-admin autoregister -- automatic model registration
Original: http://djangosnippets.org/snippets/2066/
## sample admin.py ##
from yourproject.autoregister import autoregister
# register all models defined on each app
autoregister('app1', 'app2', 'app3', ...)
# upstart job for supervisord
description "supervisord process supervisor"
author "Sabin Iacob <iacobs@m0n5t3r.info>"
start on runlevel [2345]
stop on runlevel [016]
respawn
respawn limit 10 5
#!/usr/bin/env ruby
# Aside from removing Ruby on Rails specific code this is taken verbatim from
# mislav's git-deploy (http://github.com/mislav/git-deploy) and it's awesome
# - Ryan Florence (http://ryanflorence.com)
#
# Install this hook to a remote repository with a working tree, when you push
# to it, this hook will reset the head so the files are updated
if ENV['GIT_DIR'] == '.'
@jacobian
jacobian / models.py
Created February 15, 2011 18:11
An example of using many-to-many "through" to augment m2m relationships. See http://www.quora.com/How-do-you-query-with-a-condition-on-a-ManyToMany-model-in-Django for context.
from django.db import models
class Person(models.Model):
name = models.CharField(max_length=200)
groups = models.ManyToManyField('Group', through='GroupMember', related_name='people')
class Meta:
ordering = ['name']
def __unicode__(self):
@ianoxley
ianoxley / base58.py
Created March 11, 2011 14:00
base58 encoding in Python
""" base58 encoding / decoding functions """
import unittest
alphabet = '123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ'
base_count = len(alphabet)
def encode(num):
""" Returns num in a base58-encoded string """
encode = ''
@mikeyk
mikeyk / redis_session_backend.py
Created April 8, 2011 18:01
A redis backend for Django Sessions, tested on Django 1.3+
from django.contrib.sessions.backends.base import SessionBase, CreateError
from django.conf import settings
from django.utils.encoding import force_unicode
import redis
class SessionStore(SessionBase):
""" Redis store for sessions"""
def __init__(self, session_key=None):
self.redis = redis.Redis(
@c4milo
c4milo / yourservice.conf
Created April 25, 2011 18:05
upstart example script
# Ubuntu upstart file at /etc/init/yourservice.conf
pre-start script
mkdir -p /var/log/yourcompany/
end script
respawn
respawn limit 15 5
start on runlevel [2345]
@linuxbender
linuxbender / .bash_profile
Created May 11, 2011 12:28
SSH with plink (putty) = remote send linux command
if [[ $- != *i* ]] ; then
ON_A_TTY=No
else
ON_A_TTY=Yes
fi
# check that an ssh-agent is running
if [ -x /usr/bin/ssh-agent ]
then
SSH_AGENT_PID=-1
@amcclosky
amcclosky / remove_foreign_keys.py
Created May 26, 2011 22:37
Remove all foreign key constraints from a MySQL database with Django 1.3
"""
remove_foreign_keys.py
Removes all the foreign key constraints in a django project's MySQL database.
NO FOREIGN KEYS = NO FOREIGN KEY HEADACHES
(of course if you are using anything other than the django ORM its likely to cause other headaches)
Before running this script be sure your django settings module is available
to your environment.