Skip to content

Instantly share code, notes, and snippets.

======================================================
Setting up Django using Apache/mod_wsgi on Ubuntu 8.10
======================================================
This article will cover setting up Django using Apache/mod_wsgi on Ubuntu
8.10. The article is targeted at a production environment, but keep in mind
this is a more generalized environment. You may have different requirements,
but this article should at least provide the stepping stones.
The article will use distribution packages where nesscary. As of 8.10 the
@fcurella
fcurella / json_response.py
Created December 30, 2010 04:02
A little decorator that allows you to return a dict in your views instead of render_to_response or HttpResponse or whatever. It respects the callback argument for proper JSONP action if you so choose.
from django.http import HttpResponse
from decorator import decorator
import simplejson as json
@decorator
def json_response(f, *args, **kwargs):
try:
status_code = 200
response = {
'status': True,
# -*- coding: utf-8 -*-
import datetime
from django.http import HttpResponse
from django.utils import simplejson
from django.shortcuts import render_to_response
from django.template import RequestContext
class DateTimeJSONEncoder(simplejson.JSONEncoder):
"""
@fcurella
fcurella / IterableCollection.js
Created January 9, 2011 18:06
A Backbone.js collection class with utility methods for iterating and picking
IterableCollection = Backbone.Collection.extend({
initialize: function() {
//_.bindAll(this, )
this._resetIndexes();
},
_resetIndexes: function() {
this.currentIndex = 0;
this.hasSelection = false;
},
parse: function(response) {
@fcurella
fcurella / placeholders.js
Created January 15, 2011 21:44
Add 'placeholder' attribute support to inputs and textareas. Requires jQuery and Modernizr.
$(function(){
if (!Modernizr.input.placeholder) {
$('input[placeholder], textarea[placeholder]').each(function(index, elem) {
elem = $(elem);
placeholder = elem.attr('placeholder');
elem_id = elem.attr('id');
elem_name = elem.attr('name');
clone = elem.clone();
clone.hide();
// execute callback only after a pause in user input; the function returned
// can be used to handle an event type that tightly repeats (such as typing
// or scrolling events); it will execute the callback only if the given timout
// period has passed since the last time the same event fired
function createOnPause(callback, timeout, _this) {
return function(e) {
var _that = this;
if (arguments.callee.timer)
clearTimeout(arguments.callee.timer);
arguments.callee.timer = setTimeout(function() {
"""
Straight Include template tag by @HenrikJoreteg
Django templates don't give us any way to escape template tags.
So if you ever need to include client side templates for ICanHaz.js (or anything else that
may confuse django's templating engine) You can is this little snippet.
Just use it as you would a normal {% include %} tag. It just won't process the included text.
@fcurella
fcurella / gist:976625
Created May 17, 2011 14:56 — forked from putermancer/gist:591964
Set up a local solr instance on mac
# Setting up a local solr instance on a mac
# install solr with homebrew
brew install solr
# create the base solr index directory
mkdir -p /data/solr
# make sure you can write to the solr logs
sudo chown -R `whoami` /usr/local/Cellar/solr/
@fcurella
fcurella / clean_pyc
Created August 25, 2011 21:17
command to clean stale *.pyc files
#!/bin/sh
find . -name '*.pyc' -print0|xargs -0 rm
@fcurella
fcurella / bootstrap_python_django.sh
Created September 9, 2011 19:47
This script installs virtualenv and pip, and create a virtualenv with django and your project
#!/bin/bash
PROJ_DIR=$1
PROJ_NAME=$2
easy_install virtualenv pip;
mkdir -p $PROJ_DIR;
virtualenv $PROJ_DIR
source $PROJ_DIR/bin/activate