Skip to content

Instantly share code, notes, and snippets.

View jonifreeman's full-sized avatar

Joni Freeman jonifreeman

View GitHub Profile
case class Book(title: String, date: Date, author: String)
val someDate = new Date
/* Would be nice to return String, PreparedStmt or something instead of Dynamic
val books: Dynamic[String] = Book
val q1 = books.findByTitle("The Stand")
val q2 = books.findByTitleLike("Harry Pot%")
val q3 = books.findByDateGreaterThan(someDate)
*/
case class Book(title: String, date: Date, author: String)
val someDate = new Date
/* Would be nice to return String, PreparedStmt or something instead of Dynamic
val books: Dynamic[String] = Book
val q1 = books.findByTitle("The Stand") // q1, q2 and q3 are Strings
val q2 = books.findByTitleLike("Harry Pot%")
val q3 = books.findByDateGreaterThan(someDate)
*/
@jonifreeman
jonifreeman / gist:1097071
Created July 21, 2011 12:16
Elvis loves Options
implicit def elvisSyntax[A](o: Option[A]) = new {
def ?[B](f: A => Option[B]) = o flatMap f
def :?[B](f: A => B) = o map f
def ??(default: => A) = o getOrElse default
}
case class Head(name: String)
case class Department(head: Option[Head])
case class Employee(department: Option[Department])
@jonifreeman
jonifreeman / gist:1151994
Created August 17, 2011 16:50
JsonDSL vs. JsonAST
("lotto" ->
("lotto-id" -> lotto.id) ~
("winning-numbers" -> lotto.winningNumbers) ~
("winners" ->
lotto.winners.map { w =>
(("winner-id" -> w.id) ~
("numbers" -> w.numbers))}))
// vs.
@jonifreeman
jonifreeman / gist:1306258
Created October 22, 2011 17:35
Port of submit.m Octave functionality to Haskell
import System.IO
import Control.Exception
import Numeric.LinearAlgebra
import Data.Digest.Pure.SHA
import Data.ByteString.Lazy.Char8 as BS8 (pack)
import Data.List (sort)
import System.Random (randomRIO)
import Network.Curl
import Text.Printf (printf)
import Data.List.Split (splitOn)
@jonifreeman
jonifreeman / gist:1308709
Created October 24, 2011 10:05
Function to submit mlclass week 2 excercises
-- LinExtras.hs, some hmtarx helpers
module LinExtras where
import Numeric.LinearAlgebra
import Foreign.Storable (Storable)
vector xs = fromList xs :: Vector Double
-- Each entry is a column.
@jonifreeman
jonifreeman / gist:1308712
Created October 24, 2011 10:06
Function to submit mlclass week 2 excercises
-- LinExtras.hs, some hmtarx helpers
module LinExtras where
import Numeric.LinearAlgebra
import Foreign.Storable (Storable)
vector xs = fromList xs :: Vector Double
-- Each entry is a column.
@jonifreeman
jonifreeman / gist:1324216
Created October 29, 2011 07:52
Function to submit mlclass week 3 excercises
-- LinExtras.hs
module LinExtras where
import Numeric.LinearAlgebra
import Foreign.Storable (Storable)
vector xs = fromList xs :: Vector Double
size :: (Num b) => Vector Double -> b
@jonifreeman
jonifreeman / scalatoprolog.md
Created January 30, 2012 09:16
Scala type system -> Prolog
@jonifreeman
jonifreeman / gist:2321316
Created April 6, 2012 16:58
State monad in Roy
data State_t a s = State a s
let unit = {}
let stateMonad = {
return: \x -> \s -> State x s
bind: \sm f -> \s0 -> match (sm s0)
case (State x s) = (f x) s
}