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
# decorators to leverage cache based on conditional view processing. | |
# cache_condition decorator based on django.views.decorators.http.condition | |
# cache_last_modified, cache_etag shortcuts. | |
# settings.py | |
# ----------- | |
# you may or may not want this. | |
# CACHE_MIDDLEWARE_ANONYMOUS_ONLY = True |
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 hook (sys.meta_path) for mocking imports | |
# using mock library (http://www.voidspace.org.uk/python/mock/) | |
# | |
import sys | |
import mock | |
import logging | |
IMPORTER = None | |
MOCK = None |
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 | |
# find duplicate files based on their md5sum | |
import os | |
import hashlib | |
import mmap | |
def chunks(file_): | |
try: | |
map = mmap.mmap(file_.fileno(), 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
#!/usr/bin/python | |
# merge LCOV file counters | |
import sys | |
filedict = {} | |
currentitem = {} | |
currentfile = '' | |
for line in sys.stdin: | |
subline = line[3:][:-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
# python startup file to toggle autocomplete on. | |
# e.g. export PYTHONSTARTUPFILE=pythonstartup.py | |
# | |
import readline | |
import rlcompleter | |
readline.parse_and_bind('tab: complete') |
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
# | |
# discover all url patterns in django project | |
# | |
def discover_urls(urllist, parent): | |
for entry in urllist: | |
item = parent.setdefault(entry.regex.pattern, {}) | |
if hasattr(entry, 'url_patterns'): | |
discover_urls(entry.url_patterns, item) |
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
# set/get process name (using ctypes & prctl) | |
# set_proc_name('python rocks') | |
# name = get_proc_name() | |
import ctypes | |
from ctypes.util import find_library | |
libc = ctypes.CDLL(find_library('c')) | |
PR_SET_NAME = 15 | |
PR_GET_NAME = 16 |
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
# django admin @register class decorator, e.g. | |
# @register(Entry) | |
# class EntryAdmin(models.ModelAdmin): | |
# pass | |
def register(model): | |
def inner(admin_cls): | |
admin.site.register(model, admin_cls) | |
return admin_cls | |
return inner |
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
# Mixin for checkin admin interface. | |
# To be used in a django testcase (using test client). | |
# e.g. | |
# from django.test import TestCase | |
# class EntryTest(AdminTestMixin, TestCase): | |
# pass | |
class AdminTestMixin(object): | |
def test_model_admin(self): |
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
# apache2 config tuning for linux (8MB default stack size) | |
# allows to run more threads, min stack size should depend on worse case scenario | |
# | |
#MaxClients 1000 | |
#ThreadsPerChild 64 | |
#MinSpareThreads 500 | |
# default linux 8MB | |
#ThreadStackSize 8388608 | |
#ThreadStackSize 4194304 |
OlderNewer