Skip to content

Instantly share code, notes, and snippets.

@searler
searler / DecoderGather.scala
Created July 20, 2015 01:32
Self contained ByteString scodec decoder mechanism
import akka.util.ByteString
import scodec.Attempt.Successful
import scodec.DecodeResult
import scodec.Decoder
import scodec.bits.BitVector
class DecoderGather[R](decoder: Decoder[R]) {
private var bitBuffer = BitVector.empty
def apply(chunk: ByteString): Seq[R] = {
@searler
searler / Server.scala
Created July 19, 2015 22:11
Serialized TP server using Akka streams and actor to manage state
package io
import scala.concurrent.Future
import akka.actor.ActorRef
import akka.actor.ActorSystem
import akka.actor.FSM
import akka.actor.PoisonPill
import akka.actor.Props
import akka.stream.ActorMaterializer
import akka.stream.OverflowStrategy
@searler
searler / IOServer.scala
Created July 19, 2015 21:45
Serialized TCP Server using Akka IO
package io
import java.net.InetSocketAddress
import akka.actor.Actor
import akka.actor.ActorRef
import akka.actor.ActorSystem
import akka.actor.FSM
import akka.actor.Props
import akka.io.IO
@searler
searler / Server.scala
Created July 18, 2015 22:24
Serialized TCP server using Akka streams that accepts at most one client
package io
import scala.concurrent.Future
import akka.actor.ActorRef
import akka.actor.ActorSystem
import akka.actor.FSM
import akka.actor.PoisonPill
import akka.actor.Props
import akka.stream.ActorMaterializer
import akka.stream.OverflowStrategy
@searler
searler / FSMTCPClient.scala
Created July 18, 2015 20:58
Simple request/response TCP client using AKKA streams and FSM
package io
import scala.concurrent.duration.DurationInt
import scala.util.Success
import akka.actor.ActorRef
import akka.actor.ActorSystem
import akka.actor.FSM
import akka.actor.PoisonPill
import akka.actor.Props
@searler
searler / swimlane.html
Created July 9, 2015 02:06
d3 swimlane with data from server, keyboard scroll and tooltips
<html>
// derived from http://bl.ocks.org/bunkat/1962173
<head>
<title>Swimlane using d3.js</title>
<script src="./d3.js" charset="utf-8"></script>
<script src="http://labratrevenge.com/d3-tip/javascripts/d3.tip.v0.6.3.js"></script>
<style>
.chart {
shape-rendering: crispEdges;
}
@searler
searler / ScalaxbFuture.scala
Created July 8, 2015 02:58
Akka Future based HTTP client implementation of Scalaxb HttpClientsAsync
import scala.concurrent.Await
import scala.concurrent.Future
import scala.concurrent.duration.Duration
import scala.util.Try
import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.model.ContentType
import akka.http.scaladsl.model.HttpCharsets
import akka.http.scaladsl.model.HttpEntity.Strict
@searler
searler / BroadcastFilterMerge.scala
Created July 5, 2015 20:21
Illustrate fundamental structure on which Akka reactive stream switch could be implemented
package conditionals
import scala.collection.immutable.Seq
import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import akka.stream.scaladsl.Source
import scala.concurrent.Future
import akka.stream.scaladsl.Sink
import akka.stream.scaladsl.FlowGraph
import akka.stream.scaladsl.Broadcast
@searler
searler / sse.js
Created June 25, 2015 01:58
Generalize RxJs Observable over an EventStream, specifying event type
var rx = require('rx')
module.exports = {
/**
* This method wraps an EventSource as an observable sequence.
*
* Generalizes https://github.com/Reactive-Extensions/RxJS-DOM/blob/master/src/eventsource.js
* by allowing different Observables on the same EventSource, based on the event type.
*
* Copyright Microsoft Open Technologies
@searler
searler / ProtocolStacker.scala
Created June 21, 2015 19:47
Akka reactive streams Bidi example from documentation
/**
* Extracted from the Bidi example at http://doc.akka.io/docs/akka-stream-and-http-experimental/1.0-RC3/scala/stream-graphs.html
*/
package bidi
import akka.util.ByteString
import akka.stream.scaladsl.BidiFlow
import akka.stream.scaladsl.Flow
import akka.stream.BidiShape
import java.nio.ByteOrder