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)
@marklit
marklit / worker.py
Created November 11, 2011 10:52
ZeroMQ Worker example
import zmq
from multiprocessing import Process
def worker(wrk_num):
print "Getting ready to work", wrk_num
context = zmq.Context()
work_receiver = context.socket(zmq.PULL) # Channel to receive work
work_receiver.connect("tcp://127.0.0.1:5557")
@marklit
marklit / server.py
Created November 11, 2011 10:52
ZeroMQ Ventilator/Results Manager example
import zmq
from multiprocessing import Process
def ventilator():
context = zmq.Context()
ventilator_send = context.socket(zmq.PUSH) # Set up a channel to send work
ventilator_send.bind("tcp://127.0.0.1:5557")
for num in range(10000):
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