Skip to content

Instantly share code, notes, and snippets.

View esuomi's full-sized avatar

Esko Suomi esuomi

  • Helsinki, Finland
View GitHub Profile
@esuomi
esuomi / build.gradle
Created June 9, 2013 08:02
Gradle multimodule project with Scala and less noisy directory structure than the default Maven one.
subprojects {
apply plugin: 'scala'
repositories {
mavenCentral()
}
dependencies {
compile 'org.scala-lang:scala-library:2.10.1'
testCompile 'junit:junit:4.11'
@esuomi
esuomi / Calculator.scala
Created May 26, 2013 18:27
Got terribly carried over when doing something completely different so here ya go, example DSL for simple BDD style testing.
/**
* Very low-tech calculator.
*
* @author Esko Suomi <[email protected]>
* @since 26.5.2013
*/
class Calculator {
def sum(x:Int, y:Int) = { x + y }
}
@esuomi
esuomi / worksheet.scala
Created May 9, 2013 08:37
Two lists with distinct types, both types having their unique definition of object identity. Find all id:s which exist in both lists or only in the latter.
class Ident(identity:Int) {
def ident = identity
override def toString = "[id:"+identity+"]"
}
class Id(identity:Int) {
def id = identity
override def toString = "[id:"+identity+"]"
}
@esuomi
esuomi / worksheet.scala
Created April 1, 2013 18:15
Quick pattern match test with Strings.
object worksheet {
def call[T](t:T, s:String) : (T,String) = { (t, s) }
//> call: [T](t: T, s: String)(T, String)
call("foo", "bar") match {
case (x, "bar") => println("found bar")
case (x, "baz") => println("found baz")
} //> found bar
}
@esuomi
esuomi / gist:5213168
Created March 21, 2013 13:55
Conditional app root with teamon's Play-Navigator (https://github.com/teamon/play-navigator/)
package controllers
import play.navigator._
object nav extends PlayNavigator {
if(!Play.isDev()) {
val root = namespace("app") {
val appRoot = app
}