This file contains 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 sleep(inSeconds:Int) = Thread.sleep(inSeconds*1000L) | |
def usedMemoryInMo_sillyimpl() = { | |
System.gc | |
sleep(2) | |
val rt= java.lang.Runtime.getRuntime |
This file contains 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 sleep(inSeconds:Int) = Thread.sleep(inSeconds*1000L) | |
def usedMemoryInMo_sillyimpl() = { | |
System.gc | |
sleep(2) | |
val rt= java.lang.Runtime.getRuntime |
This file contains 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.concurrent._ | |
import ExecutionContext.Implicits.global | |
val f = future { new java.net.URL("http://mvnrepository.com/artifact/com.jcraft/jsch").openConnection() } | |
.map { cnx => | |
cnx.setConnectTimeout(5000) | |
cnx.setReadTimeout(5000) | |
cnx.setAllowUserInteraction(false) | |
cnx.setUseCaches(false) | |
cnx } |
This file contains 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
// ----------------------------------------------- | |
// Generic square method that works with any kind | |
// of numerical type | |
// ----------------------------------------------- | |
def square[N](x: N)(implicit n: Numeric[N]) = { | |
n.times(x, x) | |
} | |
square(10d) | |
square(BigDecimal(4)) |
This file contains 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 -J-Xms80m -J-Xmx80m -deprecation -nocompdaemon "$0" "$@" | |
!# | |
def allocate(szInMb:Int=24) = | |
Array.fill[Byte](1024*1024*szInMb)(util.Random.nextInt(256).toByte) | |
def testit = { | |
val showStep = {var s=0 ; () => {s+=1 ; println(s"step$s")}} | |
{ showStep(); val x= allocate(20) } |
This file contains 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 -J-Xms80m -J-Xmx80m -deprecation -nocompdaemon "$0" "$@" | |
!# | |
def allocate(szInMb:Int=24) = | |
Array.fill[Byte](1024*1024*szInMb)(util.Random.nextInt(256).toByte) | |
def allocally[A](proc: => A) {proc} | |
def testit = { |
This file contains 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 /opt/analysis/analysis "$0" "$@" | |
!# | |
import scalax.file._ | |
import scalax.file.ImplicitConversions._ | |
val dirs = if (args.size>0) args.toList else List(".") | |
val exts = List( | |
"scala","xml","drl","java","ksh","sh","sql","sbt","properties","conf" |
This file contains 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 java.util.Date | |
trait Currency { | |
val symbol:String | |
val name:String | |
} | |
// unfortunately Objects is not supported by json4s (or not yet) | |
case class Dollar() extends Currency { |
This file contains 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.generic.CanBuildFrom | |
import scala.annotation.tailrec | |
def compact[A, I[A]](list: I[A]) | |
(implicit bf: CanBuildFrom[I[A], A, I[A]], c2i:I[A]=>Iterable[A]): I[A] = { | |
var builder = bf.apply() | |
var prev: Option[A] = None | |
for (item <- list) { | |
if (prev == None || prev.get != item) builder += item | |
prev = Some(item) |
This file contains 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
scala> def doubler(start:Long):Stream[Long]=start#::doubler(2*start) | |
doubles: (start: Long)Stream[Long] | |
scala> doubler(1250).take(12).toList | |
res21: List[Long] = List(1250, 2500, 5000, 10000, 20000, 40000, 80000, 160000, 320000, 640000, 1280000, 2560000) | |
scala> def doubler[N](start:N)(implicit n: Numeric[N]):Stream[N]=start#::doubler(n.plus(start,start)) | |
doubles: [N](start: N)(implicit n: Numeric[N])Stream[N] | |
scala> doubler(1250d).take(6).toList |