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
""" | |
Module contains ``order_dicts`` decorator. When used, all dicts declarations are converted to OrderedDict. Example:: | |
from new_order import order_dicts | |
@order_dicts | |
def func(): | |
d1 = {1: 2, 3: 4, 5: 6} | |
d2 = {"test": 2 ** 42, "foo": "bar", "baz": d1} | |
print("What do we have here? %s" % d1) |
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 resource | |
from cassandra.cluster import Cluster | |
def create_and_shutdown(): | |
cluster = Cluster() | |
session = cluster.connect() | |
session.shutdown() | |
cluster.shutdown() |
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 os import urandom | |
from celery.beat import PersistentScheduler | |
from some_place import create_readis_connection # ! | |
class SingletonScheduler(PersistentScheduler): | |
def __init__(self, *args, **kwargs): | |
super(SingletonScheduler, self).__init__(*args, **kwargs) |
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
""" | |
This module adds Redis Sentinel transport support to Celery. | |
Current version of celery doesn't support Redis sentinel client, which is must have for automatic failover. | |
To use it:: | |
import register_celery_alias | |
register_celery_alias("redis-sentinel") | |
celery = Celery(..., broker="redis-sentinel://...", backend="redis-sentinel://...") |
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 requests | |
class RemoteFile(object): | |
def __init__(self, url, session=None): | |
self._url = url | |
self._session = session or requests.Session() | |
self._need_to_close_session = session is 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 -*- | |
import ast | |
from parsimonious.grammar import Grammar | |
from parsimonious.nodes import NodeVisitor | |
json_syntax = r''' | |
json_file = ws? json ws? | |
json = object / array |
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 -*- | |
# Based on http://www.marsohod.org/index.php/projects/plata1/205-carctrlandr | |
import os | |
import BaseHTTPServer | |
from threading import Thread | |
import urlparse | |
import time | |
import string |
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 file lock implementation that tries to avoid platform specific | |
issues. It is inspired by a whole bunch of different implementations | |
listed below. | |
- https://bitbucket.org/jaraco/yg.lockfile/src/6c448dcbf6e5/yg/lockfile/__init__.py | |
- http://svn.zope.org/zc.lockfile/trunk/src/zc/lockfile/__init__.py?rev=121133&view=markup | |
- http://stackoverflow.com/questions/489861/locking-a-file-in-python | |
- http://www.evanfosmark.com/2009/01/cross-platform-file-locking-support-in-python/ | |
- http://packages.python.org/lockfile/lockfile.html |
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 timeit | |
import sys | |
class A(object): | |
"""Original""" | |
def x(self): | |
return 2 |
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 -*- | |
# http://stackoverflow.com/a/8785689/1052325 | |
class SMTransliterator(object): | |
two_letters = {u'Ch': u'Ч', u'yo': u'ё', u'Yo': u'Ё', u'Ya': u'Я', u'yu': u'ю', | |
u'sh': u'щ', u'ch': u'ч', u'ya': u'я', u'Sh': u'Щ', u'zh': u'ж', u'Yu': u'Ю', } | |
two_letters_set = set([s[0] for s in two_letters]) |