Skip to content

Instantly share code, notes, and snippets.

View jonifreeman's full-sized avatar

Joni Freeman jonifreeman

View GitHub Profile
example.dot:
graph graphname {
a -> b -> c;
b -> d;
}
$ graph-easy example.dot example.txt
$ cat example.txt
+---+
object Sql {
import scala.reflect.makro._
import language.experimental.macros
case class Query[R](/*sql: String*/)
def execute[R](q: Query[R]): Seq[R] = sys.error("implement me")
def sqlImpl(c: Context)(s: c.Expr[String]): c.Expr[Any] = {
import c.universe._
@jonifreeman
jonifreeman / gist:3667222
Created September 7, 2012 15:35
Kiama rewrite
scala> import org.kiama.rewriting.Rewriter._
import org.kiama.rewriting.Rewriter._
scala> trait Expr
defined trait Expr
scala> case class Constant(x: Int) extends Expr
defined class Constant
scala> case class Add(e1: Expr, e2: Expr) extends Expr
@jonifreeman
jonifreeman / gist:5402450
Created April 17, 2013 07:37
Do-notation for Fantasy Land
/*
$do {
x <- foo
y <- bar
z <- baz
return x * y * z
}
Desugars into:
@jonifreeman
jonifreeman / gist:5404963
Created April 17, 2013 14:55
Negroni in do-notation
assemble = function(g, v, a) {
return $do {
gin <- g
vermouth <- v
amaro <- a
return new Negroni(gin, vermouth, amaro)
}
}
// Compilation time of each commented function on my machine (as repoted by sbt console).
// **********************************************************************
// Test.scala
import shapeless._
import syntax.singleton._
object Test {
val r =
("k01" ->> 1) :: ("k02" ->> 1) :: ("k03" ->> 1) :: ("k04" ->> 1) :: ("k05" ->> 1) ::
@jonifreeman
jonifreeman / gist:6550469
Created September 13, 2013 13:09
Record compilation performance
// Compilation time of each commented function on my machine (as repoted by sbt console).
// **********************************************************************
// Test.scala
import shapeless._
import syntax.singleton._
object Test {
val r =
("k01" ->> 1) :: ("k02" ->> 1) :: ("k03" ->> 1) :: ("k04" ->> 1) :: ("k05" ->> 1) ::
@jonifreeman
jonifreeman / gist:6550962
Created September 13, 2013 13:48
Records with objects as keys
// Test3.scala
import shapeless._
import syntax.singleton._
object Test3 {
val r =
(k01 ->> 1) :: (k02 ->> 1) :: (k03 ->> 1) :: (k04 ->> 1) :: (k05 ->> 1) ::
(k06 ->> 1) :: (k07 ->> 1) :: (k08 ->> 1) :: (k09 ->> 1) :: (k10 ->> 1) ::
(k11 ->> 1) :: (k12 ->> 1) :: (k13 ->> 1) :: (k14 ->> 1) :: (k15 ->> 1) ::
(k16 ->> 1) :: (k17 ->> 1) :: (k18 ->> 1) :: (k19 ->> 1) :: (k20 ->> 1) ::
@jonifreeman
jonifreeman / gist:6552821
Last active December 23, 2015 00:19
type FieldType[K, V] = (K, V)
// Singleton types as keys
r get "k01" // 1s was 1s
r get "k02" // 3s was 4s
r get "k03" // 5s was 7s
r get "k04" // 6s was 10s
r get "k05" // 7s was 12s
r get "k10" // 12s was 21s
r get "k20" // 16s was 30s
// Objects as keys
@jonifreeman
jonifreeman / gist:6570276
Created September 15, 2013 12:13
Explicit type for a Shapeless record, version: type FieldType[K, V] = (K, V)
// See https://gist.github.com/jonifreeman/6533463
object TestExplicitRecordType {
import shapeless._, record._, syntax.singleton._
object testF extends Poly1 {
implicit def atFieldType[K, V] = at[(K, V)] {
case (k, v) => k.toString
}
}