Skip to content

Instantly share code, notes, and snippets.

View prestontimmons's full-sized avatar

Preston Timmons prestontimmons

View GitHub Profile
@prestontimmons
prestontimmons / gist:2423821
Created April 19, 2012 20:07
Replaced {{ STATIC_URL }} with {% static %} using sed
$ find -name "*.html" | xargs sed -i "s/{{ STATIC_URL }}\([^\"]\+\)/{% static '\1' %}/g"
"""
jQuery templates use constructs like:
{{if condition}} print something{{/if}}
This, of course, completely screws up Django templates,
because Django thinks {{ and }} mean something.
Wrap {% verbatim %} and {% endverbatim %} around those
blocks of jQuery templates and this will try its best
@prestontimmons
prestontimmons / json-response.py
Created February 13, 2012 02:19 — forked from leah/json-response.py
JSONResponse classes
import re
import simplejson
from django.http import HttpResponse
from django.conf import settings
class JSONResponse(HttpResponse):
def __init__(self, request, data):
indent = 2 if settings.DEBUG else None
@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))
@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 / gist:1627767
Created January 17, 2012 17:40
Change permissions on directories
find /my/directory/ -type d -exec chmod 755 {} \;
@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: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: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: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