Skip to content

Instantly share code, notes, and snippets.

@AlecZorab
AlecZorab / 1. Shapeless.scala
Last active June 7, 2016 19:54
Deep Modification Magic
import shapeless._
val smoothTrades: Map[String, K2OverHttp.Trade] = {
object continuous extends poly.->((p: OISCompoundingPeriodCommon) => (p match {
case c: OISCompoundingPeriod => c.copy(roundingDecimal = None)
case c: OISAveragingPeriod => c.copy(roundingDecimal = None)
case c: OISAveragingExtPeriod => c.copy(roundingDecimal = None)
case c: OISAveragingCustomSchedulePeriod => c.copy(roundingDecimal = None)
case c: OISSpreadCompoundingPeriod => c.copy(roundingDecimal = None)
case c: OISStraightCompoundingPeriod => c.copy(roundingDecimal = None)
@AlecZorab
AlecZorab / build.sbt
Created June 3, 2016 13:52
Coursier kills console!
scalaVersion in ThisBuild := "2.11.8"
Welcome to Scala version 2.11.7 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_66).
Type in expressions to have them evaluated.
Type :help for more information.
scala> import shapeless._ ; import syntax.singleton._ ; import record._
import shapeless._
import syntax.singleton._
import record._
scala> import prelude._
2015-09-28 11:19:37,233 - [INFO] - from play in main
Application started (Prod)
2015-09-28 11:19:37,354 - [INFO] - from play in main
Listening for HTTP on /0:0:0:0:0:0:0:0:9000
2015-09-28 11:21:48,072 - [DEBUG] - from application in New I/O worker #1
Notebooks directory in the config is referring ./notebooks. Does it exist? true
2015-09-28 11:21:48,091 - [INFO] - from application in New I/O worker #1
@AlecZorab
AlecZorab / 1 - Under 2.3.0
Last active August 29, 2015 14:27
The cause of my monstrous compile times
Compiled from "ScaJSON.scala"
public final class art.examples.ScaJSON$$anonfun$14$hcons$macro$337$1 implements scala.Serializable {
public shapeless.PolyDefns$Case<art.model.risk.FrmPart2$Frmp2Pre$, shapeless.$colon$colon<art.world.W, shapeless.$colon$colon<scala.collection.immutable.List<art.trade.fra.FRA>, shapeless.HNil>>> inst$macro$331();
public shapeless.PolyDefns$Case<art.model.risk.FrmPart2$Frmp2Pre$, shapeless.$colon$colon<art.world.W, shapeless.$colon$colon<scala.collection.immutable.List<art.trade.swap.Swap>, shapeless.HNil>>> inst$macro$334();
public shapeless.PolyDefns$Case<art.model.risk.FrmPart2$Frmp2Pre$, shapeless.$colon$colon<art.world.W, shapeless.$colon$colon<shapeless.HNil, shapeless.HNil>>> inst$macro$336();
public shapeless.PolyDefns$Case<art.model.risk.FrmPart2$Frmp2Pre$, shapeless.$colon$colon<art.world.W, shapeless.$colon$colon<shapeless.$colon$colon<scala.collection.immutable.List<art.trade.swap.Swap>, shapeless.HNil>, shapeless.HNil>>> inst$macro$333();
public shapeless.P
@AlecZorab
AlecZorab / Timings.md
Last active August 29, 2015 14:27
Compilation Timings for shapeless

Gathered by doing repeated ";clean;package;" calls, discarding the first after a change.

Project TC Ver Time(s)
All Lazy 2.2.5 130
131
129
All Lazy 2.3.0-SN 29
29
28
@AlecZorab
AlecZorab / gist:e9b4360c033bbdae75f9
Created May 12, 2015 11:42
Experiments in fastparse
object ParseGist extends App {
import fastparse._
val space = P(CharsWhile(" \n".contains(_)).?)
val digits = P(CharsWhile('0' to '9' contains _))
val exponent = P(CharIn("eE") ~ CharIn("+-").? ~ digits)
val fractional = P("." ~ digits)
val integral = P("0" | CharIn('1' to '9') ~ digits.?)
class MapBool[K, V](implicit ev: Bool[V]) extends Bool[Map[K, V]] with Serializable {
def one = Map.empty[K, V].withDefaultValue(ev.one)
def or(a: Map[K, V], b: Map[K, V]) = {
val ad = a.withDefaultValue(ev.zero)
val bd = b.withDefaultValue(ev.zero)
(a.keySet ++ b.keySet).map(k => k -> ev.or(ad(k), bd(k))).toMap
}
def complement(a: Map[K, V]) = a.mapValues(ev.complement)
def and(a: Map[K, V], b: Map[K, V]) =
@AlecZorab
AlecZorab / Java Output
Created July 2, 2013 08:01
JVM 1.7.21, -server -ms2g -mx2g -XX:+UseG1GC -XX:+AggressiveOpts Akka 2.2.0-RC2, SingleConsumerOnlyUnboundedMailbox, fork-join-executor, pmax = pmin = 2, throughput 1024
handled 1000000 messages in 68.917303ms
handled 1000000 messages in 51.064434ms
handled 1000000 messages in 77.18446ms
handled 1000000 messages in 79.364979ms
handled 1000000 messages in 72.436795ms
handled 1000000 messages in 79.938059ms
handled 1000000 messages in 76.635481ms
handled 1000000 messages in 82.522278ms
handled 1000000 messages in 76.44066ms
handled 1000000 messages in 69.09773ms
@AlecZorab
AlecZorab / ACaseClass.scala
Created August 28, 2012 23:06
Hacky attempt at representing Bra-Ket notation. Term simplification could be best described as "unstructured". (or appalling, your choice)
object BraKet3_SmokeyIsTheBraket extends App {
sealed trait Expr {
e1 =>
def *(e2: Expr): Expr = Prod(e1, e2)
def +(e2: Expr): Expr = Sum(e1, e2)
def simplify: Expr = this