Skip to content

Instantly share code, notes, and snippets.

object Account
object Clob {
def unapply(clob: Clob): Option[String] = Some(clob.getSubString(1, clob.length.toInt))
}
implicit val rowToPermission: Column[Permission] = {
Column.nonNull[Permission] { (value, meta) =>
value match {
case Clob("Administrator") => Right(Administrator)
sealed trait Permission
case object Administrator extends Permission
case object NormalUser extends Permission
def testMappedType {
sealed trait Bool
case object True extends Bool
case object False extends Bool
implicit val boolTypeMapper = MappedColumnType.base[Bool, Int](
{ b =>
assertNotNull(b)
if(b == True) 1 else 0
}, { i =>
implicit val permissionTypeMapper = MappedTypeMapper.base[Permission, String](
p => p match {
case Administrator => "Administrator"
case NormalUser => "NormalUser"
},
s => s match {
case "Administrator" => Administrator
case "NormalUser" => NormalUser
}
)
def index = MaybeAuthenticated { implicit userOrLogin => implicit request =>
val frontpageItems = Item.frontpage
Ok(views.html.index("Your new application is ready.")(frontpageItems))
}
@ryantanner
ryantanner / AnormBatchInsert.scala
Created March 20, 2013 01:38
Anorm batch insert demo
def saveList(list: List[Long]) = {
DB.withConnection { implicit connection =>
val insertQuery = SQL("insert into UserActions(action) values ({action})")
val batchInsert = (insertQuery.asBatch /: list)(
(sql, elem) => sql.addBatchParams(elem)
)
batchInsert.execute()
}
}
// pass in the role name of the service being tested
object BackendConfig extends MultiNodeConfig {
// register the named roles (nodes) of the test
val supervisor = role("supervisor")
val analytics = role("analytics")
val imap = role("imap")
val mailer = role("mailer")
val nodeConfig: Config = ConfigFactory.parseString(s"""
akka.actor.provider = "akka.cluster.ClusterActorRefProvider"
// pass in the role name of the service being tested
object MultiSpecConfig extends MultiNodeConfig {
// register the named roles (nodes) of the test
val supervisor = role("supervisor")
val service1 = role("service1")
val service2 = role("service2")
val nodeConfig: Config = ConfigFactory.parseString(s"""
akka.actor.provider = "akka.cluster.ClusterActorRefProvider"
akka.remote.log-remote-lifecycle-events = off
import sbt._
import sbt.Keys._
import PlayProject._
import akka.sbt.AkkaKernelPlugin
import akka.sbt.AkkaKernelPlugin.{ Dist, outputDirectory, distJvmOptions, configSourceDirs, distMainClass }
import com.typesafe.sbt.SbtMultiJvm
import com.typesafe.sbt.SbtMultiJvm.MultiJvmKeys._
import sbtassembly.Plugin._
import AssemblyKeys._
import twirl.sbt.TwirlPlugin._
// Play controller
def source(flightIdent: String) = Action {
Async {
for {
flight <- Flight.findByIdent(flightIdent)
source <- (eventSource ? Track(flight))
} yield source match { case Connected(stream) =>
Ok.feed((stream &> EventSource[JsValue]()(