Skip to content

Instantly share code, notes, and snippets.

@mikeyk
mikeyk / redis_session_backend.py
Created April 8, 2011 18:01
A redis backend for Django Sessions, tested on Django 1.3+
from django.contrib.sessions.backends.base import SessionBase, CreateError
from django.conf import settings
from django.utils.encoding import force_unicode
import redis
class SessionStore(SessionBase):
""" Redis store for sessions"""
def __init__(self, session_key=None):
self.redis = redis.Redis(
anonymous
anonymous / bootstrap.sh
Created June 2, 2011 17:19
Django on Heroku with Celery and Sentry
virtualenv --no-site-packages .
source bin/activate
bin/pip install Django psycopg2 django-sentry
bin/pip freeze > requirements.txt
bin/django-admin.py startproject mysite
cat >.gitignore <<EOF
bin/
include/
lib/
EOF
@nzakas
nzakas / sprintf.js
Created June 8, 2011 02:56
Quick and dirty sprintf
/*
* Quick and Dirty sprintf
* Copyright 2011 Nicholas C. Zakas. All rights reserved.
* BSD licensed
*/
/*
* This function does not attempt to implement all of sprintf, just %s,
* which is the only one that I ever use.
*/
@jsocol
jsocol / data-uri.py
Created July 18, 2011 14:48
Give an image, get a data-uri
#!/usr/bin/env python
"""Command line script to convert a file, usually an image, into a data URI
for use on the web."""
import base64
import mimetypes
import os
import sys
import os
from optparse import make_option
from django.conf import settings
from django.core.management.base import BaseCommand, CommandError
from django.db.models.loading import get_model
from babel.messages.pofile import read_po, write_po
from tower.management.commands.extract import TEXT_DOMAIN, tweak_message
def todict(obj, classkey=None):
if isinstance(obj, dict):
for k in obj.keys():
obj[k] = todict(obj[k], classkey)
return obj
elif hasattr(obj, "__iter__"):
return [todict(v, classkey) for v in obj]
elif hasattr(obj, "__dict__"):
data = dict([(key, todict(value, classkey))
for key, value in obj.__dict__.iteritems()
@harthur
harthur / tweets.js
Created October 25, 2011 19:25
tweets.js
var ntwitter = require("ntwitter"),
growl = require("growl");
var twitter = new ntwitter({
// fill in w/ keys from https://dev.twitter.com/apps/new
consumer_key: null,
consumer_secret: null,
access_token_key: null,
access_token_secret: null
});
@jsocol
jsocol / Explain.rst
Last active September 28, 2015 07:27
@json_view decorator

I finally put this in its own package! Check out django-jsonview.

This is a decorator that guarantees a response will be JSON, and sends meaningful (to a developer) error messages. It relies on a BadRequest exception I created elsewhere, because there is no standard way of handling that in Django (frex, we should really return HTTP 400 on form validation failures but they don't make that particularly easy). That could easily be removed, though.

@potch
potch / bezzy.js
Created March 5, 2012 21:58
bezier curve function generator returns a function(t) that accepts [0..1] and returns an [x,y] pair at that point.
function bezzy() {
var pts = Array.prototype.slice.call(arguments),
funcs = [];
function b1(p1, p2) {
return function(t) {
var i = 1 - t;
return [p1[0]*i+p2[0]*t, p1[1]*i+p2[1]*t];
}
}
function b2(p1, p2, p3) {
@paulrouget
paulrouget / scratchpad.js
Created March 21, 2012 09:38
Firefox Magnifier
/*
TODO:
- zoom level menu
- need to find a way to re-start the update
- add color tools
- integrate better in Firefox
- crosshair has a 1px offset
*/