Skip to content

Instantly share code, notes, and snippets.

@wkschwartz
wkschwartz / spreads-example.do
Last active August 29, 2015 14:01
Example of spreads data & code in Stata
spreads_read using spreads.csv, clear
collapse (firstnm) open_pinnacle=pinnacle_spread ///
open_betonline=betonline_spread ///
open_bookmaker=bookmaker_spread ///
points_* ///
(lastnm) close_pinnacle=pinnacle_spread ///
close_betonline=betonline_spread ///
close_bookmaker=bookmaker_spread, ///
by(season week hometeam awayteam game_date)
generate byte actual = points_home - points_away

Keybase proof

I hereby claim:

  • I am wkschwartz on github.
  • I am wkschwartz (https://keybase.io/wkschwartz) on keybase.
  • I have a public key whose fingerprint is BD4C C2D4 F957 4C11 8383 A479 F609 7642 2AA9 4204

To claim this, I am signing this object:

@wkschwartz
wkschwartz / dfs.go
Created September 16, 2013 14:50
An example of using Ruby-block-like callbacks for iteration in Go. This example is basic depth-first search on an undirected graph. The function using the "block" is `dfs`, at the end.
// Undirected graph where each node is labeled by a small integer.
type Graph struct {
neighbors [][]int // a list of neighbors for each node
}
// Omitting code to initialize a graph. The initializer would take the number
// of nodes and set up the neighbors array to be the right length. Another method
// would be available to add a neighbor to a given vertex. That way for a
// Graph `g`, `g.neighbors[node]` would be an array of nodes adjacent to `node`.
@wkschwartz
wkschwartz / profiling.py
Created April 24, 2013 21:55
Timing/profiling tests on different branches of https://github.com/wkschwartz/algorithms2
from math import sqrt
def ttest(x1, x2):
"Student's t-test for unpaired, equal variance, equal size samples."
if len(x1) != len(x2):
raise ValueError('unequal sample sizes')
mx1 = sum(x1) / len(x1)
mx2 = sum(x2) / len(x2)
s2x1 = sum((xi - mx1)**2 for xi in x1) / (len(x1) - 1)
s2x2 = sum((xi - mx2)**2 for xi in x2) / (len(x2) - 1)
@wkschwartz
wkschwartz / sort.c
Last active December 16, 2015 09:08
Experiments with an LSD Radix sort
#include <stdlib.h> /* malloc, free */
#include <stdio.h> /* NULL */
/**
* Stably sort and array of unsigned integers in place in linear time. Uses
* linear extra space. Return 0 on failure to allocate memory and 1 on success.
*
* Author: William Schwartz
*/
int sort(unsigned int a[], size_t len) {
@wkschwartz
wkschwartz / gist:5295571
Last active December 15, 2015 17:19
Java utility method for helping me find outliers for the Princeton/Coursera Algorithms Part 2 course assignment "WordNet."
/**
* Reflect a upper triangular matrix across its diagonal and return the row
* index whose sum is greatest, without modifying the input matrix.
* <p>
* The non-mutating reflection is accomplished by adding down column <em>i</em>
* from 0 to <em>i</em> - 1 and adding across row <em>i</em> from <em>i</em> to
* <code>a[i].length</code>.
*
* @param a An array of arrays of integers in row-major form. The arrays should
* but do not have to be equal lengths.
@wkschwartz
wkschwartz / new_bashrc.sh
Created August 11, 2012 16:08 — forked from josephwecker/new_bashrc.sh
Replace .bashrc, .bash_profile, .profile, etc. with something much more clean, consistent, and meaningful.
#!/bin/bash
# License: Public Domain.
# Author: Joseph Wecker, 2012
#
# Are you tired of trying to remember what .bashrc does vs .bash_profile vs .profile?
# Are you tired of trying to remember how darwin/mac-osx treat them differently from linux?
# Are you tired of not having your ~/.bash* stuff work the way you expect?
#
# Symlink all of the following to this file:
# * ~/.bashrc