This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
exec scala -nocompdaemon -usejavacp -savecompiled "$0" "$@" | |
!# | |
/* will output : | |
END of the script reached | |
OK - slept 1s | |
OK - slept 2s | |
OK - slept 4s | |
OK - slept 8s |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
exec scala -deprecation -nocompdaemon "$0" "$@" | |
!# | |
def usedMemoryInMo() = { | |
val rt= java.lang.Runtime.getRuntime | |
(rt.totalMemory - rt.freeMemory)/1024/1024 | |
} | |
println(util.Properties.javaVersion) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.collection._ | |
import scala.collection.mutable.{ArrayBuffer,ListBuffer, Builder} | |
import scala.collection.generic._ | |
import scala.collection.immutable.VectorBuilder | |
// ================================ CustomTraversable ================================== | |
object CustomTraversable extends TraversableFactory[CustomTraversable] { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ============================= NamedCustomSet =================================== | |
object NamedCustomSet { | |
def apply[A](name:String, s:A*) = new NamedCustomSet(name, s.toSet) | |
implicit def canBuildFrom[A,B]: CanBuildFrom[NamedCustomSet[B], A, NamedCustomSet[A]] = | |
new CanBuildFrom[NamedCustomSet[B], A, NamedCustomSet[A]] { | |
def apply(from: NamedCustomSet[B]) = newBuilder(from.name) | |
def apply() = newBuilder | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
exec java -jar jassh.jar -nocompdaemon -usejavacp -savecompiled "$0" "$@" | |
!# | |
// jassh.jar can be downloaded here : http://code.google.com/p/janalyse-ssh/ | |
import jassh._ | |
import concurrent._ | |
import duration._ | |
import scala.util._ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
exec scala -deprecation -nocompdaemon "$0" "$@" | |
!# | |
val l=List(0, 1, 2) | |
var x=1 | |
val m1=l.map(_ +x) // c1 | |
val v1=l.view.map(_+x) // c2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
exec scala -deprecation -nocompdaemon "$0" "$@" | |
!# | |
def trace(x:Int) = {println(x); x} | |
val x=(1 to 5).toStream.map(trace _) | |
// 1 is printed | |
val y=(5 to 1 by -1).toStream.map(trace _) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val args=Array("x=5", "y=10", "debug=true", "-verbose", "toto=truc1=titi", "nop", "tata=") | |
val argsRE="([^=]+)=(.*)".r | |
// ------- solution 1 with regex | |
args.flatMap{case argsRE(k,v) => Some(k->v) case _=> None}.toMap | |
// ------- solution 2 - with regex | |
args.collect{case argsRE(k,v) => k->v}.toMap |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package controllers | |
import play.api._ | |
import play.api.mvc._ | |
import play.api.libs.concurrent.Execution.Implicits._ | |
import play.api.libs.concurrent.Akka | |
import play.api.Play.current | |
import scala.concurrent._ | |
import scala.concurrent.duration._ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
exec scala "$0" "$@" | |
!# | |
import scala.annotation.tailrec | |
// --------------------------------------------------- | |
def searchFirstGreaterOrEqual[T<%Ordered[T]](seq: Seq[T], value: T):Option[Int] = { | |
@tailrec | |
def binarysearch(left:Int, right:Int):Option[Int] = { |
OlderNewer