Skip to content

Instantly share code, notes, and snippets.

@jsocol
jsocol / forms.py
Created September 21, 2011 03:50
Form-based user settings
from django import forms
from tower import ugettext_lazy as _lazy
class SettingForm(forms.Form):
auto_watch_new_threads = forms.BooleanField(
default=True, required=False, initial=True,
help_text=_lazy('Automatically watch threads I create.'))
auto_watch_reply = forms.BooleanField(
@jsocol
jsocol / jsocol-master-whoa
Created August 23, 2011 13:52
output of `git lg`
[james ((c0ff882...)) kitsune]$ git lg -15
* c0ff882 - (HEAD, origin/master, origin/HEAD) Merge branch 'remove_long_filename' of github.com:readevalprint/kitsune into remove_long_filename (14 hours ago) <Tim Watt
|\
| * f3837cb - (tim/remove_long_filename) removed (correct) gallery tests (14 hours ago) <Tim Watts :timw>
| |\
| | * 5baa3a0 - removed gallery tests (15 hours ago) <Tim Watts :timw>
| * | cd91d23 - removed (correct) gallery tests (14 hours ago) <Tim Watts :timw>
| |/
| * 9619f86 - removed file and test (4 days ago) <Tim Watts :timw>
* | 82c5e8c - Merge branch 'master' of github.com:jsocol/kitsune into remove_long_filename (14 hours ago) <Tim Watts :timw>
@jsocol
jsocol / ClientStatsD.js
Created August 3, 2011 15:46 — forked from chowse/ClientStatsD.js
StatsD for Client-Side Interactions
if (!Date.now) {
Date.now = function() {
return (new Date()).getTime();
};
}
var StatsD = (function($, undefined) {
@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
@jsocol
jsocol / git-compare
Created May 17, 2011 22:03
spits out a compare URL
$ cat /home/james/bin/git-compare
#!/bin/bash
BRANCH=$(git here)
echo "https://github.com/jsocol/kitsune/compare/$BRANCH"
@jsocol
jsocol / middleware.py
Created March 31, 2011 15:16
PermissionDeniedMiddleware for Django 1.2.x
"""
Improve PermissionDenied/HttpResponseForbidden handling in Django 1.2.
At some point, Django added better handling for PermissionDenied
and HttpResponseForbidden, including a handler403 on the ROOT_URLCONF, and,
I think, the ability to fall back to a generic 403.html.
But Django 1.2 didn't have that, as far as I know. So this middleware adds
it for Django 1.2 projects.
@jsocol
jsocol / twitter-fx4.js
Created March 22, 2011 23:32
watch #fx4 tweets stream in
/**
* Start by cloning git://github.com/technoweenie/twitter-node, then
* save this file in the same directory as the clone, edit the login
* information, and run it with:
*
* $ node twitter-fx4.js
*
* then sit back and watch!
*/
var twitter = require('./twitter-node/lib/twitter-node'),
@jsocol
jsocol / storage.js
Created March 18, 2011 14:05
Simple namespaced storage API for JS (largely stolen from Chris Van)
/**
* storage.js - Simple namespaced browser storage.
*
* Creates a window.Storage function that gives you an easy API to access localStorage,
* with fallback to cookie storage. Each Storage object is namespaced:
*
* var foo = Storage('foo'), bar = Storage('bar');
* foo.set('test', 'A'); bar.set('test', 'B');
* foo.get('test'); // 'A'
* bar.remove('test');
@jsocol
jsocol / sockolepsy.js
Created March 16, 2011 01:20
slow TCP proxy
/**
* Usage: node sockolepsy.js <listen> <forward> <delay>
*
* Creates a generic TCP proxy that can introduce a controllable degree of
* delay per packet.
*
* Params:
* listen - the port to listen on.
* forward - the port to foward to.
* delay - the amount of delay to introduce, in ms.
@jsocol
jsocol / contextdecorator.py
Created March 12, 2011 20:54
ContextDecorator for Python 2.6/2.7.
from functools import wraps
class ContextDecorator(object):
def __call__(self, fn):
@wraps(fn)
def decorator(*args, **kw):
with self:
return fn(*args, **kw)
def __enter__(self):