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 import template | |
register = template.Library() | |
token_formats = { | |
template.TOKEN_TEXT: '%s', | |
template.TOKEN_VAR: '%s%%s%s' % (template.VARIABLE_TAG_START, template.VARIABLE_TAG_END), | |
template.TOKEN_BLOCK: '%s%%s%s' % (template.BLOCK_TAG_START, template.BLOCK_TAG_END), | |
template.TOKEN_COMMENT: '%s%%s%s' % (template.COMMENT_TAG_START, template.COMMENT_TAG_END), | |
} |
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 googol(): | |
def palindromes(end): | |
for odd_length in (True, False): | |
left = 0 | |
last_palindrome = 0 | |
while last_palindrome < end: | |
left += 1 | |
left_str = str(left) | |
right_str = left_str[::-1] | |
if odd_length: |
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 googol(): | |
power = 100 | |
count = sum([2*9*10**n for n in range(power/2)]) | |
count_sum = sum([int(digit) for digit in str(count)]) | |
return (count, count_sum) |
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.core import serializers | |
from django.utils import simplejson | |
def add_to_fixture(qs, filename): | |
f = open(filename, 'r') | |
data_python_existing = simplejson.loads(f.read()) | |
f.close() | |
data_json_unformatted = serializers.serialize('json', qs) | |
data_python_new = simplejson.loads(data_json_unformatted) | |
data_python_existing.extend(data_python_new) |
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 import template | |
register = template.Library() | |
class UpdateQuerystringNode(template.Node): | |
def __init__(self, **kwargs): | |
self.kwargs = kwargs | |
def render(self, context): | |
query_dict = context['request'].GET.copy() |
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.core.cache import cache | |
def _incr_decr(key, incr=True, min=None, max=None, initial=None): | |
'''Incr/decr function which handles key creation as needed''' | |
# FIXME: min/max have rampant race conditions which could be fixed using | |
# memcache's "cas" feature, but current pylibmc + libmemcached causes a | |
# segfault when used. | |
initial = initial or min or 0 |
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 __future__ import division | |
import datetime | |
import hashlib | |
import inspect | |
import math | |
import pytz | |
import time | |
import urllib | |
from common.cache import incr, decr |
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 import settings | |
from django.core.exceptions import ImproperlyConfigured | |
from django.db.models import loading | |
from django.db.models.fields.related import RelatedField | |
INDENT = ' ' | |
for app_name in settings.INSTALLED_APPS: | |
print app_name | |
app_label = app_name.split(".")[-1] | |
try: |
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.db import models | |
from django import forms | |
from django.forms.models import modelform_factory | |
class ValidatingModel(models.Model): | |
class Meta: | |
abstract = True | |
def __init__(self, *args, **kwargs): | |
self.model_form_class = modelform_factory(self.__class__) |
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 __future__ import division | |
import os | |
import subprocess | |
try: | |
from cStringIO import StringIO | |
except ImportError: | |
from StringIO import StringIO |
OlderNewer