Skip to content

Instantly share code, notes, and snippets.

View nicmarti's full-sized avatar

Nicolas Martignole nicmarti

View GitHub Profile
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Association du Paris Java User Group.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
@nicmarti
nicmarti / SecureCFP Controller
Created May 10, 2014 12:39
SecureCFPController Play 2.2 Scala secure controller used for Devoxx CFP
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Association du Paris Java User Group.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
@nicmarti
nicmarti / JournauxRepository.scala
Created May 26, 2014 23:30
Slick 2.x left join
object JournauxRepository {
def allWithOperateurs():Seq[(Journal, Operateur, Option[String])] = {
DB.withSession {
implicit s =>
val result = for {
((journal, operateur), intervenant) <- Journaux leftJoin Operateurs on(_.idOperateur === _.id) leftJoin Intervenants on(_._1.idIntervenant === _.idAgence)
} yield (journal,operateur,intervenant.nom.?)
result.run
}
}
@nicmarti
nicmarti / selection.scala
Last active August 29, 2015 14:07
Sample scala test
package roger
import org.scalatest.{FlatSpec, ShouldMatchers}
import roger.AggregationOperation.AggregationOperation
case class Metric(id: String, aggregationOperation: AggregationOperation)
case class Dimension(id: String)
object AggregationOperation extends Enumeration {
@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 *)