Skip to content

Instantly share code, notes, and snippets.

// based on methodology developed by PPK:
// http://www.quirksmode.org/blog/archives/2009/08/when_to_read_ou.html
(function($){
$.benchmark = function(times, result_selector, func){
var startTime = new Date().getTime();
while (times != 0){
func();
times--;
}
======================================================
Setting up Django using Apache/mod_wsgi on Ubuntu 8.10
======================================================
This article will cover setting up Django using Apache/mod_wsgi on Ubuntu
8.10. The article is targeted at a production environment, but keep in mind
this is a more generalized environment. You may have different requirements,
but this article should at least provide the stepping stones.
The article will use distribution packages where nesscary. As of 8.10 the
require 'rubygems'
require 'redis'
require 'json'
require 'eventmachine'
class RedisLoop
class << self
attr_accessor :queues
def start(opts={}, &blk)
EM.run {
# Depends on the OS X "say" command
import time, datetime, subprocess, math, sys
def say(s):
subprocess.call(['say', str(s)])
def seconds_until(dt):
return time.mktime(dt.timetuple()) - time.time()
== Rules ==
On Infrastructure
-----------------
There is one system, not a collection of systems.
The desired state of the system should be a known quantity.
The "known quantity" must be machine parseable.
The actual state of the system must self-correct to the desired state.
The only authoritative source for the actual state of the system is the system.
The entire system must be deployable using source media and text files.
#!/bin/sh
# on ubuntu: need some utils & dev libs
sudo apt-get install apache2-utils openssl libssl-dev libpcre3-dev
# compile nginx
cd /tmp
curl http://nginx.org/download/nginx-0.7.64.tar.gz | tar xz
cd nginx*
./configure --with-http_ssl_module --with-http_dav_module \
"""
A drop in replacement for {% url %} that generates relative paths.
Just put {% load relative_urls %} at the top of your template, and all {% url %}
calls will generate paths relative to the current request path.
For example, when reversing a URL that points to ``/admin/foo/`` on the page
``/admin/bar/``, it will output ``../foo/``.
"""
# Copypasta of Django's runserver management command, modified to use gunicorn http://github.com/benoitc/gunicorn
import sys
from optparse import make_option
import django
from django.core.management.base import BaseCommand, CommandError
from django.conf import settings
from django.utils import translation
def write(sock, data):
send_buffer = ""
send_buffer += data
while send_buffer:
try:
num_bytes = sock.send(send_buffer)
send_buffer = send_buffer[num_bytes:]
return num_bytes
except socket.error, e:
if e[0] in (errno.EWOULDBLOCK, errno.EAGAIN):
;; emacsd-tile.el -- tiling windows for emacs
(defun swap-with (dir)
(interactive)
(let ((other-window (windmove-find-other-window dir)))
(when other-window
(let* ((this-window (selected-window))
(this-buffer (window-buffer this-window))
(other-buffer (window-buffer other-window))
(this-start (window-start this-window))