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
data = [{1:1, 2:2, 3:3}, {1:2, 4:4, 5:5}, {6:6, 7:7, 4:0}] | |
reduce(lambda x, y: dict(x, **y), data, {}) |
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 logging, time | |
from timer import timed | |
logger = logging.getLogger() | |
logger.setLevel(logging.DEBUG) | |
handler = logging.StreamHandler() | |
handler.setLevel(logging.DEBUG) | |
logger.addHandler(handler) |
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 | |
""" | |
run `profile-stats -h` for help | |
example usage: | |
view all calls, ordered by internal time, call count (default): $ profiler-stats /path/to/log | |
view top 25 calls, ordered by internal time, call count: $ profiler-stats -n 25 /path/to/log | |
view top 50 calls, ordered by cumulative time: $ profiler-stats -s cumu -n 50 /path/to/log | |
view all calls with callers: $ profiler-stats -c /path/to/log |
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 view_class_decorator(decorator): | |
""" | |
Wraps a class based view dispatcher with the provided decorator. | |
Usage: | |
@view_class_decorator(login_required) |
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
var portrange = 45032 | |
function getPort (cb) { | |
var port = portrange | |
portrange += 1 | |
var server = net.createServer() | |
server.listen(port, function (err) { | |
server.once('close', function () { | |
cb(port) |
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 django.core.management.commands.flush | |
from django.conf import settings | |
from django.core.cache import get_cache | |
from django.db.backends.creation import TEST_DATABASE_PREFIX | |
from django.db.models.signals import post_syncdb | |
from redis import Redis | |
def is_test_database(database): |
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() | |
@register.tag(name='as') | |
def as_variable(parser, token): | |
""" | |
Adds the rendered content of this block to the context, using the argument | |
as the key name. |
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 copy import copy | |
from urllib import urlencode | |
from urlparse import parse_qs, urlparse, urlunparse | |
from django import template | |
register = template.Library() | |
@register.filter | |
def with_querystring(value, request): |
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() | |
@register.filter | |
def get(value, key): | |
""" | |
Returns the item of the `value` dictionary at `key`. | |
Usage: {{ somedict|get:somevar }} |
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 view_class_decorator(decorator): | |
""" | |
Wraps a class based view dispatcher with the provided decorator. | |
Usage: | |
@view_class_decorator(login_required) |