Skip to content

Instantly share code, notes, and snippets.


Bruno Renié brutasse

View GitHub Profile
import os
import subprocess
base = [f.rsplit('-', 3)[0] for f in os.listdir('..') if f.endswith('.xz')]
downloaded = {'sh'}
def clean(p):
return p.split('>=')[0].split('=')[0]
sudo apt-get -y install python-virtualenv libxslt1-dev libxml2-dev python-virtualenv-tools
export VERSION=`date +"%Y.%m.%d"`.$BUILD_NUMBER
mkdir -p build/usr/share/python
virtualenv build/usr/share/python/sentry
build/usr/share/python/sentry/bin/pip install -U pip wheel distribute
build/usr/share/python/sentry/bin/pip uninstall -y distribute
build/usr/share/python/sentry/bin/pip install sentry[mysql] dj-database-url hiredis dj-redis-url django-redis-cache
View replication.rst


Sync process is:

  • make a base backup
  • catch up with changes that happened during the base backup using master's WAL files
  • stream

Make sure master's wal_keep_segments is set to a high enough value to allow tracking all changes happening during the base backup. Restart needed when changing this.

View monthdelta
>>> import datetime
>>> from monthdelta import monthdelta
>>>, 1, 31) + monthdelta(1), 2, 29)
>>>, 1, 31) + monthdelta(3), 4, 30)
>>>, 2, 29) + monthdelta(12)
View gmail-purge.js
// The name of the Gmail Labels that are to be purged
// Purge messages automatically after that many days
def find_api_views(urls, views=None):
if views is None:
views = []
for entry in urls:
if hasattr(entry, 'url_patterns'):
view = entry.callback
if (
hasattr(view, 'cls') and
brutasse /
Last active Dec 25, 2015
Setting application environment variables on production servers

A great tool is envdir

apt-get install envdir
mkdir /etc/mysite.d/env
echo "postgres://postgres:@localhost:5432/mysite" > /etc/mysite.d/env/DATABASE_URL
echo "s3ce3t K3Y" > /etc/mysite.d/env/SECRET_KEY
echo "/srv/www/mysite/static" > /etc/mysite.d/env/STATIC_ROOT
echo "mysite.settings" > /etc/mysite.d/env/DJANGO_SETTINGS_MODULE
brutasse /
Created Jul 14, 2013
Clean stale RQ jobs
import datetime
import redis
import pytz
from dateutil import parser
from itertools import product
r = redis.Redis()
last_month = (
datetime.datetime.utcnow().replace(tzinfo=pytz.utc) -
import os
import re
import requests
import feedgenerator
from dateutil.parser import parse
from raven import Client
REPO = 'django/django'
brutasse /
Created Dec 10, 2012
Markdown filter with proper content filtering
from django.template import Library
from django.utils.encoding import force_text
from django.utils.safestring import mark_safe
import bleach
import markdown as markdownlib
register = Library()