Skip to content

Instantly share code, notes, and snippets.

View ryanwitt's full-sized avatar

Ryan Witt ryanwitt

  • New York, NY
View GitHub Profile
@login_required # This is the decorator! One line... simple.
def my_view(request):
# Do something here to turn the request into an HTML page.
# ...
# settings.py
LOGIN_URL = '/login/'
LOGIN_EXEMPT_URLS = (
r'^about\.html$',
r'^legal/', # allow any URL under /legal/*
)
MIDDLEWARE_CLASSES = (
from django.http import HttpResponseRedirect
from django.conf import settings
from re import compile
EXEMPT_URLS = [compile(settings.LOGIN_URL.lstrip('/'))]
if hasattr(settings, 'LOGIN_EXEMPT_URLS'):
EXEMPT_URLS += [compile(expr) for expr in settings.LOGIN_EXEMPT_URLS]
class LoginRequiredMiddleware:
"""
<script language="javascript" type="text/javascript">
SHARETHIS.addEntry({
// defaults here
{block:PostTitle} title:'{PostTitle}',{/block:PostTitle}
{block:PostSummary} summary:'{PostSummary}',{/block:PostSummary}
icon:'{PortraitURL-30}',
url:'{Permalink}',
// entry type specifics here
<script language="javascript" type="text/javascript">
SHARETHIS.addEntry({
title:'Share me',
summary:'Sharing is good for the soul.',
icon: 'http://path.to/icon'
}, {button:true} );
</script>
@ryanwitt
ryanwitt / gist:305695
Created February 16, 2010 17:18
slides for @kriskowal's vim presentation @fastsoft
^w hjkl move to windows
^w HJKL move windows
^w +- horizontal resize
^w = even splits
^w10<> vertical resize
O
I ia A
@ryanwitt
ryanwitt / samp.py
Created April 14, 2010 16:30
Sample program inspired by the todo in kriskowal/xbin
#!/usr/bin/env python
"""usage: %prog [-n N]
Returns a random uniform sample of the lines on stdin using a technique
called reservoir sampling [VITTER '85]. Preserves input ordering."""
import sys
from optparse import OptionParser
p = OptionParser(usage = __doc__)
p.add_option(
We couldn’t find that file to show.
"""
Classes for a dynamic, templated settings environment.
By "environment" we just mean a dictionary where keys can be accessed as
object attributes. The _AttributeDict class comes from Fabric.
The _RecursiveAttributeDict class takes this idea one step further, and lets
you refer to other keys in the dictionary using new-style python formatting
syntax (PEP 3101). See the class docstring for examples.
"""
function setupValidation(field, timeout) {
var input = $('#id_'+field);
var input_tr = $('#id_tr_'+field);
check = function () {
var t = this;
if (this.value != this.lastValue) {
if (this.timer) clearTimeout(this.timer);
input_tr.removeClass('error');
$('#id_tr_errors_'+field).remove();
this.timer = setTimeout(function () {