Skip to content

Instantly share code, notes, and snippets.

class Foo {
val quux = "quux"
def bar(baz: () => Unit): Foo = {
baz()
this
}
}
// I would like to write in fluent style like this but I can't reference the
// previous object in the chain
class Bar(i: Int) {
val lst = List.empty[Int]
def copy(i: Int = i, lst: List[Int] = lst) = {
val b = new Bar(i = i)
b.lst = lst
}
}
import scala.concurrent._
import scala.concurrent.duration._
import scala.concurrent.ExecutionContext.Implicits.global
def runWithTimeout[T](timeoutMs: Long)(f: => Future[T]) : T = {
Await.result(f, timeoutMs.millis)
}
runWithTimeout(50) { Future { "result" } }
class LoggerLikeStub extends LoggerLike {
import scala.collection.mutable.Buffer
val logMessages: Buffer[String] = Buffer()
override val logger: Logger = null
override def warn(msg: => String) = {
logMessages += msg
@dabd
dabd / ex.scala
Last active December 21, 2015 15:34
trait A {
protected def f : Boolean
}
object A extends A {
protected def f : Boolean = true
}
object B extends A {
(defprotocol PStack
"A stack protocol"
(push [this val] "Push element in")
(pop* [this] "Pop element from stack")
(top [this] "Get top element from stack"))
(defrecord FStack [coll]
PStack
(push [_ val]
"Return the stack with the new element inserted"
(def ddl-parser
(insta/parser
"ddl = (createtable* (!createtable <any>)*)+
<any> = #'\\S+'
createtable = 'CREATE TABLE' table cols
cols = <'('> columns <','> constraint <');'>
table = identifier
identifier = #'[a-zA-Z_0-9\\.]+'
columns = column (',' column)*
column = name type nullable?
@dabd
dabd / .clj
Last active August 29, 2015 14:26
(def foo-parser
(insta/parser
"grammar = foo | other
foo = 'FOO'
other = !foo"
:auto-whitespace :standard))
Configuring TestNG with: org.apache.maven.surefire.testng.conf.TestNG652Configurator@60acc399
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 2.326 sec <<< FAILURE!
shouldMapHashMapToFoo(org.me.modelmapper.JsonModelMapperTest) Time elapsed: 0.186 sec <<< FAILURE!
org.modelmapper.ConfigurationException: ModelMapper configuration errors:
1) Invalid source method java.util.HashMap.get(). Ensure that method has zero parameters and does not return void.
2) Invalid source method java.util.HashMap.get(). Ensure that method has zero parameters and does not return void.
2 errors
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.me.modelmapper;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.JsonElement;