Skip to content

Instantly share code, notes, and snippets.


Loïc Descotte loicdescotte

View GitHub Profile
loicdescotte / xmlParsing.scala
Last active Aug 29, 2015
Simple Scala XML Parsing
View xmlParsing.scala
//val xmlNode = xml.XML.loadFile("xxx")
val xmlNode =
<person age="30">
<person age="40">
loicdescotte / futureError.scala
Last active Aug 29, 2015
Scala futures error handling
View futureError.scala
val f: Future[Int] = Future {
if(math.random < 0.5) 1 else throw new Exception("Oh no")
} recover {
case ex:Exception => {
f map println
View observe.js
var names = ['joe', 'bob'];
Object.observe(names, function(changes){
changes.forEach(function(change) {
loicdescotte /
Created Aug 5, 2012
How to push 2 mixed searches from twitter with Scala, Play2, Iteratee and Comet


We will see how to mix 2 twitter searches and push the results to the browser in real time.

First, checkout this mini project

To try it, you need to install Play 2.0


loicdescotte /
Last active Oct 10, 2015
Play2 : Les Iteratees expliqués aux humains... francophones!

#Play2 : Les Iteratees expliqués aux humains... francophones!

Disclaimer : Ce qui suit est la traduction d'un article anglophone paru sur le blog

Vous pouvez retrouver l'article original ici

Vous avez probablement remarqué une nouvelle fonctionnalité intrigante de Play2 nommée Iteratee (ainsi que ses compagnons Enumerators et Enumeratee). Le but de cet article est d'essayer de rendre le concept d'Iteratee compréhensible pour le plus grand nombre avec des arguments simples, en évitant l'approche mathématique / fonctionnelle.

Cet article ne prétend pas tout expliquer à propos des Iteratee / Enumerator / Enumeratee mais traite plutôt les idées qui se cachent derrière.

loicdescotte /
Created Feb 19, 2013
Java 8 lamdba test
import java.util.Arrays;
public class Lambda {
public static void main (String[] args){
Arrays.asList("aaa", "bbb", "ccc", "abb").stream()
.filter((String w) -> w.startsWith("a"))
.forEach(w -> System.out.println(w));
loicdescotte /
Last active Dec 15, 2015
printToFile function

Higher order function to write stuffs in a file, with automatic resources management


  def printToFile(f: => Unit) {
    val p = new
    try { op(p) } finally { p.close() }
loicdescotte /
Last active Dec 23, 2015
Scala pattern matching examples

Scala pattern matching example

Value matching

def f(x: Int): String = x match {
  case 1 | 2 => "one or two"
  case 3 => "three"
  case _ => "other values"
View ConstructorDI.scala
class PrintService {
def print = println("I'm a real service")
trait Services {
val printService = new PrintService()
// put your other services here
//for example, a Play controller
loicdescotte / composeFutureOfNullable.kt
Last active May 16, 2016
Kotlin : compose futures of nullables
View composeFutureOfNullable.kt
fun combineNullable() {
fun giveInt(x: Int):Int? = x+1
fun giveInt2(x: Int):Int? = x+2
fun combine(x: Int): Int? = giveInt(x)?.let { giveInt2(it) }