Skip to content

Instantly share code, notes, and snippets.

View jto's full-sized avatar
🏠
Working from home

Julien Tournay jto

🏠
Working from home
View GitHub Profile
@jto
jto / Search.scala
Last active December 14, 2015 09:38 — forked from zxamplez/CODE
Create an #elasticsearch local node in a #playframework app
trait ElasticSearch {
import org.elasticsearch.node._
import org.elasticsearch.node.NodeBuilder._
val ELASTIC_URL = "http://localhost:9200"
val INDEX_URL = ELASTIC_URL + "/examples/gists"
val SEARCH_URL = INDEX_URL + "/_search"
private var node: Option[Node] = None
@jto
jto / _LICENSE.txt
Last active December 14, 2015 09:38 — forked from zxamplez/CODE
High level `Result` transformation in #playframework using #scalaz `Endo`
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2013 YOUR_NAME_HERE <YOUR_URL_HERE>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@jto
jto / actors.scala
Last active April 18, 2017 09:22 — forked from playxamplez-admin/CODE
simple #json messaging using #websocket and #akka #actors.
package controllers
import akka.actor._
import akka.pattern.ask
import akka.util.Timeout
import scala.concurrent.duration._
import scala.concurrent.Future
import play.api._
@jto
jto / Application.scala
Last active December 20, 2015 03:39 — forked from playxamplez-admin/CODE
Very simple #ServerSentEvent (#SSE) example
package controllers
import play.api.mvc._
import play.api.libs.EventSource
import play.api.libs.iteratee._
object Application extends Controller {
val events = Enumerator.repeat("0")
@jto
jto / parser.scala
Last active December 20, 2015 03:39 — forked from playxamplez-admin/CODE
Create an #Enumeratee transforming Bytes in lines. Compose it with am #Iteratee or an #Enumerator
private val LB = "\r\n"
val concatLine: Iteratee[Parsing.MatchInfo[Array[Byte]],String] =
(Enumeratee.breakE[Parsing.MatchInfo[Array[Byte]]](_.isMatch) ><>
Enumeratee.collect{ case Parsing.Unmatched(bytes) => new String(bytes)} &>>
Iteratee.consume()).flatMap(r => Iteratee.head.map(_ => r))
def lineParser =
Enumeratee.map{ s: Array[Byte] =>
(if(s.contains(LB + LB))