Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View andypetrella's full-sized avatar

Andy Petrella andypetrella

View GitHub Profile
@andypetrella
andypetrella / Build.scala
Created February 6, 2012 23:40
Play20 RC1 : sbt-idea
import sbt._
import Keys._
import PlayProject._
object ApplicationBuild extends Build {
val appName = "playbasket"
val appVersion = "1.0"
val sbtIdeaRepo = "sbt-idea-repo" at "http://mpeltonen.github.com/maven/"
@andypetrella
andypetrella / json
Created February 19, 2012 21:06
Test Play REPL
scala> val o:JsObject = JsObject(Seq("a" -> JsNumber(1), "2" -> JsString("two")))
o: play.api.libs.json.JsObject = {"a":1.0,"2":"two"}
scala> o \ "a" //return the value as a JsValue
res26: play.api.libs.json.JsValue = 1.0
scala> val o2:JsObject = JsObject(Seq("a" -> JsNumber(1), "2" -> JsObject(Seq("deep" -> JsBoolean(true)))))
o2: play.api.libs.json.JsObject = {"a":1.0,"2":{"deep":true}}
scala> o \\ "a" // find at first level and return in a list
@andypetrella
andypetrella / Format.scala
Created February 19, 2012 21:16
Play Json
trait Format[T] extends Writes[T] with Reads[T]
/**
* Default Json formatters.
*/
object Format extends DefaultFormat
url(urlString)
>\ "ISO-8859-1" //set the charset
<:< (Map("Accept-Language" -> "fr-BE" )) //set some headers
gzip //encode the response in archived gzip is accepted
@andypetrella
andypetrella / Build.scala
Created February 20, 2012 22:47
Neo4J using Play and Dispatch
import sbt._
import Keys._
import PlayProject._
object ApplicationBuild extends Build {
val appName = "Play20WithNeo4J"
val appVersion = "1.0"
val sbtIdeaRepo = "sbt-idea-repo" at "http://mpeltonen.github.com/maven/"
@andypetrella
andypetrella / GraphService.scala
Created February 24, 2012 21:40
Neo4J Play and DAO
//A trait defining some high level operation on graph, hasn't been cleaned but illustrates well what it might be meant for
trait GraphService[Node] {
//entry point of the graph
def root: Node
//get a Node based on its id
def getNode[T <: Node](id: Int): Option[T]
//return all nodes in the graph as a list
@andypetrella
andypetrella / Groups.scala
Created February 27, 2012 21:36
Create Views in Play 2.0 for Neo4J
object Groups extends Controller {
// create a new Group based on its given name
def create = Action {
implicit request => {
//a form that will create a Group based on the request body. See how apply and unapply functions are given after the mapping definition
Form[Group](
mapping(
"name" -> nonEmptyText
)(
(name: String) => Group(null.asInstanceOf[Int], name)
@andypetrella
andypetrella / Neo4JRestService.scala
Created February 29, 2012 21:17
Deploy Play and Neo4J on Heroku
//PREVIOUSLY ::>> val neoRest = :/("localhost", 7474)
//NOW use `as`
val neoRest = :/(NEO4J_URL, NEO4J_PORT) as (NEO4J_USERNAME, NEO4J_PASSWORD)
val neoRestBase = neoRest / "db" / "data"
val neoRestNode = neoRestBase / "node"
val neoRestRel = neoRestBase / "relationship"
val neoRestCypher = neoRestBase / "cypher"
def selfRestUriToId(uri: String) = uri.substring(uri.lastIndexOf('/') + 1).toInt
@andypetrella
andypetrella / Build.scala
Created March 11, 2012 11:47
Salat and Play 2.0
//...
val novusSnapsRepo = "Novus Snapshots Repository" at "http://repo.novus.com/snapshots/"
val salatCore = "com.novus" %% "salat-core" % "0.0.8-SNAPSHOT" withSources
val salatUtil = "com.novus" %% "salat-util" % "0.0.8-SNAPSHOT" withSources
val appDependencies = Seq(
// Add your project dependencies here,
salatCore,
salatUtil
@andypetrella
andypetrella / Build.scala
Created March 14, 2012 21:57
Gatling Within Play 2.0
import sbt._
import Keys._
import PlayProject._
object ApplicationBuild extends Build {
val appName = "gatling-play2-plugin"
val appVersion = "1.0"
/* OFFICIAL GATLING REPO */