Skip to content

Instantly share code, notes, and snippets.

View marklit's full-sized avatar

Mark Litwintschik marklit

View GitHub Profile
@marklit
marklit / colours.py
Created July 26, 2011 10:25
ANSI highlighting with Python
class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
def disable(self):
self.HEADER = ''
@marklit
marklit / django-setup.sh
Created August 10, 2011 16:09
Django site setup cheat sheet
$ export PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
$ sudo easy_install setuptools
$ wget http://pypi.python.org/packages/source/p/pip/pip-0.6.3.tar.gz
$ tar xzf pip-0.6.3.tar.gz
$ cd pip-0.6.3
$ sudo python setup.py install
$ sudo pip install virtualenv virtualenvwrapper
@marklit
marklit / apple.html
Created August 24, 2011 08:18
Apple Icon HTML header example
<link rel="apple-touch-icon" href="images/apple-touch-icon.png">
<link rel="apple-touch-icon" sizes="72x72" href="images/apple-touch-icon-72x72.png">
<link rel="apple-touch-icon" sizes="114x114" href="images/apple-touch-icon-114x114.png">
@marklit
marklit / gist:1220541
Created September 15, 2011 21:34
Linode costs per MB to upgrade a VPS
RAM Disk Bandwidth
cost per month (USD) $20.00 $2.00 $10.00
amount per month (MB) 360MB 2048MB 102,400MB
$/GB $56.89 $1.00 $0.10
Ratio ~57x 10x
@marklit
marklit / hg_logs.sh
Created October 31, 2011 13:41
Makes Mercurial logs more readable
alias hglog="hg log --template '\033[31m{rev}\033[0m \033[32m{date|age}\033[0m \033[33m{author|person}\033[0m \033[30;1m{desc}\033[0m\n' | less -R"
@marklit
marklit / hgdiff
Created October 31, 2011 16:46
Diff syntax highlighting
hg diff | \
sed -e 's/^--- .*/'`echo -e "\033[0;46m"`'&'`echo -e "\033[0m"`'/' | \
sed -e 's/^+++ .*/'`echo -e "\033[0;46m"`'&'`echo -e "\033[0m"`'/' | \
sed -e 's/^-.*/'`echo -e "\033[0;41m"`'&'`echo -e "\033[0m"`'/' | \
sed -e 's/^+.*/'`echo -e "\033[0;42m"`'&'`echo -e "\033[0m"`'/' | \
less -R
@marklit
marklit / threading_queues.py
Created November 1, 2011 14:27
Threading and queues in Python
import threading, Queue, time, random
WORKERS = 4
JOB_COUNT = 100
class Worker(threading.Thread):
def __init__(self, queue):
self.__queue = queue
threading.Thread.__init__(self)
require 'twitter'
Twitter::Search.new.geocode(39.037, -94.5874, '5mi').fetch().results
#=> all tweets within 5 miles of lat/lon
Twitter::Search.geocode(39.037, -94.5874, '5mi').fetch().results.first
#=> most recent tweet within 5 miles of lat/lon
Twitter::Search.new('dinner').geocode(39.037, -94.5874, '5mi').fetch().results
#=> all tweets containing the word 'dinner' within 5 miles of lat/lon
var song = new Backbone.Model({
title: "Lucy In The Sky With Diamonds",
album: new Backbone.Model({
title: "Sgt. Pepper's Lonely Hearts Club Band",
release: {
year: "1987"
}
})
});
@marklit
marklit / gist:2805184
Created May 27, 2012 11:05 — forked from gabesmed/gist:376015
The routing algorithm from Scenic Route (http://scenicroute.info)
import math
import random
import operator
from django.contrib.gis.geos import LineString, Point
from scenicroute.apps.hunts.routing.triangulation import (
build_triangulation, START_INDEX, END_INDEX)
from scenicroute.apps.hunts.routing.culling import no_dupes
from scenicroute.apps.hunts.routing.estimation import (duration_for_distance,