Skip to content

Instantly share code, notes, and snippets.

@rjhall
rjhall / scala_wtf
Created December 18, 2012 20:21
I am curious why class B has two methods called f, and why calling f returns a List rather than an Iterable.
scala> abstract class A { def f : Iterable[String] }
defined class A
scala> class B extends A { def f = List("foo", "bar") }
defined class B
scala> class C extends A { val r = math.random; def f = { val v = List("foo", "bar"); if(r < 0.5) v else v.map{_ + "_"} } }
defined class C
scala> (new B).f
@rjhall
rjhall / nlss.R
Created June 9, 2013 03:53
A non-linear state space model where the transitions come via a kernel regression.
library(tuneR);
library(MASS);
rate = 10000;
width = 2500;
zdim = 400;
play_vec = function(v) {
wnew = Wave(v * 32760/max(abs(v)), right = numeric(0), samp.rate = rate, bit = 16);
play(wnew, '/Users/rhall/Downloads/playRWave');
@rjhall
rjhall / lsh_hmm.R
Last active December 18, 2015 10:49
library(tuneR);
rate = 24000;
width = 6000;
play_vec = function(v) {
wnew = Wave(v * 32760/max(abs(v)), right = numeric(0), samp.rate = rate, bit = 16);
play(wnew, '/Users/rhall/Downloads/playRWave');
}
@rjhall
rjhall / gist:6134808
Created August 1, 2013 20:12
pwn.scala
scala> abstract class A { def holler : String; println(holler) }
defined class A
scala> class B extends A { def holler = "holler" }
defined class B
scala> new B()
holler
res0: B = B@54011d95
@rjhall
rjhall / gist:6134811
Created August 1, 2013 20:13
pwn.scala
scala> abstract class A { def holler : String; println(holler) }
defined class A
scala> class B extends A { def holler = "holler" }
defined class B
scala> new B()
holler
res0: B = B@54011d95
package com.etsy.scalding.jobs
import com.etsy.scalding._
import com.twitter.scalding._
class Demo(args : Args) extends Job(args) {
// best way to compute covariance matrix?
// the dimension.
val N = 1000;
@rjhall
rjhall / gist:6165629
Created August 6, 2013 15:39
Demo.scala
import com.twitter.scalding._
class Demo(args : Args) extends Job(args) {
override def config(implicit mode : Mode) = super.config ++ Map("cascading.aggregateby.threshold" -> "1000000")
import com.twitter.scalding.TDsl._
// best way to compute covariance matrix?
n = 500;
m = 700;
d = 10;
X = matrix(data=1*(runif(n*m) < 0.1), nr=n, nc=m);
S = matrix(data=rnorm(m*(d+2)), nr=m, nc=(d+2));
XS = X %*% S
XX = X %*% t(X);
XX2 = XX %*% t(XX);
@rjhall
rjhall / SVD.scala
Last active December 20, 2015 22:08
import org.apache.commons.math3.linear._
import com.twitter.algebird.Operators._
import com.twitter.scalding._
import cascading.pipe.Pipe
import cascading.pipe.joiner.InnerJoin
import cascading.tuple.Fields
object SVD extends Serializable {
package com.etsy.scalding.jobs
import com.twitter.scalding._
class TouchTheVoid(args : Args) extends Job(args) {
// 25M (Long, Double) pairs.
val scores = SequenceFile("stuff", ('id, 'score, 'stuff))
.project('id, 'score)