Skip to content

Instantly share code, notes, and snippets.

View prestontimmons's full-sized avatar

Preston Timmons prestontimmons

View GitHub Profile
@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
"""
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 / 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"
@prestontimmons
prestontimmons / Manifest.in
Created May 8, 2012 15:25
Minimal setup.py file
include README.md
global-include *.html
global-include *.js
global-include *.css
global-include *.json
global-include *.txt
global-include *.sql
@prestontimmons
prestontimmons / gist:2636566
Created May 8, 2012 15:53
Overriding Django template loaders within tests
from django.test.utils import (
setup_test_template_loader,
restore_template_loaders,
)
class MyTest(TestCase):
def setUp(self):
setup_test_template_loader({
"basic.html": "Basic",
@prestontimmons
prestontimmons / gist:2636865
Created May 8, 2012 16:16
Convert mercurial repository to git
git clone git://repo.or.cz/fast-export.git
git init git_repo
cd git_repo
~/Desktop/fast-export/hg-fast-export.sh -r /path/to/old/mercurial_repo
git checkout HEAD
@prestontimmons
prestontimmons / gist:2638529
Created May 8, 2012 19:02
Posting data with curl

Posting data to a url

curl -d "param1=123&param2=456" http://example.com

Posting a multi-part request with a photo attachment

Install a .deb file

dpkg -i package_file.deb

Uninstall a .deb file

dpkg -r package_name
@prestontimmons
prestontimmons / gist:3004647
Created June 27, 2012 15:02
CSS transition example
/* -- boxel --------------------------- */
.boxel {
background-color: #eee;
border-radius: 4px;
padding: 10px 0;
color: #666;
text-align: center;
-webkit-transition: background-color 0.25s linear;
-moz-transition: background-color 0.25s linear;
@prestontimmons
prestontimmons / gist:3800756
Created September 28, 2012 16:19
Django test with test template loader
from django.template import Template
from django.test import TestCase
from django.test.client import RequestFactory
from django.test.utils import (
setup_test_template_loader,
restore_template_loaders,
override_settings,
)
class TemplateTest(TestCase):