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.language.higherKinds | |
object nat { | |
trait Nat { | |
/** The type of this Nat object. */ | |
type Self <: Nat | |
/** Add another Nat to this one. */ | |
type + [_ <: Nat] <: Nat |
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
val local:ThreadLocal[String] = new InheritableThreadLocal[String] | |
local.set("value") | |
println(s"${local.get()}") |
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.concurrent._ | |
import ExecutionContext.Implicits.global | |
val local1:ThreadLocal[String] = new InheritableThreadLocal[String] | |
val local2:ThreadLocal[String] = new ThreadLocal[String] | |
local1.set("foo") | |
local2.set("bar") | |
println(s"main: local1= ${local1.get()}") |
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.concurrent._ | |
import ExecutionContext.Implicits.global | |
// global ThreadLocal structures | |
val local1:ThreadLocal[String] = new InheritableThreadLocal[String] | |
val local2:ThreadLocal[String] = new ThreadLocal[String] | |
local1.set("foo") | |
local2.set("bar") |
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.concurrent._ | |
import ExecutionContext.Implicits.global | |
// global ThreadLocal structures | |
val local1:ThreadLocal[String] = new InheritableThreadLocal[String] | |
val local2:ThreadLocal[String] = new ThreadLocal[String] | |
local1.set("foo") | |
local2.set("bar") |
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.concurrent._ | |
import ExecutionContext.Implicits.global | |
// ThreadLocal structures as class members | |
class Context { | |
private val local: ThreadLocal[String] = new InheritableThreadLocal[String] { | |
override protected def childValue(parent: String): String = { | |
println(s"cloning parent ${parent}") | |
s"(${parent})" | |
} |
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
[eje@localhost spark]$ scala | |
Welcome to Scala version 2.10.3-20130923-e2fec6b28dfd73482945ffab85d9b582d0cb9f17 (OpenJDK 64-Bit Server VM, Java 1.7.0_71). | |
Type in expressions to have them evaluated. | |
Type :help for more information. | |
scala> import java.util.Properties | |
import java.util.Properties | |
scala> val p = new Properties | |
p: java.util.Properties = {} |
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
// A formalism that might be defined using different axiom systems | |
// Not intended to be instantiated directly | |
trait Formalism { | |
// from axiom system A/B | |
def A: Unit | |
def B: Unit | |
// from axiom system C/D | |
def C: Unit |
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
// starting Spark REPL at top of source tree: | |
// $ cd ~/git/spark | |
// $ ./bin/spark-shell | |
// | |
import org.apache.spark.mllib.tree.RandomForest | |
import org.apache.spark.mllib.util.MLUtils | |
// Load and parse the data file. | |
val data = MLUtils.loadLibSVMFile(sc, "data/mllib/sample_libsvm_data.txt") | |
// Split the data into training and test sets (30% held out for testing) | |
val splits = data.randomSplit(Array(0.7, 0.3)) |
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 kMedoids[T :ClassTag, U >: T :ClassTag]( | |
data: RDD[T], | |
k: Int, | |
metric: (U,U) => Double, | |
sampleSize: Int = 10000, | |
maxIterations: Int = 10, | |
resampleInterval: Int = 3 | |
): (Seq[T], Double) = { | |
val n = data.count |