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 | |
# -*- coding: utf-8 -*- | |
# requirements: opterator, requests | |
import csv | |
import requests | |
from lxml import html | |
from opterator import opterate | |
def get_tree(): |
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 | |
# 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 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 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 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 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 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 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
diff --git a/djcelery/migrations/0002_v25_changes.py b/djcelery/migrations/0002_v25_changes.py | |
index f3bb729..7013f7f 100644 | |
--- a/djcelery/migrations/0002_v25_changes.py | |
+++ b/djcelery/migrations/0002_v25_changes.py | |
@@ -11,6 +11,10 @@ def ignore_exists(fun, *args, **kwargs): | |
fun(*args, **kwargs) | |
except DatabaseError, exc: | |
if "exists" in str(exc): | |
+ # don't panic, everything is okay, it's just a hack | |
+ if db.has_ddl_transactions: |
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
# -*- coding: utf-8 -*- | |
""" | |
Why calculator doesn't work and how to fix it? | |
I expect to see: | |
$ python /tmp/discount_calculator.py | |
950.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/env python | |
# -*- coding: utf-8 -*- | |
import httplib2 | |
import urllib | |
import json | |
def request(address, email=None, limit=None): | |
""" | |
Simple wrapper around nominatim geocoding web service |