Skip to content

Instantly share code, notes, and snippets.

object Positions {
trait Investment
trait Position {
def investment: Investment
def tradingPnL: Option[Double]
def inventoryPnL: Option[Double]
final def totalPnL = inventoryPnL → tradingPnL
}
import Monoid._
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
}
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)
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")
}
import scala.io.Source.fromFile
import scalala.scalar._
import scalala.tensor.::
import scalala.tensor.mutable._
import scalala.tensor.dense._
import scalala.tensor.sparse._
import scalala.library.Library._
import scalala.library.LinearAlgebra._
import scalala.library.Statistics._
import scalala.library.Plotting._
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] {
import scala.math.ceil
import scala.math.log
import scala.math.min
import scala.math.abs
import scala.math.exp
import scala.math.pow
import java.security.MessageDigest
import java.nio.charset.Charset
import scalaz._
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");
Optimizing Google’s Warehouse Scale Computers: The NUMA Experience - authors from Univ. of Cal (SD) & Google!
http://static.googleusercontent.com/external_content/untrusted_dlcp/research.google.com/en/us/pubs/archive/40696.pdf
MegaPipe: A New Programming Interface for Scalable Network I/O by several authors!
https://docs.google.com/viewer?a=v&pid=forums&srcid=MDUxODU4OTA1NTU1MzUxODE5MDQBMTA5MDUzNTI5Mzg2ODk0MjY5NjUBYWM5cnR1MEY4Z1FKATQBAXYy
What Every Programmer Should Know About Memory by Ulrich Drepper
http://www.akkadia.org/drepper/cpumemory.pdf
Memory Barriers: a Hardware View for Software Hackers - Paul E. McKenney (Linux Technology Center - IBM Beaverton)
/*
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