Skip to content

Instantly share code, notes, and snippets.

@joshz
joshz / gist:2595709
Created May 4, 2012 15:55
Coursera: Compilers: Cool Examples I-III
class Main {
// if you want to print something
// initialize i to new IO object
i : IO <- new IO;
// body of the program is a block of expressions
// the first one executes out_string call to the object
// i which prints "hello world", and second evaluates to 1
// which is the value of the block, which becomes the
// value of the method
/**
* User: jz
* Date: 4/23/12
* Time: 5:00 PM
*/
package main
import (
"fmt"
"os"
@joshz
joshz / fisher_th.py
Created May 13, 2012 22:10
Fisher's theorem functions, bad replicator dynamics, notes
# for 2x2 games
# PR_t+1(i) = (PR_t(i) * pi(i))/sum from j=1 to n (Pr_t(j)*pi(j))
# payoff = pi(i)
# proportion = Pr(i)
# w = weights
payoffs = [[[2,2], [2,0]],
[[0,2], [3,3]]]
payoffs = [[[2,2], [0,0]],
@joshz
joshz / lph.py
Created June 6, 2012 20:10
play with the linkedin password hash file
import hashlib
import shelve
def trim_hash(hash, offset=5):
"""outputs truncated hash
"""
return '0' * offset + hash[offset:]
def write_word_to_shelf(shelf_fn, wordfile):
"""write hashes of words in wordfile
@joshz
joshz / isnot.py
Created June 19, 2012 15:17
A is not B
import networkx as nx
import matplotlib.pyplot as plt
isnot = [('Spain', 'Greece'),
('Portugal', 'Greece'),
('Greece', 'Ireland'),
('Spain', 'Ireland'),
('Spain', 'Portugal'),
('Ireland', 'Greece'),
('Portugal', 'Ireland'),
@joshz
joshz / gist:3146444
Created July 19, 2012 20:10
grab a tweet from twitter, do sentiment analysis with AFINN
#!/usr/bin/python
#
# wget wget http://www2.imm.dtu.dk/pubdb/views/edoc_download.php/6010/zip/imm6010.zip
# unzip imm6010.zip
import math
import re
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
@joshz
joshz / the-case-for-go.txt
Created September 16, 2012 12:49
The case for Go #golang
Go at Heroku
http://blog.golang.org/2011/04/go-at-heroku.html
Why you PHP guys should learn Golang
http://www.mikespook.com/2012/08/why-you-php-guys-should-learn-golang/
Go at CloudFlare
http://blog.cloudflare.com/go-at-cloudflare
Go at Moovweb
@joshz
joshz / tree.md
Created January 3, 2013 10:14 — forked from hrldcpr/tree.md

One-line Tree in Python

Using Python's built-in defaultdict we can easily define a tree data structure:

def tree(): return defaultdict(tree)

That's it!

@joshz
joshz / pr.md
Created March 25, 2013 10:35 — forked from piscisaureus/pr.md

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = [email protected]:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

import csv
import json
with open('metrics.json', 'r') as f:
data = json.load(f)
keys = data[0].keys()
writer = csv.DictWriter(open('metrics.csv', 'wb'), keys)
writer.writer.writerow(keys)
writer.writerows(data)