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
stmt = """ | |
environ = { | |
'HTTP_X_REQUESTED_WITH': 'XMLHttpRequest' | |
} | |
if 'HTTP_X_REQUESTED_WITH' in environ: | |
result = environ['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest' | |
""" | |
timeit.timeit(stmt=stmt, number=10000000) | |
# yields 2.7133121490478516 |
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 MyForm(Form): | |
def __init__(self, request, *args, **kwargs): | |
user = request.user | |
super(MyForm, self).__init__(*args, **kwargs) | |
def my_fake_validator(value): | |
return my_real_validator(value, user) | |
# can't remember if this is the right syntax | |
self.fields['myfield'].validators.append(my_fake_validator) |
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
def function(**kwargs): | |
Thing.objects.create(**kwargs) | |
Thing2.objects.get_or_create(**kwargs) | |
# desired usage: | |
transaction.let_the_objects_buildup() | |
try: | |
function(a=1, b=2, c=3) | |
finally: |
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.conf.urls import patterns, include, url | |
from uuidfield import UUIDField | |
# Fix the bloody UUID field so that we can do prefetching. | |
UUIDField._old_to_python = UUIDField.to_python | |
def maybe_fix_to_python(self, value): | |
return unicode(UUIDField._old_to_python(self, value=value)) | |
UUIDField.to_python = maybe_fix_to_python |
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($, window, document, undefined) { | |
var totop; | |
var show_at; | |
var already_shown; | |
var didscroll; | |
var update_didscroll; | |
var maybe_should_display; | |
var move; | |
/* |
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
itin_ids = EventItinerary.objects.all().values_list('itinerary', flat=True) | |
places = Schedule.objects.filter(itinerary__in=itin_ids).distinct().values_list('place', flat=True) | |
destins = Place.objects.filter(pk__in=places) |
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 DoItLazy(object): | |
def __iter__(self): | |
from django.contrib import admin | |
admin.autodiscover() | |
yield url(r'^admin/', include(admin.site.urls)) | |
def __reversed__(self): | |
return reversed(tuple(iter(self))) | |
def __radd__(self, other): |
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
[global] | |
timeout = 15 | |
download_cache = /home/whatever/pipcache | |
use-wheel = true | |
wheel-dir = /home/whatever/pipwheels | |
find-links = /home/whatever/pipwheels |
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.contrib.auth.admin import UserAdmin | |
from django.contrib.auth.models import User | |
from django.contrib.auth import login, get_backends | |
from django.core.exceptions import PermissionDenied | |
from django.http import HttpResponseRedirect | |
from django.contrib import messages | |
from django.core.urlresolvers import reverse | |
from django.conf import settings | |
from django.contrib import admin | |
from django.contrib.admin.sites import NotRegistered |
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 MySharedObject(object): | |
""" | |
If using a locally scoped dictionary to check for duplicates, | |
do the same thread issues arise? | |
Note that I don't care about what gets stored -- it should be | |
the same end-result regardless of which threads do what, the | |
ValueError is mainly a developer-awareness issue. | |
""" | |
def do_stuff(self): |
OlderNewer