Skip to content

Instantly share code, notes, and snippets.

View alexanderjarvis's full-sized avatar

Alexander Jarvis alexanderjarvis

View GitHub Profile
package security
import scala.concurrent._
object AccessToken {
/**
* The "b64token" syntax allows the 66 unreserved URI characters
* ([RFC3986]), plus a few others, so that it can hold a base64,
* base64url (URL and filename safe alphabet), base32, or base16 (hex)
package mojolly.io
import org.jboss.netty.bootstrap.ClientBootstrap
import org.jboss.netty.channel._
import socket.nio.NioClientSocketChannelFactory
import java.util.concurrent.Executors
import org.jboss.netty.handler.codec.http._
import collection.JavaConversions._
import websocketx._
import java.net.{InetSocketAddress, URI}
package daos
import scala.concurrent.ExecutionContext
import scala.concurrent.Future
import play.api.Play.current
import play.modules.reactivemongo._
import reactivemongo.api._
import reactivemongo.api.indexes._
import reactivemongo.bson._
import reactivemongo.bson.handlers.BSONReader
@alexanderjarvis
alexanderjarvis / Tuple2Format.scala
Created January 22, 2013 15:05
Allow case classes with Tuple2 types to be represented as a Json Array with 2 elements e.g. (Double, Double)
import play.api.libs.json._
import play.api.libs.functional.syntax._
import play.api.data.validation._
implicit def tuple2Reads[A, B](implicit aReads: Reads[A], bReads: Reads[B]): Reads[Tuple2[A, B]] = Reads[Tuple2[A, B]] {
case JsArray(arr) if arr.size == 2 => for {
a <- aReads.reads(arr(0))
b <- bReads.reads(arr(1))
} yield (a, b)
case _ => JsError(Seq(JsPath() -> Seq(ValidationError("Expected array of two elements"))))