Skip to content

Instantly share code, notes, and snippets.

@jboverfelt
jboverfelt / whirlwind-clojure.clj
Last active August 29, 2015 14:19
whirlwind-clojure.clj
; clojure has all the basic datatypes - string, double, float, boolean
; it also has symbols, keywords, and nil instead of Java's null
; a symbol (an identifier that usually refers to something else
'test
; a keyword (generally used in maps and for "enum" like values)
:foo
; Data Structures
@jboverfelt
jboverfelt / foreach.clj
Created October 18, 2014 13:21
Example of syntax transformation. This is a simple macro but demonstrates the flexibility of being able to define your own syntax
(defmacro foreach [& body]
(let [parts (partition-by #{'in 'do} body)
[v _ lst _ forms] parts]
`(doseq [~(first v) ~(first lst)] (do ~@forms))))
@jboverfelt
jboverfelt / do-until.clj
Created January 10, 2014 23:44
Implementation of the do-until macro described in Fogus' Joy of Clojure using destructuring rather than explicit seq functions like first, second, and nnext. This macro executes all its clauses evaluating to true until it hits something falsey.
(defmacro do-until [& clauses]
(when-let [[first second & rest] clauses]
(list 'when first
(if second
second
(throw (IllegalArgumentException. "do-until requires an even number of forms")))
(cons 'do-until rest))))
@jboverfelt
jboverfelt / zcontact_busts.md
Last active January 1, 2016 00:09
Predicting Next Year's Busts

The dust from the winter meetings is settling, and GMs across the league are giving us a better picture of what their Spring Training rosters might look like. Everyone is off trying to find the 2014 version of Chris Davis or Jean Segura, but I’d like to suggest we take a break from that for a moment. Instead, let’s focus on something more sinister (MUHAHAHA!): who will be the biggest bust of 2014?

In a Fangraphs article last year, Bill Petti laid out a novel framework for predicting player collapses based on a few metrics. I won’t repeat his research here, but I encourage you to check out that article. I’ve decided to focus on one indicator he targets: Z-Contact%. This is the percentage of pitches in the strike zone that a hitter makes contact on when swinging. A decline here could indicate that a hitter is losing bat speed, which could cause a drop in AVG among other things.

Large Z-Contact% decliners 2012-2013: