Skip to content

Instantly share code, notes, and snippets.

View nicmarti's full-sized avatar

Nicolas Martignole nicmarti

View GitHub Profile
@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 :

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 / 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();
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 / 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#")) {
@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: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=(