- GitHub Staff
- https://www.peterbe.com
- @peterbe
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
import ldap | |
from django.conf import settings | |
from django.core.cache import cache | |
from django_auth_ldap.config import LDAPSearch | |
def fetch_user_details(email, force_refresh=False): | |
cache_key = 'ldap_user_details_%s' % hash(email) | |
if not force_refresh: | |
results = cache.get(cache_key) |
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
class EmailInput(forms.widgets.Input): | |
input_type = 'email' | |
def render(self, name, value, attrs=None): | |
if attrs is None: | |
attrs = {} | |
attrs.update(dict(autocorrect='off', | |
autocapitalize='off', | |
spellcheck='false')) | |
return super(EmailInput, self).render(name, value, attrs=attrs) |
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/python | |
import sys | |
import logging | |
import psycopg2 | |
logger = logging.getLogger("duplicates") | |
logger.addHandler(logging.StreamHandler(sys.stderr)) | |
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 bson.code import Code | |
map_ = Code(""" | |
function() { | |
if (this.right) | |
emit('right', {total:this.time, count:1}); | |
if (!this.right && this.answer) | |
emit('wrong', {total:this.time, count:1}); | |
} | |
""") |
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 | |
""" | |
Makes sure all docs/*.rst files are properly right-stripped of whitespace | |
By: peterbe | |
""" | |
import os | |
from glob import glob | |
DIR = os.path.normpath(os.path.join(os.path.dirname(__file__), '..', 'docs')) |
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 .base import * | |
try: | |
from .local import * | |
except ImportError, exc: | |
exc.args = tuple(['%s (did you rename settings/local.py-dist?)' % exc.args[0]]) | |
raise exc | |
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
class UpdateTwitterHandler(tornado.web.RequestHandler, tornado.auth.TwitterMixin): | |
@tornado.web.asynchronous | |
@tornado.gen.engine | |
def post(self): | |
access_token = self.get_current_user_access_token() | |
result = yield tornado.gen.Task(self.twitter_request, | |
"/account/update_profile_background_image", | |
image=open('new_image.png', 'rb').read(), | |
access_token=access_token) |
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.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 |
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
$(document).ready(function() { | |
$('#new-status').submit(function(e) { | |
e.preventDefault(); | |
$.post('/status', { text: $(this).find('textarea').val() }, | |
function(data) { | |
$('#statuses').append('<li>' + data.text + '</li>'); | |
$(this).find('textarea').val(''); | |
}); | |
}); |
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
@route(r'/thumbnails/(?P<image>\w{1}/\w{2}/\w{6})/(?P<width>\w{1,3})' | |
r'.(?P<extension>png|jpg)', | |
name='thumbail') | |
class TileHandler(BaseHandler): | |
@tornado.web.asynchronous | |
@tornado.gen.engine | |
def get(self, image, width, extension): | |
width = int(width) |