Using JSON in Postgres by example.
- Download and install: Docker Toolbox
- Open Docker Quickstart Terminal
- Start a new postgres container:
docker run --name my-postgres -e POSTGRES_PASSWORD=mysecretpassword -d postgres
Using JSON in Postgres by example.
docker run --name my-postgres -e POSTGRES_PASSWORD=mysecretpassword -d postgres
package globals | |
import java.io.PrintStream | |
import play.api.Logger | |
object StdOutErrLogger { | |
val logger = Logger(this.getClass) | |
def redirectSystemOutAndErrToLog() = { |
import scala.concurrent.Future | |
object either { | |
// Scala standard library Either is sometimes used to distinguish between 'failure' and 'success' state. Like these two methods: | |
def getUser(id: String): Either[String, User] = ??? | |
def getPreferences(user: User): Either[String, Preferences] = ??? | |
// The Right side contains the success value by convention, because right is right, right? |
#!/usr/bin/env bash | |
# Use this one-liner to produce a JSON literal from the Git log: | |
git log \ | |
--pretty=format:'{%n "commit": "%H",%n "author": "%an <%ae>",%n "date": "%ad",%n "message": "%f"%n},' \ | |
$@ | \ | |
perl -pe 'BEGIN{print "["}; END{print "]\n"}' | \ | |
perl -pe 's/},]/}]/' |
// see http://www.michaelpollmeier.com/execute-scala-futures-in-serial-one-after-the-other-non-blocking/ | |
def serialiseFutures[A, B](l: Iterable[A])(fn: A ⇒ Future[B]) | |
(implicit ec: ExecutionContext): Future[List[B]] = | |
l.foldLeft(Future(List.empty[B])) { | |
(previousFuture, next) ⇒ | |
for { | |
previousResults ← previousFuture | |
next ← fn(next) | |
} yield previousResults :+ next | |
} |
import org.scalatest.prop.PropertyChecks._ | |
import org.scalatest.prop.Tables.Table | |
import org.scalatest.WordSpec | |
class MyTableBasedPropertySpec extends WordSpec { | |
val $testData$ = Table( | |
("$p1$", "$p2$", "$p3$"), | |
("1", 2, 3.0), | |
("4",5,6.0) | |
) | |
import org.scalatest.prop.PropertyChecks._ | |
import org.scalatest.prop.Tables.Table | |
import org.scalatest.WordSpec | |
class MyTableBasedPropertySpec extends WordSpec { | |
val testData = Table( | |
("p1", "p2", "p3"), | |
("1", 2, 3.0), | |
("4",5,6.0) | |
) |
Prereq:
apt-get install zsh
apt-get install git-core
Getting zsh to work in ubuntu is weird, since sh
does not understand the source
command. So, you do this to install zsh
wget https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - | zsh
package enumtest | |
import play.api.libs.json._ | |
object EnumUtils { | |
def enumReads[E <: Enumeration](enum: E): Reads[E#Value] = new Reads[E#Value] { | |
def reads(json: JsValue): JsResult[E#Value] = json match { | |
case JsString(s) => { | |
try { | |
JsSuccess(enum.withName(s)) |
#!/usr/bin/env scalas | |
/*** | |
scalaVersion := "2.11.7" | |
libraryDependencies += "com.typesafe.play" %% "play-netty-server" % "2.4.1" | |
*/ | |
import play.core.server._ | |
import play.api.routing.sird._ | |
import play.api.mvc._ |