Skip to content

Instantly share code, notes, and snippets.

@jacobian
jacobian / virtualenv-example.rb
Created October 5, 2010 21:36
My first Chef definition: create a virtualenv. Be nice.
# An example of the below
virtualenv "/home/dvcsmirrors/hg" do
owner "root"
group "dvcsmirrors"
mode 0775
packages "Mercurial" => "1.6.3",
"hgsubversion" => "1.1.2"
end
cd /home/dvcsmirrors/hg/django && /home/dvcsmirrors/hg/bin/hg pull -q subversion && /home/dvcsmirrors/hg/bin/hg push -q bitbucket
with run_in_parallel():
run('...')
run('...')
local('...')
import datetime
import mechanize
from xml.etree import cElementTree
USERNAME = '...'
PASSWORD = '...'
NUMBER = '2025551212'
br = mechanize.Browser()
br.open('https://ebillpay.verizonwireless.com/vzw/accountholder/overview/AccountOverview.action')
"""
This is a test settings file suitable for running Django's under a build slave.
Out of the box it's configured to run tests against SQLite, but there are
examples below, commented out, to run tests against MySQL and PostgreSQL.
The important parts:
* You must have two databases: "default" and "other".
* For all databases except SQLite, the "default" database must exist and you
must be able to connect to it given the creds in the settings.
@jacobian
jacobian / check_postgres_replication.py
Created December 16, 2010 20:13
Nagios plugin to check PostgreSQL 9 streaming replication lag.
#!/usr/bin/env python
"""
Nagios plugin to check PostgreSQL 9 streaming replication lag.
Requires psycopg2 and nagiosplugin (both installable with pip/easy_install).
MIT licensed:
Copyright (c) 2010 Jacob Kaplan-Moss. All rights reserved.
from django import template
from django.template import defaulttags
from django.utils.safestring import mark_for_escaping
register = template.Library()
class EscapedNode(template.Node):
def __init__(self, node):
self.node = node
@jacobian
jacobian / elem2dict.py
Created January 25, 2011 20:22
Convert an lxml.etree node tree into a dict.
def elem2dict(node):
"""
Convert an lxml.etree node tree into a dict.
"""
d = {}
for e in node.iterchildren():
key = e.tag.split('}')[1] if '}' in e.tag else e.tag
value = e.text if e.text else elem2dict(e)
d[key] = value
return d
@jacobian
jacobian / replication_fabfile.py
Created January 27, 2011 18:05
A fab task to start pg9 hot standby.
def start_replication():
"""
Begin Postgresql standby
"""
# Stop pg on the slave machine.
with settings(host_string=env.db_slave):
run('service postgresql-9.0 stop')
# Create the backup on the master machine
with settings(host_string=env.db_master):
### Basic daemon config
ServerRoot "/etc/apache2"
PidFile ${APACHE_PID_FILE}
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}
ServerTokens ProductOnly
ServerAdmin [email protected]
### Listen on localhost:8000 (behind the proxy)