Skip to content

Instantly share code, notes, and snippets.

@bodil
bodil / extremestartup.coffee
Created August 19, 2011 08:05
A CoffeeScript solution for @jhannes's evil Extreme Startup question set
# 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"
@mikkelbd
mikkelbd / ExtremeStartup.scala
Created October 24, 2011 11:23
BEKK kodekveld - Extreme Startup - refac
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"
@thirtysixthspan
thirtysixthspan / update.rb
Created December 9, 2011 03:36
The Gilded Rose Code Kata - a 'solution'
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] ]
@oxbowlakes
oxbowlakes / scala-interview1.scala
Last active October 1, 2015 08:48
Scala interview questions
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] {
@oxbowlakes
oxbowlakes / scala-interview2.scala
Created March 2, 2012 12:08
Scala interview questions hard
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")
}
@oxbowlakes
oxbowlakes / imperial-fx.scala
Created March 13, 2012 12:52
FX Rate example
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)
@oxbowlakes
oxbowlakes / imperial-monoid.scala
Created March 13, 2012 12:53
Monoid example
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
}
@oxbowlakes
oxbowlakes / imperial-position.scala
Created March 13, 2012 12:54
Position example (using monoid)
object Positions {
trait Investment
trait Position {
def investment: Investment
def tradingPnL: Option[Double]
def inventoryPnL: Option[Double]
final def totalPnL = inventoryPnL → tradingPnL
}
import Monoid._
@oxbowlakes
oxbowlakes / lens-example-tradingday.scala
Created April 24, 2012 10:05
Lens/State Example to remove repetition
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 {
@kimble
kimble / ApplicationGuiceModule.java
Created May 6, 2012 19:01
Dropwizard instrumentation of Guice beans annotated with @timed
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;
/**