Skip to content

Instantly share code, notes, and snippets.

View pmclanahan's full-sized avatar

Paul McLanahan pmclanahan

View GitHub Profile
for file in `git diff-tree --no-commit-id --name-only -r HEAD | sort | uniq`
do
if [ ${file: -3} == ".py" ]
then
flake8 --ignore=E121,E123,E124,E125,E126,E127,E128 $file
fi
if [ ${file: -3} == ".js" ]
then
jshint $file
fi
@peterbe
peterbe / gist:2913338
Created June 11, 2012 23:13
A very practical decorator for Django Class Based Views
from django.utils.decorators import method_decorator
def class_decorator(decorator):
def inner(cls):
orig_dispatch = cls.dispatch
@method_decorator(decorator)
def new_dispatch(self, request, *args, **kwargs):
return orig_dispatch(self, request, *args, **kwargs)
cls.dispatch = new_dispatch
return cls
@mtigas
mtigas / middleware.py
Created February 13, 2012 01:14
An SSL-enforcing middleware
from django.conf import settings
from django.http import HttpResponsePermanentRedirect, get_host
class ForceSSLMiddleware(object):
"""
Redirects all (non-DEBUG) requests to go through SSL.
Picks up the `HTTP_X_FORWARDED_PROTO` proxy header set by Heroku.
Also sets the "Strict-Transport-Security" header for 600 seconds so that
@fish2000
fish2000 / readability.py
Created September 30, 2010 05:51
python port of Arc90 readability.js (circa 2009)
#!/usr/bin/env python
# encoding: utf-8
#####
##### Readability.py -- by fish. © 2009, Some Rights Reserved But Some May Be
##### http://objectsinspaceandtime.com/
#####
##### it's a python port of the Readability JavaScript bookmarklet,
##### by Arc90 Labs --
##### http://lab.arc90.com/2009/03/readability.php
"Memcached cache backend"
from django.core.cache.backends import memcached
from django.utils.encoding import smart_unicode, smart_str
MIN_COMPRESS_LEN = 150000
class CacheClass(memcached.CacheClass):
def add(self, key, value, timeout=None, min_compress_len=MIN_COMPRESS_LEN):
if isinstance(value, unicode):
"""
A two-part middleware which modifies request.COOKIES and adds a set and delete method.
`set` matches django.http.HttpResponse.set_cookie
`delete` matches django.http.HttpResponse.delete_cookie
MIDDLEWARE_CLASSES = (
'django_cookies.CookiePreHandlerMiddleware',
...
'django_cookies.CookiePostHandlerMiddleware',