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
trait InMainThread { | |
private val handler = new Handler | |
def mainThread(block: => Unit) { | |
handler.post(new Runnable { | |
def run { block } | |
}) | |
} | |
} |
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> val l = List((1,2), (2,3)) | |
l: List[(Int, Int)] = List((1,2), (2,3)) | |
scala> l map { case (i, j) => i+j } | |
res5: List[Int] = List(3, 5) | |
scala> import Function.tupled | |
import Function.tupled | |
scala> l map tupled { (i, j) => i + j } |
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 test = { println("Evaluating"); "test" } | |
test: java.lang.String | |
scala> case class TestClass(s: String) { override def toString = "overrided so the REPL doesn't coerse evaluation of s" } | |
defined class TestClass | |
scala> val t = TestClass(test) | |
Evaluating | |
t: TestClass = overrided so the REPL doesn't coerse evaluation of s |
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
> test | |
... | |
[info] Test Starting - BenchmarksTest: SourceBenchmark | |
Mean: 392.100000 | |
StdDev: 5.022947 | |
[info] Test Succeeded - BenchmarksTest: SourceBenchmark | |
[info] Test Starting - BenchmarksTest: InputStreamBenchmark | |
Mean: 69.610000 |
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
implicit def iterable2Cross[T, C[T] <: Iterable[T]](tees: C[T]) = new { | |
import collection.generic.CanBuildFrom | |
def cross[S](esses: Iterable[S])(implicit cbf: CanBuildFrom[C[(T,S)],(T,S),C[(T,S)]]): C[(T,S)] = { | |
val builder = cbf() | |
val rst = for (t <- tees; s <- esses) yield (t, s) | |
rst foreach { builder += } | |
builder.result |
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
implicit def seq2Distinct[T, C[T] <: Seq[T]](tees: C[T]) = new { | |
import collection.generic.CanBuildFrom | |
import collection.mutable.{HashSet => MutableHashSet} | |
def distinctBy[S](hash: T => S)(implicit cbf: CanBuildFrom[C[T],T,C[T]]): C[T] = { | |
val builder = cbf() | |
val seen = MutableHashSet[S]() | |
for (t <- tees) { | |
if (!seen(hash(t))) { |
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
CREATE OR REPLACE FUNCTION dfn_clobReplace | |
( p_clob IN CLOB, | |
p_what IN VARCHAR2, | |
p_with IN VARCHAR2 ) RETURN CLOB IS | |
c_whatLen CONSTANT PLS_INTEGER := LENGTH(p_what); | |
c_withLen CONSTANT PLS_INTEGER := LENGTH(p_with); | |
l_return CLOB; | |
l_segment CLOB; |
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
autoCompilerPlugins := true | |
addCompilerPlugin("org.scala-lang.plugins" % "continuations" % "2.9.1") | |
scalacOptions += "-P:continuations:enable" |
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
implicit def nullable2Option[N >: Null](n: N) = new { | |
lazy val option: Option[N] = Option(n) | |
} | |
val s1: String = "1234" | |
s1.option // Option[String] = Some(1234) | |
val s2: String = null | |
s2.option // Option[String] = None |
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
val Param = """(.+)=(.+)""".r | |
def params(parameters: String): Map[String, String] = { | |
(parameters split "\\?") match { | |
case Array(path, queryString) => | |
val kvs = (queryString split "&").toList collect { | |
case Param(key, value) => key -> value | |
} | |
kvs.toMap |
OlderNewer