Skip to content

Instantly share code, notes, and snippets.

val pairs = sc.parallelize(List(("aa", 1), ("bb", 2),
("aa", 10), ("bb", 20),
("aa", 100), ("bb", 200)))
/* aggregateByKey takes an initial accumulator (here an empty list),
a first lambda function to merge a value to an accumulator, and a
second lambda function to merge two accumulators */
pairs.aggregateByKey(List[Any]())(
(aggr, value) => aggr ::: (value :: Nil),
(aggr1, aggr2) => aggr1 ::: aggr2
@krishnanraman
krishnanraman / r in scala.txt
Last active October 2, 2020 00:00
Using R from Scala
Step 0. You must have the latest & greatest version of R, and scala 2.10.1, for all of this to work.
Step 1. Download and unzip the MacOS X Binary jvmr_1.0.4.tgz from here: http://cran.r-project.org/web/packages/jvmr/index.html
Step 2. Create a lib folder, and copy jvmr_2.10-1.0.4.jar to that folder.
Step 3. Start R
Step 4. At the R console
>install.packages("jvmr")
@amscotti
amscotti / md5.coffee
Last active January 18, 2021 12:54
MD5 hashing
crypto = require('crypto');
#Quick MD5 of text
text = "MD5 this text!"
md5hash1 = crypto.createHash('md5').update(text).digest("hex")
#MD5 of text with updates
m = crypto.createHash('md5')
m.update("MD5 ")
m.update("this ")