Skip to content

Instantly share code, notes, and snippets.

def chop(matrix, box, direction, results=None):
if results is None:
results = []
x1, y1, x2, y2 = box
w = x2 - x1 + 1
h = y2 - y1 + 1
if w <= 0 or h <= 0:
return results
else:
if direction == 0:

Running redis using upstart on Ubuntu

I've been trying to understand how to setup systems from the ground up on Ubuntu. I just installed redis onto the box and here's how I did it and some things to look out for.

To install:

#! /bin/sh
### BEGIN INIT INFO
# Provides: redis-server
# Required-Start: $syslog
# Required-Stop: $syslog
# Should-Start: $local_fs
# Should-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: redis-server - Persistent key-value db
@observerss
observerss / etc-init-elasticsearch.conf
Last active December 19, 2015 19:19 — forked from jaytaylor/etc-init-elasticsearch.conf
elasticsearch upstart script for official deb packages (tested with 0.90.2)
# ElasticSearch Service
description "ElasticSearch"
start on (net-device-up
and local-filesystems
and runlevel [2345])
stop on runlevel [016]
respawn
/*
Pretty Date script modified from John Resig here http://ejohn.org/blog/javascript-pretty-date
*/
function relativeDateTime (tdate) {
var system_date;
if (typeof (tdate) === "number") {
tdate = new Date(tdate).toString();
}
if (navigator.userAgent.match(/MSIE\s([^;]*)/)) {
@observerss
observerss / s3put
Created October 9, 2012 09:38 — forked from mattbillenstein/s3put
boto parallel s3 upload script
#!/usr/bin/env python
import gevent.monkey
gevent.monkey.patch_all()
import boto
import config
import gevent
import gevent.pool
import os
@observerss
observerss / gevent-multiprocess.py
Created September 26, 2012 07:55 — forked from denik/gevent-multiprocess.py
Python: Gevent multiprocessing server
import sys
from gevent import server
from gevent.baseserver import _tcp_listener
from gevent.monkey import patch_all; patch_all()
from multiprocessing import Process, current_process, cpu_count
def note(format, *args):
sys.stderr.write('[%s]\t%s\n' % (current_process().name, format%args))
@observerss
observerss / gist:3786658
Created September 26, 2012 07:51 — forked from padolsey/gist:527683
JavaScript: Detect IE
// ----------------------------------------------------------
// A short snippet for detecting versions of IE in JavaScript
// without resorting to user-agent sniffing
// ----------------------------------------------------------
// If you're not in IE (or IE version is less than 5) then:
// ie === undefined
// If you're in IE (>=5) then you can determine which version:
// ie === 7; // IE7
// Thus, to detect IE:
// if (ie) {}