Skip to content

Instantly share code, notes, and snippets.

View nicmarti's full-sized avatar

Nicolas Martignole nicmarti

View GitHub Profile
@nicmarti
nicmarti / gist:1140203
Created August 11, 2011 17:11
Loading an image from the database with play! scala
/**
* Loads the specified documentInstance, the current authenticated user is retrieved
* to check that it's the document owner.
* Play! Framework with latest Scala module.
* Nicolas Martignole - 09/08/2011
*/
def loadImage(di:Option[Long]) = {
import play.utils.Scala.MayErr._
val result=(
@nicmarti
nicmarti / demo.scala
Created October 15, 2011 20:52
Yes I am proud to be able to write this kind of Code
@(contacts:List[(Long,String,String)])
<html>
<head>
<title>ZenContact - Play! 2 Sample application</title>
<link rel="shortcut icon" type="image/png" href="http://www.playframework.org/public/images/favicon.png">
<link rel="stylesheet" type="text/css" media="screen" href="@routes.Assets.at("stylesheets/main.css")">
<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Varela+Round|Droid+Sans">
</head>
<body>
@nicmarti
nicmarti / gist:1376491
Created November 18, 2011 13:42
Play 2.0 generate a list from A to Z and group by last name
@(contacts:List[(models.Contact)])
<html>
<head>
<title>Contact - Play! 2 Sample application</title>
</head>
<body>
Number of contacts in the database: @contacts.length<br/>
@for(letter<-("ABCDEFGHIJKLMNOPQRSTUVWXYZ#")) {
val urlBase = "http://localhost:8080"
val httpConf = httpConfig.baseURL(urlBase)
val headers_1 = Map(
"Accept" -> """text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8""",
"Accept-Charset" -> """ISO-8859-1,utf-8;q=0.7,*;q=0.3""",
"Accept-Encoding" -> """gzip,deflate,sdch""",
"Accept-Language" -> """fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4""",
@nicmarti
nicmarti / DemoPlayground
Created February 1, 2012 16:10
Playground controller Play 1.x
package controllers;
import models.JobPost;
import play.mvc.Controller;
import java.util.List;
public class DemoPlayground extends Controller {
public static void index(){
List<JobPost> jobs=JobPost.find15Latest();
def getJobsSinceWithPattern(someday: DateTime, msgPattern: String): List[Log] = DB.withConnection{
implicit c=>
val sql = SQL("""|SELECT log_date, category, level, message, error, source FROM logs
|WHERE log_date >={day}
|AND message like {msg}
""".stripMargin)
.on("day" -> someday.toString("yyyy-MM-dd")).on("msg" -> msgPattern)
val listParsed=sql.as(date("log_date") ~ str("category") ~ str("level") ~ str("message") ~ get[Option[String]]("error") ~ str("source") map flatten *)
@nicmarti
nicmarti / gist:3134698
Created July 18, 2012 06:58 — forked from sadache/gist:3026886
Bits'bout Play2 Architecture

Quelques bouts d'architecture de Play2

Play2 Simple HTTP API

Le coeur de l'architecture de Play2 est plutôt simple et reste facile à expliquer dans un article court de blog. Vous pouvez découvrir petit à petit le framework à différents niveaux, et à chaque fois découvrir un peu plus sur certains aspects de son design.

Le coeur de Play2 est vraiment très simple et petit, il est complété par un ensemble d'APIs pratiques, de services et permet de faciliter le développement Web.

De manière simple, Play2 est une API qui abstrait le type suivant :

@nicmarti
nicmarti / play2_enumeratee_enumerator
Created August 5, 2012 14:02
Play2 stream with live scrapping
package models
import play.libs.WS
import play.api.libs.json.JsValue
import play.api.libs.json.Json._
import scala.Some
import play.api.libs.EventSource
import org.apache.commons.lang.StringUtils
// Define a generic event,
@nicmarti
nicmarti / OriginSpecs.scala
Created March 1, 2013 11:25
Play2 and Spec simple test - Demo for Confoo
package models
import org.specs2.mutable._
import play.api.test._
import play.api.test.Helpers._
class OriginSpecs extends Specification {
"An Origin" should {
"returns the slug for a valid origin" in {
@nicmarti
nicmarti / Origin.scala
Created March 1, 2013 11:27
Play2 and Redis simple demo - How to load an Origin from a Redis data store with a for-comprehension
def getOrigin(originId: Long): Option[Origin] = Redis.pool.withClient {
client =>
for(slug<-Option(client.hget("Url:From:Rev", originId.toString));
display<-Option(client.hget("Places:Place:"+originId, "display")
)) yield Origin(originId,display,slug)
}
}