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
def appendAt[K,V](m: scala.collection.mutable.Map[K,List[V]], k: K, v: V) = m(k) = (m.getOrElse(k, List[V]()) :+ v) |
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
type Graph[T] = scala.collection.mutable.MultiMap[T,T] | |
def newGraph[T]: Graph[T] = new scala.collection.mutable.HashMap[T,scala.collection.mutable.Set[T]] with Graph[T] |
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 sbt._ | |
class Project(info: ProjectInfo) extends DefaultProject(info) { | |
val clouderaRepo = "cloudera release" at "https://repository.cloudera.com/content/repositories/releases" | |
val cdhVer = "0.20.2-cdh3u0" | |
val hadoopCore = "org.apache.hadoop" % "hadoop-core" % cdhVer % "provided" | |
} |
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.actors.Futures | |
(Futures.awaitAll(9999999,1.to(100000).map(x => Futures.future{Thread.currentThread.getName}): _*).foldLeft(Set[String]()) {(set, name) => set + name.get.toString}).foreach(println); |
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
organization := "Example" | |
name := "example" | |
scalaVersion := "2.9.0-1" | |
resolvers += Resolver.url("ClouderaRepo", url("https://repository.cloudera.com/content/repositories/releases")) | |
libraryDependencies ++= Seq( | |
"org.apache.hadoop" % "hadoop-core" % "0.20.2-cdh3u0", |
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
object MD5 { | |
def hash(s: String) = { | |
val m = java.security.MessageDigest.getInstance("MD5") | |
val b = s.getBytes("UTF-8") | |
m.update(b, 0, b.length) | |
new java.math.BigInteger(1, m.digest()).toString(16) | |
} | |
} |
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
class ThreadLocal[T](init: => T) extends java.lang.ThreadLocal[T] with Function0[T] { | |
override def initialValue:T = init | |
def apply = get | |
def :=(value: T) { set(value) } | |
} |
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
// Note to self: Use https://github.com/scalaj/scalaj-http next time instead. | |
import java.net._ | |
import actors.Future | |
import actors.Futures._ | |
object woobox extends App { | |
val codes = ('a'.to('z').map(_.toString) ++ 0.to(9).map(_.toString)).combinations(6) | |
val blockSize = 100 | |
var i = 0 |
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
class ByteArrayWrapper(bytes: Array[Byte]) { | |
def fromUtf8: String = { | |
"Converted to String." | |
} | |
} | |
object ByteArrayWrapper { | |
implicit def makeByteArrayWrapper(bytes: Array[Byte]): ByteArrayWrapper = new ByteArrayWrapper(bytes) | |
} | |
object byteImplicit extends App { |
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
object typeErasure { | |
def main(args: Array[String]) { | |
val evenOdd = 1.to(10) | |
.map{x => if (x%2==0) { Option[Int](x) } else { None } } | |
.partition{ case Some(_) => true case _ => false } | |
println(evenOdd) | |
} | |
} |
OlderNewer