Skip to content

Instantly share code, notes, and snippets.

View tbarbugli's full-sized avatar

Tommaso Barbugli tbarbugli

View GitHub Profile
@tbarbugli
tbarbugli / factory.py
Created April 2, 2012 14:26
OneToOneModelFactory
from django.db import models
from django.utils.importlib import import_module
class OneToOneModelFactory(object):
"""
creates related models :cls
which are subclasses of :subclass named :subclasses
convenient to define a bunch of related models programmatically
(eg. localize table columns in separate tables)
@tbarbugli
tbarbugli / example model
Created April 26, 2012 20:36
example model
class Item(models.Model):
... a bunch of very interesting fields ...
popularity = models.IntegerField()
@tbarbugli
tbarbugli / s3botostorage.py
Created July 25, 2012 21:51
S3BotoStorage
from boto.utils import parse_ts
from django.core.files.storage import get_storage_class
from storages.backends.s3boto import S3BotoStorage
"""
make sure you have this setting
AWS_PRELOAD_METADATA = True
and that you have python-dateutils==1.5 installed
"""
@tbarbugli
tbarbugli / gist:3832650
Created October 4, 2012 09:56
ghettorouter
class GhettoRouter(object):
def route_for_task(self, task, args=None, kwargs=None):
return {'queue': 'celery',
'exchange': 'celery',
'exchange_type': 'direct',
'routing_key': 'celery'}
CELERY_ROUTES = (GhettoRouter(), )
@tbarbugli
tbarbugli / gist:3833911
Created October 4, 2012 14:34
celery_err
Traceback (most recent call last):
File "/srv/fashiolista/lib/python2.7/site-packages/raven/utils/serializer/manager.py", line 68, in transform
File "/srv/fashiolista/lib/python2.7/site-packages/kombu/connection.py", line 582, in __repr__
File "/srv/fashiolista/lib/python2.7/site-packages/kombu/connection.py", line 446, in as_uri
File "/srv/fashiolista/lib/python2.7/site-packages/kombu/connection.py", line 435, in info
File "/srv/fashiolista/lib/python2.7/site-packages/kombu/connection.py", line 414, in _info
File "/srv/fashiolista/lib/python2.7/site-packages/kombu/connection.py", line 637, in transport
File "/srv/fashiolista/lib/python2.7/site-packages/kombu/connection.py", line 395, in create_transport
File "/srv/fashiolista/lib/python2.7/site-packages/kombu/transport/redis.py", line 622, in __init__
self.cycle = MultiChannelPoller()
[2012-10-12 15:07:35,033: WARNING/MainProcess] builtin_function_or_method 1018 +30
[2012-10-12 15:07:35,034: WARNING/MainProcess] dict 1924 +21
[2012-10-12 15:07:35,034: WARNING/MainProcess] tuple 1415 +9
import objgraph
socks_refs = objgraph.by_type('Connection')
objgraph.show_backrefs(socks_refs, filename='sample-%r.png' % now, max_depth=10)
import objgraph
socks_refs = objgraph.by_type('Connection')
objgraph.show_backrefs(socks_refs, filename='sample-%r.png' % now, max_depth=10)
@tbarbugli
tbarbugli / redis_unique_ts.py
Created January 10, 2013 16:28
create a unique timestamp (with a namespace)
import time
def get_unique_timestamp(redis_connection, uniqueness_namespace):
while True:
t = time.time()
key = namespace % t
if redis_connection.setnx(key):
return key
time.sleep(0.1)
@tbarbugli
tbarbugli / gist:4754677
Created February 11, 2013 14:24
tail celery logs
Traceback (most recent call last):
File "/srv/fashiolista/lib/python2.7/site-packages/celery/worker/__init__.py", line 351, in start
component.start()
File "/srv/fashiolista/lib/python2.7/site-packages/celery/worker/consumer.py", line 393, in start
self.consume_messages()
File "/srv/fashiolista/lib/python2.7/site-packages/celery/worker/consumer.py", line 483, in consume_messages
handlermap[fileno](fileno, event)
File "/srv/fashiolista/lib/python2.7/site-packages/billiard/pool.py", line 1047, in maintain_pool
self._maintain_pool()
File "/srv/fashiolista/lib/python2.7/site-packages/billiard/pool.py", line 1042, in _maintain_pool