Skip to content

Instantly share code, notes, and snippets.

View crocker's full-sized avatar

Jason Crocker crocker

  • Clinetic
  • Raleigh, NC
View GitHub Profile
@crocker
crocker / forest.scala
Last active August 17, 2016 13:50
Scala multi-root tree or forest
package com.signalpath.model
import scala.collection.mutable
class Forest[A]()(ordering: Ordering[A]) {
val tree = new mutable.LinkedHashMap[Option[A], mutable.ListBuffer[A]]()
def addNode(parent: Option[A], node: A): Unit = {
val children = tree.get(parent).map(_ += node).getOrElse(mutable.ListBuffer[A](node))
tree.put(parent,children.sorted(ordering))
@crocker
crocker / guicenamed.scala
Created May 18, 2016 03:55
Named Guice dependencies in Scala
val elastic = injector.getInstance[ElasticClient](
Key.get(classOf[ElasticClient],
Names.named("elastic"))
)
@crocker
crocker / jsonview.scala
Last active May 18, 2016 03:51
@JSONVIEW with Scala Object Mapper
// define your json views
object MyViews {
class ViewA {}
class ViewB {}
class ViewC {}
}
// configure your object mapper
val mapper = new ObjectMapper with ScalaObjectMapper
mapper.registerModule(DefaultScalaModule)