Skip to content

Instantly share code, notes, and snippets.

@ericflo
ericflo / 00_logging.py
Created October 25, 2010 07:49
Log structured data about events that happen in your system (in JSON format for maximum flexibility).
# 00 prepended to filename so this shows up first in the list of gists.
import socket
import time
import simplejson
from django.conf import settings
def log_event(logger, event, request=None, data=None,
@wmerrifield
wmerrifield / build+archive.sh
Created November 8, 2010 17:53
A shell script to perform the equivalent of Xcode's "Build & Archive" command.
#!/bin/sh
#
# Copyright (c) 2010 Warren Merrifield
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
@ericflo
ericflo / redis_sessions.py
Created November 9, 2010 06:41
A Redis-based Django session store.
import simplejson
from django.contrib.sessions.backends.base import SessionBase, CreateError
from django_ext.redis_helper import get_redis
class SessionStore(SessionBase):
"""
A Redis-based session store.
@sjl
sjl / google-jslint.vim
Created December 2, 2010 17:13
Use Google's JSLint with Vim. Now you can use :make when in a .js file to run gjslint on it and get a list of errors in the quickfix window. This was thrown together hastily and Vim's errorformat is confusing as hell, so feel free to fork and improve
au BufNewFile,BufRead *.js set makeprg=gjslint\ %
" The ^G at the end is an actual <Ctrl-G> char.
" Gist won't let me include it, so you'll have to delete the last two characters
" and insert it yourself with <Ctrl-V><Ctrl-G>
au BufNewFile,BufRead *.js set errorformat=%-P-----\ FILE\ \ :\ \ %f\ -----,Line\ %l\\,\ E:%n:\ %m,%-Q,%-GFound\ %s,%-GSome\ %s,%-Gfixjsstyle%s,%-Gscript\ can\ %s,%-G^G
@ryanb
ryanb / github_tree_slider.js
Created December 6, 2010 17:23
This is how GitHub's new AJAX file browser works.
GitHub.TreeSlider = function () {
if (window.history && window.history.pushState) {
function a() {
if (e.sliding) {
e.sliding = false;
$(".frame-right").hide();
$(".frame-loading:visible").removeClass("frame-loading")
}
}
if (!($("#slider").length == 0 || !GitHub.shouldSlide)) if (!navigator.userAgent.match(/(iPod|iPhone|iPad)/)) {
@dcramer
dcramer / track_data.py
Created December 6, 2010 19:15
Tracking changes on properties in Django
from django.db.models.signals import post_init
def track_data(*fields):
"""
Tracks property changes on a model instance.
The changed list of properties is refreshed on model initialization
and save.
>>> @track_data('name')
@HenrikJoreteg
HenrikJoreteg / straight_include.py
Created December 15, 2010 16:06
A Django Template tag for including files that you don't want to parse as templates
"""
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.
@staer
staer / MultiAuthentication.py
Created January 21, 2011 19:13
Custom Django-Piston authentication backend that can handle multiple types of auth methods
# Class that can help django-piston process multiple types of authentication
# Example usage:
#
# from piston.authentication import HttpBasicAuthentication
# from somewhere import OtherCustomAuthModule
#
# httpAuth = HttpBasicAuthentication(realm="CycleCloud")
# otherAuth = OtherCustomAuthModule()
#
# auth = MultiAuthentication([httpAuth, otherAuth])
@le0pard
le0pard / getconf.sh
Created February 5, 2011 17:13
Simple shmsetup script for PostgreSQL
#!/bin/bash
# simple shmsetup script
page_size=`getconf PAGE_SIZE`
phys_pages=`getconf _PHYS_PAGES`
shmall=`expr $phys_pages / 2`
shmmax=`expr $shmall \* $page_size`
echo kernel.shmmax = $shmmax
echo kernel.shmall = $shmall
@eculver
eculver / Projects with beautiful websites
Created February 10, 2011 18:54
Projects with beautiful websites
Vows: http://vowsjs.org/
SASS: http://sass-lang.com/
SSHGuard (pretty decent layout): http://www.sshguard.net/
Django Haystack: http://haystacksearch.org/
twelvesouth (products not project, but still): http://www.twelvesouth.com/