Skip to content

Instantly share code, notes, and snippets.

@newjam
newjam / ConstructorResultSetMapperFactory.java
Created September 28, 2015 01:45
Get free jdbi ResultSetMapper if your class has a constructor from a ResultSet
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Optional;
import lombok.extern.slf4j.Slf4j;
import org.skife.jdbi.v2.ResultSetMapperFactory;
import org.skife.jdbi.v2.StatementContext;
import org.skife.jdbi.v2.tweak.ResultSetMapper;
@newjam
newjam / Number Puzzle
Created March 20, 2014 05:00
Find a simple arithmetic expression that evaluates to 24 using the numbers 1, 3, 4, 6 exactly once.
import Data.Ratio
import qualified Data.Set as S
data Op = Add | Sub | Mul | Div
deriving Eq
data Exp a = Bin Op (Exp a) (Exp a)
| Num a
deriving Eq
instance Show Op where
{-
Income quintiles in 2011. This represents the poorest fifth to the richest fifth
of income earners in america in 2001.
-}
income2011 = [15282.0, 37556.0, 61032.0, 93232.0, 197932.0]
{-
Find the average income of americans, by averaging the quintiles.