Skip to content

Instantly share code, notes, and snippets.

View chrislawlor's full-sized avatar

Chris Lawlor chrislawlor

View GitHub Profile
@chrislawlor
chrislawlor / fabfile.py
Created November 9, 2011 21:28 — forked from onyxfish/fabfile.py
Chicago Tribune News Applications fabric deployment script
from fabric.api import *
"""
Base configuration
"""
env.project_name = '$(project)'
env.database_password = '$(db_password)'
env.site_media_prefix = "site_media"
env.admin_media_prefix = "admin_media"
env.newsapps_media_prefix = "na_media"
@chrislawlor
chrislawlor / settings_local.py
Last active September 28, 2015 12:48
Starter for django dev local settings file
import sys
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'dev.sqlite',
'USER': '',
'PASSWORD': '',
'HOST': 'localhost',
'PORT': '',
@chrislawlor
chrislawlor / fabfile.py
Created May 30, 2012 13:02
Fabric task to install libxml and libxslt from source.
def install_libxml(tag='v2.8.0'):
run('git clone git://git.gnome.org/libxml2')
with('cd libxml'):
run('git reset %s' % tag)
run('./autogen.sh')
run('make')
sudo('make install')
run('rm -rf libxml')
def install_libxslt(tag='v1.1.26'):
@chrislawlor
chrislawlor / installs.py
Created June 27, 2012 14:44
Fabric scripts for installing commonly used web app infrastructure on Ubuntu-flavored OS's
# Import these into your fabfile.py as to not clutter it up.
import re
import textwrap
from fabric.api import *
from fabric.operations import prompt, require
from fabric.context_managers import settings, prefix
from fabric.contrib.console import confirm
from fabric.contrib.files import upload_template, exists, append
from fabric.utils import warn
@chrislawlor
chrislawlor / Date.toDjangoString()
Created December 19, 2012 01:18
No more looking this up every time I need to post Date / Time data to a Django-powered API
Date.prototype.toDjangoString = function() {
// YYYY-MM-DD HH:MM:SS
return this.getFullYear() + '-' +
(this.getMonth() + 1) + "-" +
this.getDate() + " " +
this.getHours() + ":" +
this.getMinutes() + ":" +
this.getSeconds();
};
@chrislawlor
chrislawlor / gist:4336645
Created December 19, 2012 13:27
Convert Google Maps LatLng to WKT (http://en.wikipedia.org/wiki/Well-known_text)
google.maps.LatLng.prototype.toPointWKT = function() {
return "POINT("+ this.Za + " " + this.Ya + ")";
};
@chrislawlor
chrislawlor / models.py
Created March 13, 2013 13:57
Chainable Model Manager boilerplate
import datetime
from django.db import models
from django.db.models.query import QuerySet
class PostQuerySet(QuerySet):
def live(self):
"""Filter out posts that aren't ready to be published"""
now = datetime.datetime.now()
return self.filter(date_published__lte=now, status="published")
@chrislawlor
chrislawlor / bootstrap.sh
Created April 17, 2013 16:24
Install some development tools and libraries on newer Linuxes
#!/bin/bash
# add repositories
# get latest mercurial
sudo apt-add-repository ppa:mercurial-ppa/releases
# Virtualbox
wget -q http://download.virtualbox.org/virtualbox/debian/oracle_vbox.asc -O- | sudo apt-key add -
@chrislawlor
chrislawlor / gist:7116554
Created October 23, 2013 10:57
Get database password from ~/.my.cnf file, if it exists. Useful when developing on CloudSQL + AppEngine, which gleefully ignores environment variables.
# Get password from ~/.my.cnf if it exists
my_cnf_path = os.path.expanduser('~/.my.cnf')
if os.path.exists(my_cnf_path):
from ConfigParser import SafeConfigParser
config = SafeConfigParser()
with open(my_cnf_path) as my_cnf:
config.readfp(my_cnf)
try:
DATABASES['default']['PASSWORD'] = config.get('client', 'password')
except ConfigParser.NoOptionError:
@chrislawlor
chrislawlor / gist:8474185
Last active January 3, 2016 14:09
Bash prompt - add Git branch and 'dirty' status, e.g. user@localhost:~/code/project on develop⚡ Add to your ~/.bashrc (linux) or ~/.bash_profile (OSX)
# Custom prompt
function parse_git_dirty {
git branch > /dev/null 2>&1
if [[ $(echo $?) == "0" ]]
then [[ $(git status 2> /dev/null | tail -n1) != "nothing to commit, working directory clean" ]] && echo "⚡"
fi
}
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/on \1/"
}