Skip to content

Instantly share code, notes, and snippets.

@Timshel
Timshel / solution.scala
Last active December 14, 2015 09:18 — forked from mandubian/solution.scala
How to create a form #scala #form #modified
Form(
tuple(
"numero" -> optional(nonEmptyText(6,6)),
"nom" -> cleanText(1,64),
"prenom" -> cleanText(1,64),
"coefficient" -> number
)
)
@Timshel
Timshel / TTT
Created June 23, 2013 19:16
Test
Wtf
@Timshel
Timshel / Atomic.scala
Created July 12, 2013 11:50 — forked from piotrga/gist:1986175
Atomic Sugar
import annotation.tailrec
import java.util.concurrent.atomic.AtomicReference
class Atomic[T](val atomic : AtomicReference[T]) {
@tailrec
final def update(f: T => T) : T = {
val oldValue = atomic.get()
val newValue = f(oldValue)
if (atomic.compareAndSet(oldValue, newValue)) newValue else update(f)
@Timshel
Timshel / Application.scala
Last active December 19, 2015 21:19
Multiple select example using play2 master
package controllers
import play.api._
import play.api.data._
import play.api.data.Forms._
import play.api.mvc._
object Application extends Controller {
val form = Form(
@Timshel
Timshel / jenkins.sh
Created July 18, 2013 12:50
Jenkins
#!/bin/bash
export PATH=/usr/share/tomcat7/play/play-2.1.1:/usr/local/bin:$PATH
export PHANTOMJS_BIN=/usr/share/tomcat7/phantomjs/phantomjs-1.9.1-linux-x86_64/bin/phantomjs
moHash=$(cat project/Build.scala | grep -e "val libVersion" | sed -e "s/.*\"\(.*\)\".*/\1/g")
# Setup env
mkdir test_out
This is the fork of Xamplez core Configuration Gist

If your csv doesn't contain escaped newlines then it is pretty easy to do a progressive parsing without putting the whole file into memory. The iteratee library comes with a method search inside play.api.libs.iteratee.Parsing :

def search (needle: Array[Byte]): Enumeratee[Array[Byte], MatchInfo[Array[Byte]]]

which will partition your stream into Matched[Array[Byte]] and Unmatched[Array[Byte]]

Then you can combine a first iteratee that takes a header and another that will fold into the umatched results. This should look like the following code:

// break at each match and concat unmatches and drop the last received element (the match)
@Timshel
Timshel / Application.scala
Last active December 20, 2015 01:29 — forked from playxamplez-admin/CODE
#multiple #select example using play2 master
package controllers
import play.api._
import play.api.data._
import play.api.data.Forms._
import play.api.mvc._
object Application extends Controller {
val form = Form(
@Timshel
Timshel / Atomic.scala
Last active December 20, 2015 01:29 — forked from playxamplez-admin/CODE
#scala #atomic sugar from https://gist.github.com/piotrga/1986175
import annotation.tailrec
import java.util.concurrent.atomic.AtomicReference
class Atomic[T](val atomic : AtomicReference[T]) {
@tailrec
final def update(f: T => T) : T = {
val oldValue = atomic.get()
val newValue = f(oldValue)
if (atomic.compareAndSet(oldValue, newValue)) newValue else update(f)
@Timshel
Timshel / CustomMessagesPlugin.scala
Last active December 20, 2015 01:58 — forked from playxamplez-admin/CODE
#play2.1 custom #MessagesPlugin to add messages from different sources
package play.api.i18n
import play.api._
import play.api.i18n._
import scala.collection.JavaConverters._
import scalax.file._
import scalax.io.JavaConverters._