Skip to content

Instantly share code, notes, and snippets.

View jsocol's full-sized avatar
🙃
for oss: hoping to get back to a monthly check-in/update cadence

James Socol jsocol

🙃
for oss: hoping to get back to a monthly check-in/update cadence
View GitHub Profile
@jsocol
jsocol / gist:746938
Created December 18, 2010 22:35
how to gzip output
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/css application/x-javascript
</IfModule>
@jsocol
jsocol / .gitconfig
Created December 30, 2010 15:37
The important parts of my .gitconfig
[color]
diff = auto
status = auto
branch = auto
grep = auto
[core]
excludesfile = /home/james/.gitignore
[alias]
a = add
ci = commit
@jsocol
jsocol / functools.js
Created February 12, 2011 08:00
partial and curry
var partial = exports.partial = function partial(fn) {
var args = arguments,
func = fn;
[].shift.apply(args);
return function() {
var _args = [].slice.call(args, 0);
[].push.apply(_args, arguments);
return func.apply(func, _args);
};
};
@jsocol
jsocol / php-serve.py
Created February 14, 2011 17:32
A local dev server for PHP.
#!/usr/bin/env python
"""
Add php-serve.py to your PATH, then, from whatever directory is the root
of your PHP application, just run:
$ php-serve.py
You can optionally specify a port number as an argument. By default,
port 8000 is used:
@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):
@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 / 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 / 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 / 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 / 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"