Skip to content

Instantly share code, notes, and snippets.

View mattdennewitz's full-sized avatar

Matt Dennewitz mattdennewitz

  • Lancaster, OH
View GitHub Profile
@mattdennewitz
mattdennewitz / chadwick.rb
Created September 10, 2011 22:56
chadwick 0.5.3 homebrew formula
require 'formula'
class Chadwick <Formula
url 'http://cdnetworks-us-2.dl.sourceforge.net/project/chadwick/chadwick-0.5/0.5.3/chadwick-0.5.3.tar.gz'
homepage 'http://chadwick.sourceforge.net/doc/index.html'
md5 'd8941a0bc0d075e9eb612cf7744657bf'
def install
system "./configure"
system "make"
@mattdennewitz
mattdennewitz / gist:1222935
Created September 16, 2011 19:39
VCL Redirect Hack
sub vcl_recv {
# ...
# detect reader's device, redirect if necessary
if (req.http.user-agent ~ "iPhone|iPod|Android") {
if(req.http.host ~ "^example.com") {
# mobile reader is on desktop site.
# raise an error with status=700 and use correct url as response body.
# vcl_error will use this response body as the Location: header.
error 700 "http://m.example.com" + req.url;
@mattdennewitz
mattdennewitz / cwgame__ext_game_header.diff
Created September 17, 2011 23:26
Patch for printing extended headers in 'cwgame'
*** cwgame.c 2011-09-17 18:24:18.000000000 -0500
--- cwgame__print_ext_hdrs.c 2011-09-17 18:24:12.000000000 -0500
***************
*** 2229,2234 ****
--- 2229,2246 ----
}
}
+ for (i = 0; i <= max_ext_field; i++) {
+ if (ext_fields[i]) {
@mattdennewitz
mattdennewitz / woba_map.js
Created September 18, 2011 23:09
Retrosheet/wOBA mapping function
function() {
var woba_fields = {nibb: (this.EVENT_CD == '14') ? 1 : 0,
hbp: (this.EVENT_CD == '15') ? 1 : 0,
_1b: (this.EVENT_CD == '20') ? 1 : 0,
_2b: (this.EVENT_CD == '21') ? 1 : 0,
_3b: (this.EVENT_CD == '22') ? 1 : 0,
hr: (this.EVENT_CD == '23') ? 1 : 0,
rboe: (this.BAT_SAFE_ERR_FL == 'T') ? 1 : 0,
pa: 1};
emit(this.BAT_ID, woba_fields);
@mattdennewitz
mattdennewitz / woba_reduce.js
Created September 18, 2011 23:09
Retrosheet/wOBA reducer
function(key, values) {
var result = {nibb: 0, hbp: 0, _1b: 0, _2b: 0, _3b: 0, hr: 0, rboe: 0, pa: 0};
for(var i in values) {
result.nibb += values[i].nibb;
result.hbp += values[i].hbp;
result._1b += values[i]._1b;
result._2b += values[i]._2b;
result._3b += values[i]._3b;
result.hr += values[i].hr;
@mattdennewitz
mattdennewitz / woba_finalize.js
Created September 18, 2011 23:10
Retrosheet/wOBA calculation
function(key, result) {
return ((0.72 * result.nibb) + (0.75 * result.hbp) + (0.9 * result._1b) + (0.92 * result.rboe) +
(1.24 * result._2b) + (1.56 * result._3b) + (1.95 * result.hr)) / result.pa;
}
@mattdennewitz
mattdennewitz / wOBA.py
Created September 18, 2011 23:26
Calculate 2010 batting wOBA
from bson.code import Code
import pymongo
connection = pymongo.connection.Connection()
db = connection['retrosheet']
tbl = db['events_2010']
# limit results to complete plate appearances.
@mattdennewitz
mattdennewitz / gist:2847650
Created June 1, 2012 00:47
M2M-aware RealTimeSearchIndex
from django.db.models import signals
from haystack.indexes import RealTimeSearchIndex
class ManyAwareRealTimeSearchIndex(RealTimeSearchIndex):
"""Many-to-many aware real-time search index base class
"""
def _on_m2m_changed(self, instance, using=None, **kwargs):
@mattdennewitz
mattdennewitz / gist:4073404
Created November 14, 2012 17:14
Formatted TZ offset by name
import datetime
import dateutil.tz
import pytz
def get_formatted_tz(zone):
"""Returns +/-HH:MM formatted time zone offset.
#!/usr/bin/env python
import sys
last = ''
punc = ','
while True:
c = sys.stdin.read(1)
if c: