Skip to content

Instantly share code, notes, and snippets.

View joost-de-vries's full-sized avatar

Joost de Vries joost-de-vries

View GitHub Profile
@joost-de-vries
joost-de-vries / scalap.sbt
Last active August 29, 2015 14:15 — forked from xuwei-k/scalap.sbt
run scalap for your project from sbt
scalaVersion := "2.11.4"
libraryDependencies += "org.scala-lang" % "scalap" % scalaVersion.value
InputKey[Unit]("scalap") := {
import complete.DefaultParsers._
val classes = spaceDelimited("<class names>").parsed
val pathSeparator = java.lang.System.getProperty("path.separator")
val classpath = "-classpath" :: (fullClasspath in Compile).value.map(_.data).mkString(pathSeparator) :: Nil
val args = "-verbose" :: classpath ::: classes.toList
@joost-de-vries
joost-de-vries / gist:98e73078dead633fb219
Last active August 29, 2015 14:15
Rough experience using Slick?

This Gist is related to the article The Rough Experience with Slick which points out performance problems with a Slick DSL query with 3 joins. The article is discussed on Linkedin and in the Slick newsgroup

I've tried this query on Slick 3.0M1 for Postgresql. The query that uses the join DSL expression

val salesQuery = {
    val salesJoin = sales join purchasers join products join suppliers on {
      case (((sale, purchaser), product), supplier) =>
        sale.productId === product.id &&
          sale.purchaserId === purchaser.id &&

The example of John de Goes' Haskell's Type Classes: We Can Do Better written in Scala.
It is precisely to allow for multiple type class implementations that Scala uses implicits to implement them. So I thought it would be interesting to compare Scala and Haskell here.

Discussion on HN

object MonoidInt{
  implicit val MonoidPlus = new Monoid[Int] {
    def empty = 0
    def append(v1: Int, v2: Int) = v1 + v2
 }
Installeer de volgende tools als je die nog niet hebt:
- java 8
- [sbt](http://www.scala-sbt.org/download.html)
- Docker Machine
- je kunt prima met een teksteditor werken zoals sublime of atom. Als je liever met een IDE werkt: installeer Scala IDE (variant van Eclipse) of IntelliJ (Community werkt ook) met de Scala plugin.
Maak een github account aan als je die nog niet hebt en stuur de handle naar mijn email. Dan voeg ik je toe aan onze repo.

Because sbt-typescript uses the standard tsconfig.json file for configuration it is possible to compile using both sbt-typescript and tsc. I use this mostly to have my IDE (IntelliJ) signal type errors early while I'm typing. To do that I only have to check 'enable typescript compiler' and 'use tsconfig.json'. Similarly you can run tsc -p -w from the commandline. The only downside is that you need to copy the right npm dependencies to node_modules from the directory in target/web/node_modules

public Mono<Void> gitterSlackRelay() {
ObjectMapper mapper = new ObjectMapper();
return create()
.get(gitterStreamUrl, gitterStreamHandler())
.flatMap(replies -> replies
.receiveByteArray()
.filter(b -> b.length > 2) // ignore gitter keep-alives (\r)
.map(b -> {
try {
return mapper.readValue(b, Map.class);
import {Observable} from "rxjs/Observable"
import {Subscriber} from "rxjs/Subscriber"
import {Operator} from "rxjs/Operator"
/**
* adds a 'debug' operator to rxjs/Observable
*
* example:
* import "./debug.observable"
import scala.concurrent.{ ExecutionContext, Future }
import scala.util.{ Failure, Success, Try }
import scala.util.control.NonFatal
/** the resulting exception when the until function becomes true */
class CanceledException extends Exception
/**
* A function that is comparable to Future.sequence.
* Future.sequence processes in parallel and in case of failure it returns only the failure.
@joost-de-vries
joost-de-vries / rsFromActor.scala
Last active January 10, 2017 14:03
Create a Reactive Streams Publisher from an actor
def scheduledPublisher(buffer: Int, initialDelay: FiniteDuration, interval: FiniteDuration)(
implicit actorSystem: ActorSystem): Publisher[Unit] = {
val actorSource = Source.actorRef[Unit](50, OverflowStrategy.fail)
val (actorRef, publisher) = actorSource.toMat(Sink.asPublisher(fanout = false))(Keep.both).run()
actorSystem.scheduler.schedule(initialDelay, interval, actorRef, ())
publisher
}
Caused by: swave.core.UnclosedStreamGraphException: Unconnected Port in MapStage@15faa2dd/awaitingOnSubscribe
at swave.core.impl.stages.StageImpl._xSeal(StageImpl.scala:313)
at swave.core.impl.stages.inout.MapStage._xSeal(MapStage.scala:16)
at swave.core.impl.stages.StageImpl.xSeal(StageImpl.scala:291)
at swave.core.impl.stages.inout.NopStage._xSeal(NopStage.scala:15)
at swave.core.impl.stages.StageImpl.xSeal(StageImpl.scala:291)
at swave.core.impl.stages.inout.MapStage._xSeal(MapStage.scala:16)
at swave.core.impl.stages.StageImpl.xSeal(StageImpl.scala:291)
at swave.core.impl.stages.drain.PublisherDrainStage._xSeal(PublisherDrainStage.scala:20)