Skip to content

Instantly share code, notes, and snippets.

View prestontimmons's full-sized avatar

Preston Timmons prestontimmons

View GitHub Profile
@prestontimmons
prestontimmons / gist:776293
Created January 12, 2011 15:26
clearfix.css
/* -----------------------
clearfix
from http://perishablepress.com/press/2008/02/05/lessons-learned-concerning-the-clearfix-css-hack/
*/
.group:after {
visibility: hidden;
display: block;
font-size: 0;
content: " ";
clear: both;
@prestontimmons
prestontimmons / settings_override.py
Created February 18, 2011 15:04
Override a Django setting during a test with a context processor
# -*- coding: utf-8 -*-
'''
Borrowed from Django CMS. This is too useful to live without
'''
from django.conf import settings
class NULL:
pass
@prestontimmons
prestontimmons / gist:849715
Created March 1, 2011 19:27
Check OS version
cat /proc/version
@prestontimmons
prestontimmons / gist:855795
Created March 4, 2011 22:10
Carousel with javascript
<!-- Carousel -->
<div id="carousel" class="feature autorotate slidelinks group">
<!-- Slides -->
<div class="carousel-slides">
<div class="slide">
<a href="/bundles/greatest-need/"><img src="//www.gfamedia.org/images/bundles-slide/greatest-need.jpg" alt=""></a>
</div>
<div class="slide">
<!DOCTYPE HTML>
<!-- zero-timeout.html, L. David Baron <[email protected]>, 2010-03-07, 2010-03-09 -->
<!--
Copyright (c) 2010, The Mozilla Foundation
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
@prestontimmons
prestontimmons / gist:885958
Created March 24, 2011 21:44
Posting data with curl

Post data to url:

curl -d "k1=v1&k2=v2" http://example.com/

Post multipart form data to url:

curl -F "photo=@test_image.jpg" -F "k1=v1" -F "k2=v2" http://example.com/
@prestontimmons
prestontimmons / gist:920546
Created April 14, 2011 21:05
Matching template variables in Django
try:
variable_name = re.search("as (\w+)", token.contents).group(1)
except AttributeError:
raise template.TemplateSyntaxError, \
"%r tag had invalid arguments." % token.split_contents()[0]
@prestontimmons
prestontimmons / gist:945264
Created April 27, 2011 21:31
Saving an image to a Django model from a url
try:
contents = urllib2.urlopen(url).read()
except urllib2.HTTPError, exc:
# handle exception
pass
mymodel.image.save(file_name, ContentFile(contents))
@prestontimmons
prestontimmons / gist:952217
Created May 2, 2011 19:37
Sample mod_wsgi Django file
"""
WSGI application configuration.
Read http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango to learn
more about integrating with Django.
"""
import os
import site
import sys
@prestontimmons
prestontimmons / redis-server
Created June 29, 2011 04:14 — forked from tessro/redis-server
A CentOS initscript for Redis
#!/bin/sh
#
# redis - this script starts and stops the redis-server daemon
#
# chkconfig: - 85 15
# description: Redis is a persistent key-value database
# processname: redis-server
# config: /etc/redis/redis.conf
# config: /etc/sysconfig/redis
# pidfile: /var/run/redis.pid