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 Image | |
import cStringIO | |
from django.core.files.base import ContentFile | |
from django.db.models import ImageField | |
from django.db.models.fields.files import ImageFieldFile | |
class JPEGImageFieldFile(ImageFieldFile): | |
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 print_function | |
import StringIO | |
import gzip | |
from boto.s3.connection import S3Connection | |
conn = S3Connection("<key_id>", "<secret>") | |
bucket = conn.get_bucket('<bucket>') | |
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
echo '{ | |
"spell_check": true, | |
"dictionary": "Packages/Language - English/en_US.dic" | |
}' > ~/Library/Application\ Support/Sublime\ Text\ 2/Packages/User/Markdown.sublime-settings |
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 libthumbor import CryptoURL | |
def thumb(url, **kwargs): | |
''' | |
returns a thumbor url for 'url' with **kwargs as thumbor options. | |
Positional arguments: | |
url -- the location of the original image |
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 | |
def find_underscores(patterns): | |
for pattern in patterns: | |
raw = pattern.regex.pattern | |
rr = re.sub('\(.*?\)', lambda x: '', raw) | |
if '_' in rr: | |
print pattern.regex.pattern | |
if hasattr(pattern, 'url_patterns'): | |
find_underscores(pattern.url_patterns) |
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 requests | |
import pyquery | |
import re | |
import sys | |
import urllib | |
SEARCH_URL = 'http://ajax.googleapis.com/ajax/services/search/web' | |
def unquote_all(url): |
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 | |
used_queues = set() | |
for route, q_dict in settings.CELERY_ROUTES.items(): | |
module, task = route.rsplit('.', 1) | |
mod = __import__(module, globals(), locals(), [task]) | |
try: | |
t = getattr(mod, task) | |
except AttributeError: |
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 kill_queries(query='', db_alias='default'): | |
from django.db import connections | |
import re | |
connection = connections[db_alias] | |
cursor = connection.cursor() | |
cursor.execute("SHOW PROCESSLIST") | |
for row in cursor.fetchall(): | |
current = row[-1] | |
if current and re.search(query, current): |
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 open_module() { | |
mate `python -c "import $1 as mod; print (mod.__file__[:-12] if '__init__' in mod.__file__ else mod.__file__[:-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
def get_exception_side_effect(num_of_exceptions, exception_class=Exception): | |
def side_effect(*args, **kwargs): | |
side_effect.calls += 1 | |
if side_effect.calls > num_of_exceptions: | |
return Mock() | |
else: | |
raise exception_class | |
side_effect.calls = 0 | |
return side_effect |
NewerOlder