Skip to content

Instantly share code, notes, and snippets.

View prestontimmons's full-sized avatar

Preston Timmons prestontimmons

View GitHub Profile
@prestontimmons
prestontimmons / gist:1198079
Created September 6, 2011 16:34
slugify model on save
from django.template.defaultfilters import slugify as django_slugify
class MyModel(models.Model):
def save(*args, **kwargs):
# Build our slug from the name, keeping it short for
# linkability, but still guarantee uniqueness
if not self.pk and self.slug:
self.slug = self.slugify(self.slug)
@prestontimmons
prestontimmons / gist:1207189
Created September 9, 2011 20:08
Install ssh-copy-id on mac
sudo curl "http://phildawson.co.uk/ssh-copy-id" -o /usr/bin/ssh-copy-id
sudo chmod +x /usr/bin/ssh-copy-id
@prestontimmons
prestontimmons / testcase.py
Created October 24, 2011 22:19
Lazy man's Django testcase
"""
Decrease the verbosity of writing view tests.
Old way:
self.client.get(reverse("my-view"))
self.client.post(reverse("my-view"), data={"key": "value"})
self.client.login("username", "password")
self.client.get(reverse("my-other-view"))
self.client.logout()
@prestontimmons
prestontimmons / gist:1359117
Created November 11, 2011 20:19
Install Fabric on Mac
# http://distributedaweso.me/past/2011/5/4/pip_workaround_for_no_ppc_support_in_xcode4/
ARCHFLAGS="-arch i386 -arch x86_64" pip install fabric
@prestontimmons
prestontimmons / gist:1359849
Created November 12, 2011 01:18
uwsgi init script
#! /bin/bash
# /etc/init.d/uwsgi
#
daemon=/path/to/uwsgi
pid=/path/to/uwsgi.pid
args="-x /path/to/uwsgi.xml"
# Carry out specific functions when asked to by the system
case "$1" in
@prestontimmons
prestontimmons / gist:1377605
Created November 18, 2011 20:10
Trustcommerce TCLink Python package
pip install https://vnvault.trustcommerce.com/downloads/tclink-3.4.4-python.tar.gz
Docs:
https://vnvault.trustcommerce.com/downloads/TC_Developers_Guide_v4.0.pdf
@prestontimmons
prestontimmons / gist:1483097
Created December 15, 2011 21:58
Makefile for generating ssl certs
UTF8 := $(shell locale -c LC_CTYPE -k | grep -q charmap.*UTF-8 && echo -utf8)
SERIAL=0
.PHONY: usage
.SUFFIXES: .key .csr .crt .pem
.PRECIOUS: %.key %.csr %.crt %.pem
usage:
@echo "This makefile allows you to create:"
@echo " o public/private key pairs"
@prestontimmons
prestontimmons / gist:1627767
Created January 17, 2012 17:40
Change permissions on directories
find /my/directory/ -type d -exec chmod 755 {} \;
@prestontimmons
prestontimmons / gist:1711148
Created January 31, 2012 15:43
Django json_view decorator
from functools import wraps
from json import dumps
from django.http import HttpResponse
def json_view(view_func):
@wraps(view_func)
def inner(request, *args, **kwargs):
response = view_func(request, *args, **kwargs)
if request.GET.get("format") == "json" and hasattr(response, "context_data"):
@prestontimmons
prestontimmons / grid.py
Created February 9, 2012 18:16
generate css grid in Python
""" Usage: python grid.py > grid.css """
MAX = 960
COL = 10
rules = []
rules.append(".column { float: left; min-height: 1px; }")
for x in range(COL, MAX + COL, COL):
rules.append(".column-%s { width: %spx; }" % (x, x))