Skip to content

Instantly share code, notes, and snippets.

Avatar

Bruno Renié brutasse

View GitHub Profile
View find-deps.py
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]
View package-sentry.sh
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

Replication

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
>>> datetime.date(2012, 1, 31) + monthdelta(1)
datetime.date(2012, 2, 29)
>>> datetime.date(2012, 1, 31) + monthdelta(3)
datetime.date(2012, 4, 30)
>>> datetime.date(2012, 2, 29) + monthdelta(12)
View gmail-purge.js
// The name of the Gmail Labels that are to be purged
var GMAIL_LABELS = [
"list",
"of",
"labels",
"to",
"purge",
];
// Purge messages automatically after that many days
View override_drf_settings.py
def find_api_views(urls, views=None):
if views is None:
views = []
for entry in urls:
if hasattr(entry, 'url_patterns'):
views.extend(find_api_views(entry.url_patterns))
else:
view = entry.callback
if (
hasattr(view, 'cls') and
@brutasse
brutasse / env.md
Last active Dec 25, 2015
Setting application environment variables on production servers
View env.md

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
brutasse / clean-redis.py
Created Jul 14, 2013
Clean stale RQ jobs
View clean-redis.py
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) -
View commits.py
import os
import re
import requests
import feedgenerator
from dateutil.parser import parse
from raven import Client
REPO = 'django/django'
@brutasse
brutasse / markup.py
Created Dec 10, 2012
Markdown filter with proper content filtering
View markup.py
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()
You can’t perform that action at this time.