Skip to content

Instantly share code, notes, and snippets.

View pmclanahan's full-sized avatar

Paul McLanahan pmclanahan

View GitHub Profile
# Prevent pip from doing anything unless you're inside an activated virtualenv.
PIP=/usr/local/bin/pip
function pip {
if [ "x$VIRTUAL_ENV" = 'x' ]; then
echo "No virtualenv activated; bailing."
else
$PIP -E `basename $VIRTUAL_ENV` "$@"
fi
}
@pmclanahan
pmclanahan / vm_manager.sh
Created March 31, 2010 15:36
Allows you to use both VirtualBox and KVM virtualization on the same machine.
#!/bin/sh
# Allows you to use both VirtualBox and KVM virtualization on the same machine.
# I replaced the commands to start both VB and KVM with this script.
# you'll also need to disable both services from starting automatically.
# sudo update-rc.d qemu-kvm disable
# sudo update-rc.d vboxdrv disable
case "$1" in
The answer to the Ultimate
Question is {{ everything.universe.answer }}.
Among our weapons are:{% for weapon in weapons %}
{{ weapon }}{% endfor %}
@pmclanahan
pmclanahan / middleware.py
Created November 22, 2010 19:25
Django 1.2+ middleware that allows you to set cookies from a request object.
from types import MethodType
from django.http import CompatCookie, HttpRequest
def _set_cookie(self, key, value='', max_age=None, expires=None, path='/',
domain=None, secure=False):
self._resp_cookies[key] = value
self.COOKIES[key] = value
if max_age is not None:
@pmclanahan
pmclanahan / managers.py
Created March 7, 2011 23:14
A class to reduce boilerplate for methods that should exist on Django model managers and querysets.
from django.db.models.manager import Manager
class PassThroughManager(Manager):
'''
Inherit from this Manager to enable you to call any methods from your
custom QuerySet class from your manager. Simply define your QuerySet
class, and return an instance of it from your manager's `get_query_set`
method.
@pmclanahan
pmclanahan / example_template.html
Created May 16, 2011 22:16
Django tag for ICanHaz.js templates
{# ICanHaz templates #}
{% icanhaz %}
{# inside here all occurrences of "[[" will become "{{" and "]]" will be "}}" #}
<script type="text/html" id="contributor_row">
<select name=role_for_[[ id ]]">
{% for role in roles %}
<option value="{{ role.id }}">{{ role.name }}</option>
@pmclanahan
pmclanahan / hostname_middleware.py
Created August 30, 2011 04:06 — forked from robballou/hostname_middleware.py
Django middleware for enforcing a hostname. Using at epio until they provide options for redirects at the loadbalancers.
from django.conf import settings
from django.http import HttpResponsePermanentRedirect
class EnforceHostnameMiddleware(object):
"""
Enforce the hostname per the ENFORCE_HOSTNAME setting in the project's settings
The ENFORCE_HOSTNAME can either be a single host or a list of acceptable hosts
"""
def process_request(self, request):
@pmclanahan
pmclanahan / fields.py
Created July 3, 2012 13:27
A Compressed JSON Field for Django.
import zlib
from base64 import b64decode, b64encode
from django.db import models
# django-jsonfield
from jsonfield import JSONField
class CompressedJSONField(JSONField):
@pmclanahan
pmclanahan / gist:3277709
Created August 6, 2012 19:18
Bug 780545 - Remove special redirects from bug 767985.
Index: includes/prefetch.php
===================================================================
--- includes/prefetch.php (revision 108075)
+++ includes/prefetch.php (working copy)
@@ -198,15 +198,8 @@
if($parsed_path == '/firefox') {
// Redirect mobile devices (Android, Maemo, iPhone)
$is_mobile_redirected = mobile_redirect('/mobile/', 'iphone|ipad');
- // Bug 767985 - Special redirects for Firefox Native Android launch
- if($is_mobile_redirected) {
{"bugzilla_url":"https://bugzilla.mozilla.org/show_bug.cgi?id=719170%2C257398%2C288329%2C333418%2C352047%2C363711%2C384806%2C401399%2C425764%2C433509%2C433617%2C434182%2C435894%2C452659%2C459291%2C467717%2C467912%2C473886%2C474390%2C475817%2C484672%2C507315%2C514793%2C537305%2C547766%2C559543%2C562256%2C566315%2C585709%2C601858%2C610150%2C611028%2C619904%2C628958%2C634848%2C634999%2C658354%2C658871%2C663678%2C670512%2C673821%2C691766%2C692844%2C692850%2C692853%2C693285%2C697655%2C699545%2C703817%2C724518%2C724835%2C736851%2C737302%2C738026%2C749644%2C755285%2C767325%2C780216%2C780677%2C780740%2C781003%2C782951%2C783884%2C784206%2C785195%2C778504%2C771006%2C777361%2C612926%2C767724%2C750848%2C202522%2C247591%2C700259%2C726982%2C742123%2C749313%2C547448%2C340697%2C344912%2C374463%2C409848%2C454967%2C487089%2C507885%2C672807%2C733799%2C783446%2C676122%2C698427%2C781551%2C785212%2C785214%2C785216%2C785218%2C697714%2C741661%2C426183%2C698069%2C665084%2C679405%2C718522%2C429286%2C343653%2C702702%2C629932%2C7864%2C1