This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case class Person(firstName: String, lastName: String) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait Constructable[T] { | |
def construct: T | |
} | |
implicit object IntIsConstructable extends Constructable[Int] { | |
def construct = 42 | |
} | |
implicit object StringIsConstructable extends Constructable[String] { | |
def construct = "Hello World" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//My take on: http://solog.co/47/10-scala-one-liners-to-impress-your-friends/ | |
//1. Multiple Each Item in a List by 2 | |
//(1 to 10) map { _ * 2 } | |
(1 to 10) map (2*) | |
//2. Sum a List of Numbers | |
//(1 to 1000).reduceLeft( _ + _ ) | |
(1 to 1000).sum |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def flatTraverse[T](node: Node)(pfn: PartialFunction[Node, TraversableOnce[T]]): Seq[T] = { | |
traverse(node)(pfn).flatten | |
} | |
def traverse[T](node: Node)(pfn: PartialFunction[Node, T]): Seq[T] = { | |
def inner(n: Node, acc: List[T]): List[T] = n match { | |
case x if (pfn isDefinedAt x) => pfn(x) :: acc | |
case e: Elem => (e.child.toList map {inner(_, Nil)}).flatten ::: acc | |
case _ => acc | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Filters[T] { | |
//Some boilerplate-busting aliases | |
type FilterResult = Either[Rejection, T] | |
type FilterFunc = (T) => FilterResult | |
//Handy helpers | |
//Rejection can carry as much info as you wish; | |
// Filter name, value in error, an exception, etc. | |
case class Rejection(input: T, msg: String) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
lazy val engine: TemplateEngine = { | |
val ctx = CaptureContext.context.get | |
val srcDirectories = ctx.getRealPath("/") match { | |
case path: String => List(new File(path)) | |
case null => List() | |
} | |
println("Scalate got src directories " + srcDirectories) | |
new TemplateEngine(srcDirectories) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def + + [B>: A, That] (that: TraversableOnce [B]) (implicit bf: CanBuildFrom [List [A], B, That]): That |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.zeebox.starwatch | |
import javax.servlet.{ServletContextEvent, ServletContextListener} | |
import java.net.InetAddress | |
import akka.actor.ActorSystem | |
import cc.spray.SprayServletSettings | |
import akka.config.ConfigurationException | |
import akka.util.{Reflect, Switch} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.zeebox.starwatch | |
import akka.actor.ActorSystem | |
import akka.util.Reflect | |
import java.net.InetAddress | |
import com.typesafe.config.ConfigFactory | |
import org.slf4j.LoggerFactory | |
object ActorSystemFactory { | |
val log = LoggerFactory.getLogger(this.getClass) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case class ZeeingEvent( | |
zid: String, | |
kind: String, | |
showId: String, | |
show_name: Option[String], | |
time: DateTime | |
) { | |
require (kind == "StartedZeeing" || kind == "EndedZeeing") | |
} |
OlderNewer