Skip to content

Instantly share code, notes, and snippets.

@Timshel
Timshel / Constraints.scala
Last active December 20, 2015 01:58 — forked from playxamplez-admin/CODE
Define a #play2 #form #constraint for #required #optional mapping
import play.api.data.validation._
trait Constraints {
/**
* Defines a ‘required’ constraint for `Optional` values, i.e. one in which None are invalid.
*
* '''name'''[constraint.required]
* '''error'''[error.required]
*/
def nonNone[A]: Constraint[Option[A]] = Constraint[Option[A]]("constraint.required") { o =>
object Binder{
implicit def navigationPathBindable(implicit longBinder: PathBindable[Long]) = new PathBindable[Navigation] {
def bind(key: String, value: String): Either[String, Navigation] = {
for{
id <- longBinder.bind(key, value).right
nav <- Navigation.getNavigation(id).toRight("Navigation not found").right
} yield nav
}
@Timshel
Timshel / format.json
Last active December 27, 2015 01:48
Format ZenBench
{
id: "toto@zappos.com",
host: "toto",
env: [
{ types: "cpu", ref: "i5-3550"},
{ types: "ram", ref: "CMZ8GX3M2A1600C9", type: "DDR3", speed: "PC17066", timing: "CAS 11", quantity: "16GO"},
{ types: "disk", ref: "MZ-7TD250BW"}
],
metrics: [
{ id: "test1", value: "255666"},
@Timshel
Timshel / application.conf
Last active December 28, 2015 23:39
Play215 with scalariform formatting before compilation
# Control the activation of the scalariform plugin (default false).
application.scalariform.enable=true
# Path to the configuration properties :
#application.scalariform.config.path="conf/scalariform.properties"
@Timshel
Timshel / application.conf
Created November 21, 2013 13:00
Play221 with scalariform formatting before compilation
# Control the activation of the scalariform plugin (default false).
application.scalariform.enable=true
# Path to the configuration properties :
#application.scalariform.config.path="conf/scalariform.properties"
@Timshel
Timshel / Chiffrage.mkd
Last active August 29, 2015 13:56
Securité et confidentialité

Objectif : Créer une partition case sensitive chiffrée

Case sensitive : Pour les développeurs pour éviter les surprises en recette/prod.

Chiffrée : Pour éviter que le voleur du métro fasse n'importe quoi avec ce qui traine sur votre machine.

Autres solutions : True crypt, File vault sur tout le mac.

Fonctionnement :
A chaque démarrage de la machine vous devrez renseigner une pass-phrase pour déverrouiller la partition en question.

@Timshel
Timshel / Test.scala
Created December 19, 2014 12:50
Validation API
package test
import play.api.data.mapping._
object Test {
sealed trait Toto
case object toto1 extends Toto
case object toto2 extends Toto
@Timshel
Timshel / AddTempFileCreatorComponent.scala
Last active August 29, 2015 14:27
Workaround for Play #4925
import play.api._
import play.api.ApplicationLoader.Context
/**
* Fix for missing DefaultTemporaryFileCreator injection (#4925)
* Remove when next play version (2.4.3) is out.
*/
abstract class AddTempFileCreatorComponent(context: Context) extends BuiltInComponentsFromContext(context) {
import play.api.inject.{ SimpleInjector, NewInstanceInjector, Injector, DefaultApplicationLifecycle }
import play.api.libs.Files.DefaultTemporaryFileCreator
table.uiNodesView {
display: flex;
overflow: hidden;
background: none;
}
table.uiNodesView thead {
display: flex;
flex-shrink: 0;
min-width: min-content;
@Timshel
Timshel / helpers.scala
Created June 29, 2016 16:09
Custom `WithApplication` to expose main component
package helpers
import org.openqa.selenium.WebDriver
import org.specs2.execute.{ AsResult, Result }
import org.specs2.mutable.Around
import org.specs2.specification.Scope
import play.api.{ Application, ApplicationLoader, Environment, Mode }
import play.core.server.{ NettyServer, ServerProvider }
abstract class WithApplication extends Around with Scope {