Skip to content

Instantly share code, notes, and snippets.

@jacobian
jacobian / virtualenv-example.rb
Created October 5, 2010 21:36
My first Chef definition: create a virtualenv. Be nice.
# An example of the below
virtualenv "/home/dvcsmirrors/hg" do
owner "root"
group "dvcsmirrors"
mode 0775
packages "Mercurial" => "1.6.3",
"hgsubversion" => "1.1.2"
end
// helper function that goes inside your socket connection
client.connectSession = function(fn) {
var cookie = client.request.headers.cookie;
var sid = unescape(cookie.match(/connect\.sid=([^;]+)/)[1]);
redis.get(sid, function(err, data) {
fn(err, JSON.parse(data));
});
};
// usage
@coderanger
coderanger / db_server.rb
Created October 20, 2010 23:29
Create postgres users and databases from Chef
#
# Cookbook Name:: atari
# Recipe:: db_server
#
# Copyright 2010, Atari
#
# All rights reserved
#
include_recipe "postgresql::server"
@elmarx
elmarx / django_gunicorn
Created December 23, 2010 14:35
init.d script for Debian GNU/Linux to run multiple Django instances, each in it's own virtualenv, with gunicorn.
#! /bin/sh
### BEGIN INIT INFO
# Provides: gunicorn_django
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Gunicorn WSGI server for django
# Description: This script starts a gunicorn instance for each django instance
### END INIT INFO
anonymous
anonymous / Javascript flow
Created January 13, 2011 23:16
Use these functions to be able to express yourself beautifully in javascript
/**
* Binds a method to an object, so "this" inside the method
* refers to that object when it is called.
* @param method
* A reference to the function to call
* @param obj
* The object to bind to
* @param options
* Optional. If supplied, binds these options and passes
* them during invocation.
#!/usr/bin/env python
"""
fabfile.py
Copyright (c) 2011 Giovanni Collazo
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
@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(
@olov
olov / references.rb
Last active September 25, 2015 17:58
Jekyll markdown references plugin by Olov Lassus: Keep all your markdown reference-style link definitions in one file (_references.md)
# references.rb has moved to https://github.com/olov/jekyll-references
@zmsmith
zmsmith / jpegfield.py
Created June 20, 2011 21:54
Implementation of a Django ImageField that converts all images to JPEG
import Image
import cStringIO
from django.core.files.base import ContentFile
from django.db.models import ImageField
from django.db.models.fields.files import ImageFieldFile
class JPEGImageFieldFile(ImageFieldFile):
@lerouxb
lerouxb / gist:1234843
Created September 22, 2011 14:02
Django Redis JSON Sessions
# originally from https://github.com/martinrusev/django-redis-sessions
# but use json, not pickle
import json
import pickle
import time
from redis import Redis
from django.utils.encoding import force_unicode
from django.contrib.sessions.backends.base import SessionBase, CreateError
from django.conf import settings