Skip to content

Instantly share code, notes, and snippets.

@jthomm
jthomm / sdr.sh
Last active March 14, 2018 02:53
brew, rtl_fm, play
# Write to file (outputs signed 16-bit integers representing audio signal)
rtl_fm -f 90.5M -M fm -s 50k -r 32k example.raw
# See the character representations of these integers (if we hadn't specified a file name, it would have printed this to terminal)
more example.raw
# Install Sound eXchange to get a program called "play" which can play the data
brew install sox
# Play the file we just recorded (32k sample rate, type = signed 16-bit, little-endian, one channel)
@jthomm
jthomm / hmm.py
Created September 28, 2016 10:40
import simplejson as json
import gzip
import csv
import re
from collections import OrderedDict
from utils import lazy_property, Rewinder, \
_retrieve_file_path, _gcdata_file_path, _all_eids, \
_read_schedule, _seconds_passed, _unicode_nonempty, \
_yards_fog, _to_inches, _experience, _to_date, _to_datetime, \
_attrs_match, _keys_match
CREATE
TABLE t_play_pos_dst
(
_gc_cur_drive_play_id INT PRIMARY KEY,
pos_abbr TEXT,
dst_abbr TEXT,
FOREIGN KEY (_gc_cur_drive_play_id) REFERENCES gc_cur_drive_play (_id)
)
;
// This script fetches NFL Game Center data for each game in a given week of
// the NFL pre, regular, or postseason. Data for each game is loaded in the
// browser as a JavaScript object, which is then stringified and written to a
// file named after the game's Game Center ID (e.g. "2014092800.json").
//
// Usage:
//
// casperjs gcdata.casper.js <year> <season type> <week>
//
// Example:
@jthomm
jthomm / gist:9315941
Created March 3, 2014 00:01
baseball metric year-to-year correlation
http://www.fangraphs.com/blogs/basic-pitching-metric-correlation-1955-2012-2002-2012/
http://www.fangraphs.com/blogs/basic-hitting-metric-correlation-1955-2012-2002-2012/
http://www.beyondtheboxscore.com/2012/1/9/2690405/what-starting-pitcher-metrics-correlate-year-to-year
http://www.beyondtheboxscore.com/2011/9/1/2393318/what-hitting-metrics-are-consistent-year-to-year
@jthomm
jthomm / gist:9286515
Created March 1, 2014 07:30
Linear weights by batted ball type
"Evaluating Pitcher Talent" (http://www.ussmariner.com/2006/08/29/evaluating-pitcher-talent/) -Dave Cameron
"What's a Batted Ball Worth?" (http://www.ussmariner.com/2005/11/28/run-values/) -Dave Studenmund
RUN VALUES
LD 0.356
HBP 0.342
uBB 0.315
@jthomm
jthomm / gist:3916268
Created October 19, 2012 04:38
Python single linear regression
def regress(x, y):
# Ensure equal length iterables
if not len(x) == len(y):
raise ValueError('Unequal lengths')
# Initialize values
n = len(x)
sx = sum(x)
sy = sum(y)
sxx = sum(val**2 for val in x)
sxy = sum(x_val*y_val for x_val, y_val in zip(x, y))
@jthomm
jthomm / gist:3145562
Created July 19, 2012 17:41
`toType` function for JavaScript
// Returns the class name of `object` (e.g. '[object Function]' -> 'Function') or 'NaN'.
// If `query` is provided, returns whether object is of type 'query'.
function toType(object, query) {
var type = object !== object ? 'NaN' : ({}).toString.call(object).match(/\s([^\]]+)/)[1];
return typeof query === 'undefined' ? type : type === query;
}
toType([1, 2]); // 'Array'
toType([1, 2], 'Array'); // true
@jthomm
jthomm / gist:3145449
Created July 19, 2012 17:21
Gist.io test

Head

Gist is a simple way to share snippets and pastes with others. All gists are git repositories, so they are automatically versioned, forkable and usable as a git repository.

First Subheading

Lorem ipsum.

@app.route('/')