This file contains hidden or 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
# -*- coding: utf-8 -*- | |
from django.db import models | |
from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned | |
class ShortcutManager(models.Manager): | |
""" | |
Manager to get access to instances of your models with just a few keystrokes. | |
""" |
This file contains hidden or 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 | |
import sys | |
import subprocess | |
def grep(fd, magic, chunk_size=1024, alignement=0): | |
""" | |
Iteratively yield positions of the magic in a file descriptor | |
:param fd: open file descriptor (device or a file) | |
:param magic: substring to find |
This file contains hidden or 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 | |
set -eux | |
db="celery_test" | |
mysql -e "drop database $db; create database $db default charset utf8" | |
./manage.py syncdb --noinput; | |
./manage.py migrate djcelery 0001 | |
# Comment out commands below to test the normal migration flow | |
mysql -e "drop table $db.celery_taskmeta" |
This file contains hidden or 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
# -*- coding: utf-8 -*- | |
from django.test.client import Client as BaseClient | |
from django.core.urlresolvers import reverse | |
class Client(BaseClient): | |
""" | |
I used to be reluctant testing Django views until I wrote this class |
This file contains hidden or 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 with_statement | |
import os | |
import time | |
import fcntl | |
import contextlib | |
@contextlib.contextmanager | |
def file_lock(filename, lock_type, timeout=None): | |
fd = open(filename, 'w') | |
fctnl_lock_type = getattr(fcntl, lock_type, None) |
This file contains hidden or 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 | |
# function `set_var` sets a variable with a possiblity to restore previous | |
# value back with `unset_var` | |
# | |
# Can be used to safely initialize/uninitialize environment in python | |
# virtualenvwrapper and friends | |
# | |
#roman@home:~$ foo=1 | |
#roman@home:~$ set_var foo 2 | |
#roman@home:~$ set_var bar 3 |
This file contains hidden or 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 | |
# -*- coding: utf-8 -*- | |
# requirements: opterator, requests | |
import csv | |
import requests | |
from lxml import html | |
from opterator import opterate | |
def get_tree(): |
This file contains hidden or 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 | |
""" | |
Requirements: | |
android2po | |
opterator | |
Sample: | |
$ python android2po_plurals.py pl |
This file contains hidden or 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 | |
# -*- coding: utf-8 -*- | |
# requirements: requests, lxml | |
import requests | |
from lxml import html | |
def get_tree(): | |
resp = requests.get('http://2013.djangocon.eu/vote/') | |
tree = html.fromstring(resp.text) |
This file contains hidden or 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
# -*- coding: utf-8 -*- | |
# This is how I'd implement this using only bare pytest functionality | |
import pytest | |
from user import add_transaction, delete_transaction, get_user_balance | |
# Attempt 1. | |
# According to the documentation at http://pytest.org/latest/fixture.html | |
# try to start with a simple fixture |