Skip to content

Instantly share code, notes, and snippets.

View ashchristopher's full-sized avatar

Ash Christopher ashchristopher

  • Shopify
  • Toronto, Ontario
View GitHub Profile
@jimbojsb
jimbojsb / gist:1630790
Created January 18, 2012 03:52
Code highlighting for Keynote presentations

Step 0:

Get Homebrew installed on your mac if you don't already have it

Step 1:

Install highlight. "brew install highlight". (This brings down Lua and Boost as well)

Step 2:

@bartek
bartek / bulk_delete.py
Created December 30, 2011 17:53
efficient bulk_delete for Django
"""
This is a quick hack that adds a bulk_delete function, which given a queryset will run the Django
implemented DeleteQuery. The purpose of this is when you have thousands (or in my case, millions)
of records to delete, I did not want to get the pk_list of every record and store that into memory,
like Django does naturally, and instead just execute a single query with its WHERE clauses.
There are probably some issues with this, in regards to ForeignKeys and cascading. More info can
be found in this ticket, which looks to implement a bulk_delete functionality into the core:
https://code.djangoproject.com/ticket/9519
@wolever
wolever / README.md
Created December 14, 2011 04:23
EMPMYMIP: Easily Maintain a PyPI Mirror of Your Important Packages!
@jonashaag
jonashaag / 0-howto-listfield-django-admin.rst
Created September 7, 2011 09:41
Howto use ListFields in Django's admin

Howto use ListFields in Django's admin

Problem

Consider this blog post model:

models.py

@joestump
joestump / test.py
Created May 13, 2011 21:38
A drop-in replacement for Django's test mange.py command that uses coverage.
from django.conf import settings
from django.core.management.base import CommandError
from optparse import make_option
import re
import sys
try:
from south.management.commands.test import Command as BaseCommand
except ImportError:
@defrex
defrex / jquery.500frame.js
Created April 11, 2011 19:06
pop-up any 500s in an iframe using jQuery. Especially useful for Django errors.
$(document).bind('ajaxError', function(e, jqXHR){
if (jqXHR.status == 500){
var erframe = document.createElement('iframe');
$('body').append(erframe);
$(erframe).css({
'position': 'absolute',
'top': '5%', 'left': '50%',
'width': '90%', 'height': '90%',
'marginLeft': '-45%'
}).attr('id', 'errorframe');
@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(
@parente
parente / runinenv.sh
Created February 15, 2011 01:54
run a command in virtualenv, useful for supervisord
#!/bin/bash
VENV=$1
if [ -z $VENV ]; then
echo "usage: runinenv [virtualenv_path] CMDS"
exit 1
fi
. ${VENV}/bin/activate
shift 1
echo "Executing $@ in ${VENV}"
exec "$@"
@bartek
bartek / googlemap_location.js
Created December 13, 2010 14:48
A simple Google Map Widget with a lat/lng marker. JS file included and required.
/*
* A simple Google maps Javascript widget which will display a map and
* a marker with the ability to move the marker, then setting the
* lat/lng of the marker into the specified (or default) fields.
*/
var google_map_location = new function() {
var jQuery;
var init_options;
var geocoder;
@acdha
acdha / test-coverage.py
Created January 28, 2010 14:57
A custom Django test runner with support for coverage.py and graceful handling for app selection and various testing gotchas
#!/usr/bin/env python
"""
Run Django Tests with full test coverage
This starts coverage early enough to get all of the model loading &
other startup code. It also allows you to change the output location
from $PROJECT_ROOT/coverage by setting the $TEST_COVERAGE_OUTPUT_DIR
environmental variable.
"""