Skip to content

Instantly share code, notes, and snippets.

View SpencerBingol's full-sized avatar

Spencer Bingol SpencerBingol

  • Boston Red Sox - Manager, Baseball Analytics
  • Boston, MA
View GitHub Profile
@SpencerBingol
SpencerBingol / Retrosheet Multi-Year FIP
Last active May 23, 2016 05:02
[MYSQL] Multi-year FIP Function for Retrosheet
-- function to calculate multi-year FIP for Retrosheet
-- This snippet supposes you have the Fangraphs GUTS table located with-in retrosheet.
-- Currently calculates career FIP. Just add a year parameter and it works for single season calculations.
DELIMITER //
CREATE FUNCTION FIP(pitcher VARCHAR(8))
RETURNS DECIMAL(10,2)
BEGIN
DECLARE FIP DECIMAL(10,2);
@SpencerBingol
SpencerBingol / Retrosheet Multi-Year wOBA
Created March 1, 2014 16:55
[MYSQL] Multi-year wOBA Function for Retrosheet
-- function to calculate multi-year wOBA for Retrosheet
-- This snippet supposes you have the Fangraphs GUTS table located with-in retrosheet.
-- Currently calculates career wOBA. Just add a year parameter and it works for single season calculations.
-- Also good for vs. Pitcher matchups and date ranges
DELIMITER //
CREATE FUNCTION wOBA(batter VARCHAR(8))
RETURNS DECIMAL(10,3)
BEGIN
@SpencerBingol
SpencerBingol / Ordinal Suffix solution
Created March 1, 2014 17:51
[JS] Quick solution to needing an ordinal suffix on a number. ( st nd rd th )
// adds st nd rd th to number
// returns suffix-appended string or FALSE
function ordinal_suffix (num) {
var val=parseInt(num);
if ( isNaN(val) ) return false;
var mod_ten = Math.abs(val) % 10;
var mod_hun = Math.abs(val) % 100;
if ( (mod_ten == 1) && (mod_hun != 11) ) return val + "st";
else if ( (mod_ten == 2) && (mod_hun != 12) ) return val + "nd";
@SpencerBingol
SpencerBingol / Zeller's Congruence
Last active August 29, 2015 13:57
[Java] Zeller's Congruence Implementation, finds Day of Week given numeric month, day of month, and full year.
/************************************************
* An implementation of Zeller's Congruence - presuming MM/DD/YYYY input
* more information here:
* http://en.wikipedia.org/wiki/Zeller's_congruence
*
* TL;DR notes:
* - january and february are treated as months 13 & 14 of the previous year
* - resulting day number begins on saturday (0 = "Sat", 1 = "Sun", ... , 6 = "Fri")
* - actual formula listed below
* ********************************************/
name value
Locke 4
Reyes 8
Ford 15
Jarrah 16
Shephard 23
Kwon 42