View MultipartParsing.scala
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
pathEndOrSingleSlash { | |
(post & parameter("rev")) { rev => | |
// This is very important, so we can provide a more specific | |
// implicit to overcome the Json4sSupport default unmarshaller | |
// that will require an `application/json` ContentType! | |
import Unmarshaller._ | |
entity(as[Multipart.General]) { body => | |
import scala.concurrent.duration._ |
View for-blahbrehensions.scala
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
// fold | |
client ! Projects(rows.headOption.fold(Nil)(_ \ "value" extract)) | |
// map.getOrElse | |
client ! Projects(rows.headOption | |
.map(_ \ "value" extract) | |
.getOrElse(Nil)) | |
// Option.toList | |
client ! Projects(rows.headOption.toList.map(_ \ "value" extract)) |
View build.sbt
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
// Don't include private.conf in main package. | |
mappings in (Compile, packageBin) ~= { | |
_ filter { | |
case (_, "private.conf") => false | |
case _ => true | |
} | |
} | |
// Don't include private.conf in main sources package. | |
mappings in (Compile, packageSrc) ~= { |
View IdSerializer.scala
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
import org.json4s._ | |
case object IdSerializer extends CustomSerializer[Id](formats => ( { | |
case JObject(JField("prefix", JString(prefix)) :: JField("id", JString(id)) :: JField("rev", JString(rev)) :: Nil) => IdWithRev(prefix, id, rev) | |
case JObject(JField("prefix", JString(prefix)) :: JField("id", JString(id)) :: Nil) => NewId(prefix, id) | |
}, { | |
case NewId(prefix, id) => JObject(JField("prefix", JString(prefix)) :: JField("id", JString(id)) :: Nil) | |
case IdWithRev(prefix, id, rev) => JObject(JField("prefix", JString(prefix)) :: JField("id", JString(id)) :: JField("rev", JString(rev)) :: Nil) | |
} | |
)) |
View 1_Password.scala
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
// This is just a basic sealed trait implementing a couple cases. | |
sealed trait Password { | |
val value: String | |
def hashed: HashedPassword | |
def check(plainTextCandidate: String): Boolean | |
} | |
case class PlainTextPassword(value: String) extends Password { | |
def hashed = HashedPassword.Scrypt(value) | |
def check(plainTextCandidate: String) = plainTextCandidate == value |
View FunctionZipping.scala
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
type FixtureFunction[T] = T => Any | |
implicit class FixtureFunctionZipper[A](f1: FixtureFunction[A] => Any) { | |
def zip[B](f2: FixtureFunction[B] => Any): ((A, B) => Any) => Any = { test => | |
f1(a => f2(b => test(a, b))) | |
} | |
def zip(f2: (Unit => Any) => Any): (A => Any) => Any = { test => | |
f1(a => f2(_ => test(a))) | |
} |
View ActorPerRequest.scala
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
// Just inlining the revelant bits of https://github.com/hseeberger/akka-http-json/blob/master/akka-http-json4s/src/main/scala/de/heikoseeberger/akkahttpjson4s/Json4sSupport.scala#L44 | |
// for the gist. | |
trait Json4sSupport { | |
implicit def json4sUnmarshallerConverter[A: Manifest](serialization: Serialization, formats: Formats): FromEntityUnmarshaller[A] = | |
json4sUnmarshaller(manifest, serialization, formats) | |
/** | |
* HTTP entity => `A` | |
* | |
* @tparam A type to decode |
View BrokenMacro.scala
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
// Example actor: | |
class EchoActor extends Actor { | |
def receive = { | |
case message => context.sender ! message | |
} | |
} | |
// I want to be able to write: | |
object EchoActor extends ActorGenerator0 |
View CompilationExample.scala
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 compile(): List[CompiledScript] = { | |
val outputCache = directory / ".cache" | |
if(!outputCache.exists()) outputCache.mkdirs() | |
val engine: IMain = new ScriptEngineManager().getEngineByName("scala").asInstanceOf[IMain] | |
engine.settings.usejavacp.value = true | |
// TODO: This breaks things. No idea why. | |
// engine.settings.outdir.value = outputCache.getCanonicalPath | |
directory.listFiles().toList collect { |
View ApplicationController.scala
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.wieck.base | |
package controllers | |
import play.api.{Application, Play, mvc, i18n}, mvc._, i18n._ | |
abstract class ApplicationController extends Controller { | |
private val messagesApiCache = Application.instanceCache[BaseMessagesApi] | |
implicit def messages(implicit lang: Lang): Messages = new Messages(lang, messagesApiCache(Play.current)) | |
NewerOlder