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 / 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
}
@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 / 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 / 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 / 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 / gist:7180371
Last active December 26, 2015 16:29
UPDATE/CREATE REST-rajapinnoissa

simppeli POST

POST /collection/{resourceId} + request payload

  • Jos resurssi on uusi, luodaan resurssi. (=CREATE)
  • Jos resurssi on olemassa, asetetaan resurssin arvoksi annettu tieto. (=UPDATE) Osittainen resurssin päivitys mahdollista.

simppeli PUT

PUT /collection + request payload

@esuomi
esuomi / CodePointIterator.java
Created November 3, 2013 09:27
Iterates through a given `String` in unicode compatible way character by character.
package text;
import java.util.Iterator;
/**
* <p>Fun fact, this actually already exists in <code>sun.text.CodePointIterator</code></p>
*
* @author Esko Suomi <[email protected]>
* @since 31.8.2013
*/
@esuomi
esuomi / FizzBuzz8.java
Created February 15, 2014 12:53
Java 8 lambda syntax and then some to reinvent the FizzBuzz wheel.
package features;
import java.util.function.Function;
import java.util.stream.IntStream;
/**
* Just to prove that I'm not an idiot. Or maybe I am but haven't noticed it yet. Making seemingly simple tasks
* makes one really, really paranoid.
*
* @since 15.2.2014
public class Labels {
public static void main(String[] args) {
http://example.org
for (int i = 0; i < 5; i++) {
System.out.println("i = " + i);
if (i == 3) {
break http;
}
}
}
@esuomi
esuomi / Labels2.java
Created October 14, 2017 16:01
this is even worse
public class Labels {
public static void main(String[] args) {
http://example.org
for (int i = 0; i <= 3; ++i) {
System.out.println("i = " + i);
if (i == 2) {
System.out.println("*cough*");
i = 2;
continue http;
}