Skip to content

Instantly share code, notes, and snippets.

View johanandren's full-sized avatar
👻
hakking

Johan Andrén johanandren

👻
hakking
View GitHub Profile
import akka.actor.{Actor, ActorSystem, Props}
import akka.http.scaladsl.Http
import akka.http.scaladsl.marshalling._
import akka.http.scaladsl.server.Directives._
import akka.stream.ActorMaterializer
import http.ActorPerRequest.RequestHandler.Handle
import scala.io.StdIn
@johanandren
johanandren / UdpRemoting
Created August 3, 2016 12:25
Non-working minimal udp remoting sample
package remoting
import akka.actor.{Actor, ActorLogging, ActorSystem, Props}
import com.typesafe.config.ConfigFactory
import scala.io.StdIn
/**
* Created by johan on 2016-08-03.
*/
@johanandren
johanandren / SimplePartitionSample.scala
Created July 26, 2016 08:25
Sample of using partition to split up incoming elements over multiple outgoing streams
import akka.actor.ActorSystem
import akka.stream._
import akka.stream.scaladsl._
import scala.io.StdIn
import scala.util.Random
object SimplePartitionSample extends App {
implicit val system = ActorSystem()
@johanandren
johanandren / GracefulLeaveCluster.scala
Created June 7, 2016 09:41
Simple self-contained two-node-cluster app
import akka.actor._
import akka.cluster.{Cluster, MemberStatus}
import com.typesafe.config.ConfigFactory
import scala.concurrent.Await
import scala.concurrent.duration._
import scala.io.StdIn
object GracefulLeaveCluster extends App {
@johanandren
johanandren / ActorMaterializerSettingsApp.scala
Created May 20, 2016 14:55
Does the stages inherit the materializer strategy?
package streams
import akka.actor.ActorSystem
import akka.stream.ActorAttributes.SupervisionStrategy
import akka.stream.Supervision.Resume
import akka.stream._
import akka.stream.scaladsl.Source
import akka.stream.stage.{GraphStage, GraphStageLogic}
object ActorMaterializerSettingsApp extends App {
@johanandren
johanandren / Intersperse.scala
Created December 3, 2015 15:46
Naive intersperse implementation
import akka.stream.FlowShape
import akka.stream.scaladsl.FlowGraph
import akka.stream.scaladsl.{Source, Concat, Flow}
import akka.stream.stage.{SyncDirective, Context, PushPullStage}
object Intersperse {
def apply[E](separator: E): Flow[E, E, Unit] =
Flow[E].transform(() => new Intersperse[E](separator))
@johanandren
johanandren / SimpleClient.scala
Created December 3, 2015 07:39
Minimal example showing request api and unmarshalling response body to a string
import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.model._
import akka.http.scaladsl.unmarshalling._
import akka.stream.ActorMaterializer
import scala.concurrent.{Await, Future}
import scala.concurrent.duration._
object SimpleClient {
@johanandren
johanandren / SimpleFileUpload.scala
Created December 2, 2015 17:29
Example of accepting a file via post
import java.io.File
import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.server.Directives._
import akka.stream.ActorMaterializer
import akka.stream.scaladsl.{Sink, Source}
import scala.io.StdIn
import akka.actor.ActorSystem
import akka.http.scaladsl._
import akka.http.scaladsl.model.{HttpMethods, Uri, HttpRequest}
import akka.stream.ActorMaterializer
import scala.concurrent.duration._
import scala.concurrent.Await
object Bug18797 {
def main(args: Array[String]): Unit = {
@johanandren
johanandren / ClusteredRoundRobinPool.scala
Created September 9, 2015 14:30
Simple sample with clustered round robin pool
import akka.actor.{Actor, ActorLogging, ActorSystem, Props}
import akka.cluster.Cluster
import akka.routing.FromConfig
import com.typesafe.config.ConfigFactory
import scala.concurrent.{Await, Future}
import scala.io.StdIn
object ClusteredRoundRobinPool extends App {