This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Play Json only supports Map[String,V]. This function creates a format for Map[K,V]. The type K should produce a JsString. | |
* Otherwise the serialisation will fail. Which is good enough since in valid json keys can only be strings. */ | |
def mapFormat[K, V](implicit fk: Format[K], fv: Format[V]): Format[Map[K, V]] = new OFormat[Map[K, V]] { | |
override def writes(o: Map[K, V]): JsObject = { | |
val stringMap = o.map { case (k, v) => (Json.toJson[K](k).as[JsString].value, v) } | |
Json.toJson(stringMap).as[JsObject] | |
} | |
override def reads(json: JsValue): JsResult[Map[K, V]] = { | |
for { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
slick { | |
dbs { | |
default { | |
driver = "slick.driver.PostgresDriver$" | |
db { | |
driver = "org.postgresql.Driver" | |
url = ${rds.url} | |
user = ${rds.username} | |
password = ${rds.password} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package shared | |
import swave.core.{Pipe, Spout, StreamOps} | |
import scala.concurrent.{ExecutionContext, Future} | |
object StreamingUtil { | |
import scala.language.higherKinds | |
implicit class ContinueAfter[T, S[X] <: StreamOps[X]](val underlying: S[T]) extends AnyVal { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import swave.core.{Coupling, Spout, StreamEnv, UnterminatedSynchronousStreamException} | |
import scala.concurrent.{Await, Future, TimeoutException} | |
import scala.concurrent.duration._ | |
import scala.util.{Success, Try} | |
trait MyEvent | |
class EventA extends MyEvent |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Pretty prints a Scala value similar to its source represention. | |
* Particularly useful for case classes. | |
* @param a - The value to pretty print. | |
* @param indentSize - Number of spaces for each indent. | |
* @param maxElementWidth - Largest element size before wrapping. | |
* @param depth - Initial depth to pretty print indents. | |
* @return | |
*/ | |
object PrettyPrint { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |