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
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) |
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
package com.gu.scoobi | |
import com.nicta.scoobi.Scoobi._ | |
object ScoobiRemoteCalculation extends ScoobiApp { | |
def run() { | |
val test = onHadoop { | |
scala.math.pow(2, 16) | |
} |
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
name := "Scoobi" | |
version := "1-SNAPSHOT" | |
scalaVersion := "2.9.2" | |
scalacOptions ++= Seq("-Ydependent-method-types", "-deprecation") | |
libraryDependencies += "com.nicta" %% "scoobi" % "0.6.0-cdh3-RC2" |
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
package com.gu.hadoop | |
import org.apache.hadoop.util.GenericOptionsParser | |
object ApplicationParameters { | |
def apply(args: Array[String]): List[String] = { | |
new GenericOptionsParser(args).getRemainingArgs.toList | |
} | |
} |
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
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()); |
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 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 => |
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 |
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
autoCompilerPlugins := true | |
addCompilerPlugin("org.scala-lang.plugins" % "continuations" % "2.9.1") | |
scalacOptions += "-P:continuations:enable" |
NewerOlder