This file contains 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
# To install dependencies: | |
# $ npm install express mongoose connect-mongoose | |
fs = require "fs" | |
express = require 'express' | |
mongoose = require 'mongoose' | |
sessionStore = require("connect-mongoose")(express) | |
Schema = mongoose.Schema | |
mongo_uri = "mongodb://localhost/bodilpwnz" |
This file contains 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 util.matching.Regex | |
object ExtremeStartup { | |
def answer(q: String): Any = { | |
if (q.contains("what is your name")) | |
return "Mikkel" | |
if (q.contains("which city is the Eiffel tower in")) | |
return "Paris" |
This file contains 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 update_quality(items) | |
rules = { "Conjured" => { ds:-1, mq:50, dq:[ -4, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2 ]}, | |
"Sulfuras" => { ds: 0, mq:80, dq:[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]}, | |
"Aged Brie" => { ds:-1, mq:50, dq:[ +2, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1 ]}, | |
"Backstage" => { ds:-1, mq:50, dq:[-50, +3, +3, +3, +3, +3, +2, +2, +2, +2, +2, +1 ]}, | |
"." => { ds:-1, mq:50, dq:[ -2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 ]}} | |
items.each do |item| | |
rules.each do |key,rule| | |
if item.name=~/#{key}/ | |
item.quality += rule[:dq][ [0, item.sell_in, 11].sort[1] ] |
This file contains 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 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 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 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 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 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 TradingDays extends App { | |
import scalaz._ | |
import Scalaz._ | |
case class Trade(sym: String, trader: String, qty: Int) | |
case class TradingDay(symbols: Map[String, SymDay] = Map.empty) | |
object TradingDay { |
This file contains 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
package com.developerb.dropbot; | |
import com.developerb.dropbot.instrumentation.MethodInvocationTimingInterceptor; | |
import com.google.inject.AbstractModule; | |
import com.yammer.metrics.annotation.Timed; | |
import static com.google.inject.matcher.Matchers.annotatedWith; | |
import static com.google.inject.matcher.Matchers.any; | |
/** |
OlderNewer