Skip to content

Instantly share code, notes, and snippets.

@robhudson
robhudson / ipy_user_conf.py
Created March 20, 2009 22:08 — forked from jacobian/ipy_user_conf.py
Fork of Jacob's ipython config to make the prompt just like standard Python
import os
import time
import readline
import ipy_defaults
import IPython.ipapi
import ipy_stock_completers
ip = IPython.ipapi.get()
o = ip.options
from mimetypes import guess_type
from django.core.exceptions import ImproperlyConfigured
from django.core.files.storage import Storage
from django.utils.encoding import iri_to_uri
import re
try:
import S3
except ImportError:
raise ImproperlyConfigured, "Could not load amazon's S3 bindings.\
@robhudson
robhudson / gist:118990
Created May 28, 2009 00:02
Copy/Paste to print SQL in the Django shell
"""
A quick copy/paste action you can drop into your `./manage.py shell` session so any
queries executed are displayed in the shell output.
If sqlparse is available it will use that to pretty print the SQL:
http://code.google.com/p/python-sqlparse/
"""
from django.db.backends import util
try:
import sqlparse
@robhudson
robhudson / clean_settings.py
Created May 28, 2009 14:06
Cleaned up and alphabetical settings
import os
PROJECT_PATH = os.path.realpath(os.path.dirname(__file__))
ADMINS = (('Your Name', '[email protected]'),)
ADMIN_MEDIA_PREFIX = '/static/admin/'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': '',
'USER': '',
@robhudson
robhudson / gist:202599
Created October 5, 2009 23:39
Super minimal Disqus API client
"""Super minimal Disqus API client"""
import urllib
try:
import json
except ImportError:
import simplejson as json
class DisqusClient(object):
@robhudson
robhudson / parse_date.py
Created October 8, 2009 23:47
parse_date template tag
import datetime
from django.template import Library
from django.template.defaultfilters import stringfilter
register = Library()
@stringfilter
def parse_date(date_string, format):
"""
@robhudson
robhudson / gist:423138
Created June 2, 2010 22:54
Django error logging middleware for GoPlanApp
class GPATicketErrorLogMiddleware(object):
@transaction.commit_on_success
def process_exception(self, request, exception):
import oauth2 as oauth
import sys
import traceback
create_ticket_url = 'http://%s.goplanapp.com/api/tickets/create' % (
def roll_release(version):
local('git flow release start %s' % (version,), capture=True)
local('sed -e "s/\'AWS_PREFIX\':.*$/\'AWS_PREFIX\': \'%s\', # cache bust/g" -i \'\' potluck/settings/base.py' % (version,))
local('git commit -am \'Bumped media version to %s\'' % (version,))
local('git flow release finish -m %s -p %s' % (version, version), capture=True)
@robhudson
robhudson / dumpdata_to_s3.sh
Created March 8, 2011 18:02
One-liner for cron to backup a Django project to S3 using dumpdata
# Assumptions:
#
# Assumes boto is installed which comes with the s3put command
#
# Assumes your S3 keys are in ~/.boto in the form:
#
# [Credentials]
# aws_access_key_id = XXX
# aws_secret_access_key = XXX
#
@robhudson
robhudson / post-merge
Created September 18, 2012 16:41
git post-merge hook to look for changes to requirements
#!/bin/sh
if [ $(git diff HEAD@{1} HEAD --name-only | grep 'requirements/' -c) -ne 0 ]
then
$VIRTUAL_ENV/bin/pip install -r requirements/dev.txt
fi