Skip to content

Instantly share code, notes, and snippets.

@gurgeh
gurgeh / cos_dist.py
Last active September 27, 2016 10:17
import csv
import sys
from scipy import spatial
def compare_year(d, y1, cluster, y2):
dist = []
for vec in d[y2]:
dist.append(spatial.distance.cosine(d[y1][cluster], vec))
best = [(score, i) for (i, score) in enumerate(dist)]
@gurgeh
gurgeh / add_files.py
Last active September 27, 2016 07:08
import csv
import os
def add_all(path, prefix):
rows = []
first = True
for fname in os.listdir(path):
if fname.startswith(prefix):
with open(os.path.join(path, fname)) as inf: # join path and filename
c = csv.reader(inf)
@gurgeh
gurgeh / lottery.py
Created December 11, 2015 13:10
Notch's lottery question
import random
def timeto(nguys, nwins):
guys = [0] * nguys
i = 0
while True:
i += 1
j = random.randrange(0, nguys)
guys[j] += 1
if guys[j] == nwins:
@gurgeh
gurgeh / 15min.gnaural
Created January 30, 2013 13:30
15 minutes meditation for Gnaural
<?xml version="1.0"?>
<!-- See http://gnaural.sourceforge.net -->
<schedule>
<gnauralfile_version>1.20101006</gnauralfile_version>
<gnaural_version>1.0.20110606</gnaural_version>
<date>Mon Jan 28 15:15:33 2013
</date>
<title>Quick meditation</title>
<schedule_description>15 min isochronic 4 Hz meditation followed by 45 minutes 35 Hz</schedule_description>
<author>David Fendrich</author>
@gurgeh
gurgeh / oldvsnew.cpp
Created October 11, 2012 11:37
Comparison of C++ string writing
#include <vector>
#include <string>
#include <map>
#include <iostream>
using namespace std;
/*
d = {"primes" : [2, 3, 5, 7],
"fib": [1, 1, 2, 3]}
@gurgeh
gurgeh / mp3.cpp
Created October 11, 2012 11:29
A C++ example of Dive Into Python
//Having to include so many different header files to do basic
//things like open a file, use strings, vectors and tuples, etc,
//is still annoying.
#include <fstream>
#include <vector>
#include <map>
#include <tuple>
#include <string>
//To use C++11 lambdas with Boost lambdas we define this.
@gurgeh
gurgeh / gist:3800232
Created September 28, 2012 14:36
Gurgeh's Zsh configuration
# Path to your oh-my-zsh configuration.
ZSH=$HOME/.oh-my-zsh
# Set name of the theme to load.
# Look in ~/.oh-my-zsh/themes/
# Optionally, if you set this to "random", it'll load a random theme each
# time that oh-my-zsh is loaded.
ZSH_THEME="gurgeh"
@gurgeh
gurgeh / gist:3800072
Created September 28, 2012 14:05
Gurgeh's Zsh prompt
function prompt_char {
git branch >/dev/null 2>/dev/null && echo '±' && return
hg root >/dev/null 2>/dev/null && echo '☿' && return
echo '%(!.!.➜)'
}
function parse_hg_dirty {
if [[ -n $(hg status -mard . 2> /dev/null) ]]; then
echo "$ZSH_THEME_HG_PROMPT_DIRTY"