This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@login_required # This is the decorator! One line... simple. | |
def my_view(request): | |
# Do something here to turn the request into an HTML page. | |
# ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# settings.py | |
LOGIN_URL = '/login/' | |
LOGIN_EXEMPT_URLS = ( | |
r'^about\.html$', | |
r'^legal/', # allow any URL under /legal/* | |
) | |
MIDDLEWARE_CLASSES = ( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
^w hjkl move to windows | |
^w HJKL move windows | |
^w +- horizontal resize | |
^w = even splits | |
^w10<> vertical resize | |
O | |
I ia A |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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. | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 () { |
OlderNewer