Skip to content

Instantly share code, notes, and snippets.

@tjulien
tjulien / LRUCache.java
Created March 4, 2012 19:41 — forked from hoffrocket/LRUCache.java
Simple LRUCache in java (not threadsafe)
import java.util.HashMap;
import java.util.Map;
public class LRUCache<K, V> {
private final Map<K, Pair<Node<K>, V>> map = new HashMap<K, Pair<Node<K>,V>>();
private Node<K> head = null;
private Node<K> tail = null;
private final int maxSize;
@tjulien
tjulien / serve.sh
Created May 17, 2011 01:27 — forked from aroscoe/serve.sh
Start a simple python server to serve files
#!/usr/bin/env bash
IP=`ifconfig | grep "inet " | grep -v "inet 127.0.0.1" | cut -f 2 -d " "`
PORT=$1
if [ -z "$1" ]
then
PORT=8000
fi
# Copy ip and port to pasteboard
@tjulien
tjulien / ubuntu amis
Created April 3, 2011 04:03
list of ubuntu amis
https://help.ubuntu.com/community/EC2StartersGuide
@tjulien
tjulien / whathaveyoudoneformelately
Created March 3, 2011 02:50
print diffs for my commits in chronological order since some time ago
git log --committer=tjulien -p --no-prefix --simplify-merges --reverse --since="4 weeks ago"
@tjulien
tjulien / geohaystack example
Created January 28, 2011 18:53
geohaystack example
https://github.com/mongodb/mongo/blob/master/jstests/geo_haystack2.js
t = db.geo_haystack2
t.drop()
function distance( a , b ){
var x = a[0] - b[0];
var y = a[1] - b[1];
return Math.sqrt( ( x * x ) + ( y * y ) );
}
@tjulien
tjulien / mac screenshot shortcuts
Created December 9, 2010 20:08
mac screenshot shortcuts
Command-Shift-3: Take a screenshot of the screen, and save it as a file on the desktop
Command-Shift-4, then select an area: Take a screenshot of an area and save it as a file on the desktop
Command-Shift-4, then space, then click a window: Take a screenshot of a window and save it as a file on the desktop
Command-Control-Shift-3: Take a screenshot of the screen, and save it to the clipboard
Command-Control-Shift-4, then select an area: Take a screenshot of an area and save it to the clipboard
Command-Control-Shift-4, then space, then click a window: Take a screenshot of a window and save it to the clipboard
@tjulien
tjulien / ec2_ssh.sh
Created October 11, 2010 17:57
log in to an ec2 instance sitting behind an elb
#!/bin/bash
# login to an ec2 instance sitting behind an elb
if [ -z $1 ]
then
echo "Usage: ec2_ssh.sh elb-tag-name"
exit 1
fi
@tjulien
tjulien / pretty print json
Created October 2, 2010 04:54
pretty prints json
#! /bin/bash
# pretty-prints json
# Usage: curl http://foo.com/foo.json | json.sh
python -m json.tool
@tjulien
tjulien / http sniff
Created October 1, 2010 22:13 — forked from fberger/mvn invocations
http sniff
# print http headers and body
tshark -R 'http' -S -V -l | awk '/^[HL]/ {p=30} /^[^ HL]/ {p=0} /^ / {--p} {if (p>0) print}'
#! /usr/bin/python
import random
import sys
def main():
''' generates a random sys.argv[1] x sys.argv[2] matrix.
useful for testing solutions to
http://github.com/AlgorithmsNYC/AlgorithmsNYC/tree/master/Problem_0001/ '''