Skip to content

Instantly share code, notes, and snippets.

🎯
Focusing

Sam Bessalah samklr

🎯
Focusing
Block or report user

Report or block samklr

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@bodil
bodil / extremestartup.coffee
Created Aug 19, 2011
A CoffeeScript solution for @jhannes's evil Extreme Startup question set
View extremestartup.coffee
# 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 Oct 24, 2011
BEKK kodekveld - Extreme Startup - refac
View ExtremeStartup.scala
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 Dec 9, 2011
The Gilded Rose Code Kata - a 'solution'
View update.rb
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 Oct 1, 2015
Scala interview questions
View scala-interview1.scala
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 Mar 2, 2012
Scala interview questions hard
View scala-interview2.scala
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")
}
View imperial-fx.scala
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)
View imperial-monoid.scala
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 Mar 13, 2012
Position example (using monoid)
View imperial-position.scala
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 Apr 24, 2012
Lens/State Example to remove repetition
View lens-example-tradingday.scala
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
Dropwizard instrumentation of Guice beans annotated with @timed
View ApplicationGuiceModule.java
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;
/**
You can’t perform that action at this time.