Skip to content

Instantly share code, notes, and snippets.

View guillaumebort's full-sized avatar

Guillaume Bort guillaumebort

View GitHub Profile
@guillaumebort
guillaumebort / Build.scala
Created December 14, 2012 15:20
Dynamically extracting SASS
val main = play.Project(appName, appVersion, appDependencies).settings(
resourceGenerators in Compile <+= (target, resourceManaged in Compile, cacheDirectory, streams) map { (target, resources, cache, streams) =>
val logger = streams.log
val sassWorkingDir = target / "sass-blabla"
if(!sassWorkingDir.exists) {
val maybeSass = this.getClass.getClassLoader.getParent.asInstanceOf[java.net.URLClassLoader].getURLs.map(_.getFile).map(file).find { file =>
@guillaumebort
guillaumebort / Build.scala
Created December 4, 2012 16:49
Latest Play 2.1 Nightly
.settings(
resolvers += "GB Play nightlies - Maven" at "http://guillaume.bort.fr/repository/"
)
@-webkit-keyframes coloredSpans
{
0% { background: #97e733; }
12% { background: #47ff74; }
25% { background: #3cf1f3; }
37% { background: #77cbfd; }
50% { background: #f19efd; }
62% { background: #fa87fd; }
75% { background: #fb9594; }
87% { background: #fdba3e; }
interface Person {
name: string;
}
var f = function(p: Person): number {
return p.name.length
}
var a = 'COCO'
var b = f({
@guillaumebort
guillaumebort / Procfile
Created June 22, 2012 16:04
Configuration for a blocking Play 2.0 application
web: target/start -Dhttp.port=${PORT} -Dconfig.resource=prod.conf ${JAVA_OPTS}
@guillaumebort
guillaumebort / Global.scala
Created June 9, 2012 11:50
Track response time of simple Action
import play.api._
import play.api.mvc._
object Global extends GlobalSettings {
def ResponseTime[A](action: Action[A]): Action[A] = Action(action.parser) { request =>
val start = System.currentTimeMillis
val result = action(request)
println( request + " -> " + (System.currentTimeMillis - start) + " ms.")
result
@guillaumebort
guillaumebort / 1.sql
Created May 25, 2012 15:17
Play 2.0/Anorm
# --- !Ups
CREATE TABLE users(
email VARCHAR(255) NOT NULL PRIMARY KEY,
name VARCHAR(255)
);
CREATE TABLE subjects(
id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
title LONGTEXT NOT NULL,
package controllers;
import play.*;
import play.mvc.*;
import play.libs.F.*;
import views.html.*;
public class Application extends Controller {
@guillaumebort
guillaumebort / Secured.scala
Created April 7, 2012 12:05
HTTP Basic Authorization for Play 2.0
def Secured[A](username: String, password: String)(action: Action[A]) = Action(action.parser) { request =>
request.headers.get("Authorization").flatMap { authorization =>
authorization.split(" ").drop(1).headOption.filter { encoded =>
new String(org.apache.commons.codec.binary.Base64.decodeBase64(encoded.getBytes)).split(":").toList match {
case u :: p :: Nil if u == username && password == p => true
case _ => false
}
}.map(_ => action(request))
}.getOrElse {
Unauthorized.withHeaders("WWW-Authenticate" -> """Basic realm="Secured"""")
@guillaumebort
guillaumebort / Build.scala
Created March 16, 2012 16:36
Add a kotlin compilation step
val main = PlayProject(appName, appVersion, appDependencies, mainLang = SCALA).settings(
compile in Compile <<= (compile in Compile, sourceDirectory in Compile, classDirectory in Compile, dependencyClasspath in Compile) map { (analysis, src, classes, classpath) =>
val allKotlinSources: Seq[java.io.File] = (src ** ".kotlin").get
// call the kotlin compiler using `classpath` and output classes to `classes`
analysis
}