Skip to content

Instantly share code, notes, and snippets.

import scala.collection.mutable
import scala.collection.JavaConverters._
import org.eclipse.jgit.diff.{HistogramDiff, Sequence, SequenceComparator}
val histogramDiff = new HistogramDiff()
histogramDiff.setFallbackAlgorithm(null)
val deltas = histogramDiff.diff(
new DataListComparator[Char],
object CodeGenFunctions extends js.Object {
def fn() = println("hello")
}
// JavaScript output
function $s_Lminicol_CodeGenFunctions$__fn__Lminicol_CodeGenFunctions$__V($this) {
$m_Lminicol_package$();
console.log("hello")
}
import org.scalajs.dom.document
object Session {
val CookieName = "SessionId"
val key: String = CookieName
var username: Option[String] = Option(JsGlobals.username)
def get: Option[String] =
document.cookie.split(";").toList.flatMap { part =>
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
/**
* A Service is an abstraction for a small processing unit that takes a request
* and responds asynchronously. The communication is therefore entirely
* message-driven. The messages are epxected to be immutable. A service can
* have an internal state that will not be exposed. Services can be composed
* and requests may be forwarded to other services. The concept is inspired by
* Akka's actors.
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.graphics.g2d.Batch;
@tindzk
tindzk / gist:e2966773aa3e72897204
Last active January 15, 2016 16:35
ScalaRelational benchmarks
> run -i 2 -wi 2 -f 0
SR v1.1.0, Slick v3.0.0
[info] Benchmark Mode Cnt Score Error Units
[info] Test.slickDelete thrpt 2 0,008 ops/ms
[info] Test.slickInsertBatch thrpt 2 0,086 ops/ms
[info] Test.slickInsertSeparate thrpt 2 0,056 ops/ms
[info] Test.slickQuery thrpt 2 0,009 ops/ms
[info] Test.slickUpdate thrpt 2 0,010 ops/ms
[info] Test.srDelete thrpt 2 2,460 ops/ms
@tindzk
tindzk / Monokai.colorscheme
Last active November 23, 2015 23:22 — forked from wdullaer/Monokai.colorscheme
Monokai Konsole Colourscheme
[Background]
Color=40,40,40
[BackgroundIntense]
Color=40,40,40
[Color0]
Color=73,72,62
[Color0Intense]
> publishSigned
[info] Packaging /Users/tim/dev/widok/target/scala-2.10/root_2.10-0.1-SNAPSHOT-sources.jar ...
[info] Updating {file:/Users/tim/dev/widok/}root...
[info] Done packaging.
[info] Wrote /Users/tim/dev/widok/js/target/scala-2.11/widok_sjs0.6_2.11-0.2.0-SNAPSHOT.pom
[info] Wrote /Users/tim/dev/widok/jvm/target/scala-2.11/widok_2.11-0.2.0-SNAPSHOT.pom
[info] Wrote /Users/tim/dev/widok/target/scala-2.10/root_2.10-0.1-SNAPSHOT.pom
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
@tindzk
tindzk / existential-types.scala
Created February 15, 2015 15:53
Type mismatch when casting generic parameter to an existential type
trait A[T] { def print(t: T) }
trait B[T] { def ret: T }
case class Wrapper[T](a: A[T], b: B[T])
val wrapper = Wrapper[String](null, null)
wrapper.a.print(wrapper.b.ret) /* Compiles */
val anyWrapper = wrapper.asInstanceOf[Wrapper[_]]
anyWrapper.a.print(wrapper.b.ret) /* Does not compile */
@tindzk
tindzk / upickle-error2.scala
Created January 16, 2015 18:14
uPickle: Declarations in method
def main(args: Array[String]) {
sealed trait Base
case object Child extends Base
case class Wrapper(t: Base)
val x = upickle.read[Wrapper](null)
}
// Main.scala:23: uPickle does not know how to read [Wrapper]s; define an implicit Reader[Wrapper] to teach it how