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
mo = fudge.Fake().expects_call() | |
mf = mo.returns_fake() | |
mf.expects_call('read').returns('test') | |
setattr(fudge.Fake, '__enter__', fudge.Fake().is_callable().returns(mf)) | |
setattr(fudge.Fake, '__exit__', fudge.Fake().is_callable()) | |
# https://github.com/jsatt/mock/blob/master/mock.py#L1867 |
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.paginator import Paginator, InvalidPage, EmptyPage | |
def paginate(request, object_list, limit=10, page_range=10, object_pk=None): | |
paginator = Paginator(object_list, limit) | |
page = None | |
if object_pk: | |
if hasattr(object_list, 'values_list') and callable( | |
object_list.values_list): | |
object_list = list(object_list.values_list('pk', flat=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
SELECT * FROM [table name] LIMIT [row id], 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
date = now().replace(hour=0, minute=0, second=0, microsecond=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
import random | |
import string | |
rand_string = ''.join(random.choice(string.ascii_letters + string.digits) | |
for i in xrange(random.randint(6, 20))) |
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 redis import Redis | |
r = Redis('host', db=1, password='pass') | |
r.keys(':1:cachekey*') |
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 setup.py sdist bdist_egg upload |
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
# stdout to file | |
echo test > file.txt | |
# stdout append to file | |
echo test >> file.txt | |
# stderr to file | |
cmd 2> file.txt | |
# stderr to stdout |
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
#!/bin/bash | |
TASK=$1 | |
node_checksum() { | |
if [ "$1" = "$2" ]; then | |
return | |
elif [ -z $2 ]; then | |
echo 'Checksums empty' #missing in raspberry pi binary | |
return |
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.query import QuerySet | |
class QuerySetFromIter(QuerySet): | |
def __init__(self, objects=[], model=None, query=None, *args, **kwargs): | |
if model is None: | |
if len(objects): | |
model = type(objects[0]) | |
else: | |
# TODO: find a better way to handle this |