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 Positions { | |
| trait Investment | |
| trait Position { | |
| def investment: Investment | |
| def tradingPnL: Option[Double] | |
| def inventoryPnL: Option[Double] | |
| final def totalPnL = inventoryPnL → tradingPnL | |
| } | |
| import Monoid._ |
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
| trait Monoid[A] { | |
| def identity: A | |
| def mplus(a1: A, a2: A): A | |
| } | |
| object Monoid { | |
| implicit val IntMonoid = new Monoid[Int] { | |
| def identity = 0 | |
| def mplus(a1: Int, a2: Int) = a1 + a2 | |
| } |
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 java.util.Currency | |
| object Fx { | |
| type CcyPair = (Currency, Currency) | |
| case class FxRate(from: Currency, to: Currency, rate: BigDecimal) { | |
| def pair: CcyPair = from → to | |
| def unary_~ = FxRate(to, from, 1 / rate) | |
| def *(that: FxRate): FxRate = { | |
| require(this.to == that.from) | |
| FxRate(this.from, that.to, this.rate * that.rate) |
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
| trait MyList[+A] { | |
| def fold[B](k: Option[(A, B)] => B): B | |
| def map[B](f: A => B): MyList[B] = sys.error("Implement me in terms of fold") | |
| def flatMap[B](f: A => MyList[B]): MyList[B] = sys.error("Implement me in terms of fold") | |
| def headOption: Option[B] = sys.error("Implement me in terms of fold") | |
| def tailOption: Option[MyList[B]] = sys.error("Implement me in terms of fold") | |
| def isEmpty = sys.error("Implement me in terms of fold") | |
| def length = sys.error("Implement me in terms of fold") | |
| } |
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 GOption { | |
| def some[A](a: A): GOption[A] = new GOption[A] { | |
| def cata[B](n: => B, s: A => B): B = sys.error("Implement me") | |
| } | |
| def none[A]: GOption[A] = new GOption[A] { | |
| def cata[B](n: => B, s: A => B): B = sys.error("Implement me") | |
| } | |
| } | |
| trait GOption[+A] { |
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
| public void sendMessage(String url, String params){ | |
| final HttpURLConnection connection; | |
| try { | |
| URL requestUrl = new URL(url); | |
| connection = (HttpURLConnection) requestUrl.openConnection(); | |
| connection.setDoOutput(true); | |
| connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); | |
| connection.setRequestProperty("Content-Length", Integer.toString(params.getBytes().length)); | |
| connection.setRequestProperty("Content-Language", "en-US"); |
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
| /* | |
| Goal: Use Scalding to datamine the 2010 US Census data (kindly provided by @ElonAzoulay & @hmason), to find | |
| Where do the WEALTHY WELL EDUCATED ELITE live ? | |
| WEALTHY == house value quarter million, household income 150k | |
| WELL EDUCATED == sort by edu, edu = (10 * Phd + 5 * MS + 1 * BS) score | |
| */ | |
| import com.twitter.scalding._ | |
| import cascading.tuple.Fields | |
| import cascading.tap.SinkMode |
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 FizzBuzz extends App { | |
| val nones = Stream.continually(None) | |
| val fizzes: Stream[Option[String]] = nones.take(2) ++ Some("Fizz") #:: fizzes | |
| val buzzes: Stream[Option[String]] = nones.take(4) ++ Some("Buzz") #:: buzzes | |
| for (((fizz, buzz), n) <- fizzes zip buzzes zip (1 to 100)) { | |
| println(fizz.map(_ + buzz.getOrElse("")).orElse(buzz).getOrElse(n)) | |
| } |
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
| 1. General Background and Overview | |
| a) Probabilistic Data Structures for Web Analytics and Data Mining : On Highly Scalable Blog (http://highlyscalable.wordpress.com/2012/05/01/probabilistic-structures-web-analytics-data-mining/) : A great overview of the space of probabilistic data structures and how they are used in approximation algorithm implementation. | |
| b) Models and Issues in Data Stream Systems : (http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.106.9846) | |
| c) Approximate Frequency Counts over Data Streams by Gurmeet Singh Manku & Rajeev Motwani (http://www.vldb.org/conf/2002/S10P03.pdf) : One of the early papers on the subject. | |
| d) Methods for Finding Frequent Items in Data Streams by Graham Cormode & Marios Hadjieleftheriou (http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.187.9800&rep=rep1&type=pdf) | |
| e) The space complexity of approximating the frequency moments by Noga Alon, Yossi Matias, Mario Szegedy : one of the most influential papers introducing succinctness in computing fre |