View intersect.scala
def intersect(ens: List[Int], ems: List[Int]): List[Int] = (ens, ems) match {
case (Nil, _) => Nil
case (_, Nil) => Nil
case (en :: ensTail, em :: emsTail) if en == em => en :: intersect(ensTail, emsTail)
case (en :: ensTail, em :: _) if en < em => intersect(ensTail dropWhile { _ < em }, ems)
case (en :: _, em :: emsTail) => intersect(ens, emsTail dropWhile { _ < en })
}
intersect(List(1, 2, 3, 4), List(3, 4, 5, 6)) // = List(3, 4)
intersect(List(3, 4, 5, 6), List(1, 2, 3, 4)) // = List(3, 4)
View ScoobiRemoteCalculation.scala
package com.gu.scoobi
import com.nicta.scoobi.Scoobi._
object ScoobiRemoteCalculation extends ScoobiApp {
def run() {
val test = onHadoop {
scala.math.pow(2, 16)
}
View build.sbt
name := "Scoobi"
version := "1-SNAPSHOT"
scalaVersion := "2.9.2"
scalacOptions ++= Seq("-Ydependent-method-types", "-deprecation")
libraryDependencies += "com.nicta" %% "scoobi" % "0.6.0-cdh3-RC2"
View ApplicationParameters.scala
package com.gu.hadoop
import org.apache.hadoop.util.GenericOptionsParser
object ApplicationParameters {
def apply(args: Array[String]): List[String] = {
new GenericOptionsParser(args).getRemainingArgs.toList
}
}
View gist:4269195
var steps = document.getElementsByClassName("step");
var r = 2000;
for (var i = 0; i < steps.length; i++) {
var theta = -i/(steps.length-1) * 2 * Math.PI;
var x = r * Math.cos(theta);
var y = r * Math.sin(theta);
var rotation = theta/(2*Math.PI) * 360 - 90;
steps[i].setAttribute("data-x", Math.round(x).toString());
View gist:1994249
trait ListMultiMaps {
type ListMultiMap[A, B] = Map[A, List[B]]
implicit def listMultiMap2ListMultiMapOperations[A, B](map: ListMultiMap[A, B]) = new ListMultiMapOperations(map)
object ListMultiMap {
def apply[A, B](): ListMultiMap[A, B] = Map[A, List[B]]()
def apply[A, B](kvs: List[(A, B)]): ListMultiMap[A, B] = {
var rst = apply[A, B]()
kvs foreach { kv =>
View gist:1760314
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
View gist:1555284
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
View SBT 0.11 Continuations Plugin Example
autoCompilerPlugins := true
addCompilerPlugin("org.scala-lang.plugins" % "continuations" % "2.9.1")
scalacOptions += "-P:continuations:enable"
View gist:1197348
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;