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
# A granular permissions' backend for Django | |
try: | |
set | |
except NameError: | |
from sets import Set as set # Python 2.3 fallback | |
from django.contrib.auth.backends import ModelBackend | |
class PermissionsBackend(ModelBackend): |
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
""" | |
Delete your old tweets (by old I mean all except latest 100) | |
without removing favorites of your own tweets and DM. | |
1/ Install python-twitter: http://code.google.com/p/python-twitter/ as ptwitter | |
2/ Patch it with http://code.google.com/p/python-twitter/issues/detail?id=60 | |
3/ Populates USERNAME and PASSWORD | |
Note that you're limited to 150 calls to the API per hour and that you can't | |
retrieve more than the 3200 latest tweets, it means that even if you relaunch |
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
""" | |
Current Page Middleware. | |
This module provides a middleware that implements a mechanism to | |
highlight a link pointing to the current URL. | |
Thanks @davidbgk and @samueladam for improvements & optimizations | |
""" | |
import re |
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
# classinstancemethod, when you want to use both a classmethod and the function with a class instance | |
## Descriptors | |
## Anything with __get__ and optionally __set__: | |
class classinstancemethod(object): | |
def __init__(self, func): | |
self.func = func | |
def __get__(self, obj, type=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
from django.db.models import signals | |
from django.contrib.auth import models as auth_app | |
from django.contrib.auth.management import create_permissions, create_superuser | |
from django.contrib.contenttypes.management import update_contenttypes | |
signals.post_syncdb.disconnect(update_contenttypes) | |
signals.post_syncdb.disconnect(create_permissions, | |
dispatch_uid = "django.contrib.auth.management.create_permissions") | |
signals.post_syncdb.disconnect(create_superuser , | |
sender=auth_app, dispatch_uid = "django.contrib.auth.management.create_superuser") |
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 forms | |
class EmptyChoiceField(forms.ChoiceField): | |
def __init__(self, choices=(), empty_label=None, required=True, widget=None, label=None, | |
initial=None, help_text=None, *args, **kwargs): | |
# prepend an empty label if it exists (and field is not required!) | |
if not required and empty_label is not None: | |
choices = tuple([(u'', empty_label)] + list(choices)) |
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 re | |
# http://atomboy.isa-geek.com/plone/Members/acoil/programing/double-metaphone | |
from metaphone import dm as double_metaphone | |
# get the Redis connection | |
from jellybean.core import redis | |
import models | |
# Words which should not be indexed |
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 | |
#coding= utf-8 | |
# This script implements the Double Metaphone algorithm (c) 1998, 1999 by Lawrence Philips | |
# it was translated to Python from the C source written by Kevin Atkinson (http://aspell.net/metaphone/) | |
# By Andrew Collins - January 12, 2007 who claims no rights to this work | |
# http://www.atomodo.com/code/double-metaphone | |
# Tested with Pyhon 2.4.3 | |
# Updated Feb 14, 2007 - Found a typo in the 'gh' section | |
# Updated Dec 17, 2007 - Bugs fixed in 'S', 'Z', and 'J' sections. Thanks Chris Leong! | |
# Updated June 25, 2010 - several bugs fixed thanks to Nils Johnsson for a spectacular |
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 | |
"""Command line script to convert a file, usually an image, into a data URI | |
for use on the web.""" | |
import base64 | |
import mimetypes | |
import os | |
import sys | |
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 cgi import parse_qs | |
from wsgiref.simple_server import make_server | |
def simple_app(environ, start_response): | |
status = '200 OK' | |
headers = [('Content-Type', 'text/plain')] | |
start_response(status, headers) | |
if environ['REQUEST_METHOD'] == 'POST': | |
request_body_size = int(environ.get('CONTENT_LENGTH', 0)) | |
request_body = environ['wsgi.input'].read(request_body_size) |
OlderNewer