Skip to content

Instantly share code, notes, and snippets.

View mandubian's full-sized avatar

Pascal Voitot mandubian

View GitHub Profile
@mandubian
mandubian / 0. blabl.txt
Created January 25, 2013 14:44
PlayByExample: blabl
blabl
@mandubian
mandubian / 0. blabl.txt
Created January 25, 2013 14:47
PlayByExample: blabl
blabl
@mandubian
mandubian / 0. jolie question.txt
Created January 25, 2013 14:48
PlayByExample: jolie question
jolie question
val getLanguageFile = (__ \ "codeUrl").json.copyFrom(
(__ \ "files").json.pick[JsObject].map{ js =>
js.fields.collectFirst{ case (k, v) if(v \ "language" != JsNull) => v \ "raw_url" }.get
}
)
val getQuestionFile = (__ \ "questionUrl").json.copyFrom(
(__ \ "files").json.pick[JsObject].map{ js =>
js.fields.collectFirst{ case (k, v) if(v \ "language" == JsNull) => v \ "raw_url" }.get
}
@mandubian
mandubian / 0. labalbala.txt
Created January 25, 2013 16:31
PlayByExample: labalbala
labalbala
@mandubian
mandubian / 0. labalbala.txt
Created January 25, 2013 16:32
PlayByExample: labalbala
labalbala
@mandubian
mandubian / 0. coucou c'est une question.txt
Created January 25, 2013 16:32
PlayByExample: coucou c'est une question
coucou c'est une question
@mandubian
mandubian / 0. coucou c'est une question2.txt
Created January 25, 2013 16:33
PlayByExample: coucou c'est une question2
coucou c'est une question2
@mandubian
mandubian / gist:5012535
Created February 22, 2013 10:48
Play Json Reads expecting One single field
scala> import play.api.data.validation._
scala> ((__ \ "field1").readNullable[String] and (__ \ "field2").readNullable[Int]).tupled.filter(ValidationError("unexpected result")){ case( Some(x), None ) => true; case ( None, Some(x) ) => true; case _ => false }
res18: play.api.libs.json.Reads[(Option[String], Option[Int])] = play.api.libs.json.Reads$$anon$8@10654cd8
scala> Json.obj("field1" -> "toto").validate(res18)
res19: play.api.libs.json.JsResult[(Option[String], Option[Int])] = JsSuccess((Some(toto),None),)
scala> Json.obj("field2" -> 5).validate(res18)
res20: play.api.libs.json.JsResult[(Option[String], Option[Int])] = JsSuccess((None,Some(5)),)
Class Rectangle
val rectWrites = (
(__ \ 'width).write[Long] and
(__ \ 'height).write[Long] and
(__ \ 'x).write[Long] and
(__ \ 'y).write[Long]
)( (r: Rectangle) => (r.width, r.height, r.x, r.y) )