Skip to content

Instantly share code, notes, and snippets.

View johanandren's full-sized avatar
👻
hakking

Johan Andrén johanandren

👻
hakking
View GitHub Profile
### Keybase proof
I hereby claim:
* I am johanandren on github.
* I am johanandren (https://keybase.io/johanandren) on keybase.
* I have a public key whose fingerprint is 06BA 5A56 D804 4A25 E78C 76A1 14C5 61AB C73E 8B6F
To claim this, I am signing this object:
import akka.actor.{ActorSystem, ActorRef}
import akka.pattern.ask
import akka.pattern.AskTimeoutException
import akka.util.Timeout
import scala.concurrent.Future
import scala.concurrent.duration._
import scala.io.StdIn
object AskWithRetry extends App {
import akka.actor.Actor.Receive
import akka.actor._
import akka.cluster.Cluster
import akka.remote.RemoteScope
import com.typesafe.config.ConfigFactory
import scala.concurrent.Await
import scala.concurrent.duration.Duration
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 / 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 / addressbook.js
Created April 10, 2013 12:51
Min måttligt ambitiösa adressbok för mejslas JavaScript-cirkel 2013
// redefine read so that it returns strings
read = (function() {
var oldRead = read
return function(prompt) {
return oldRead(prompt) + "";
}
})();
// show a menu based on a input list of menu items
// menuItems: [{ key: 'K', action: function, desc: 'Description' }, ...]
@johanandren
johanandren / gist:5361674
Created April 11, 2013 08:20
A version of Tomasz Nurkiewicz (http://nurkiewicz.blogspot.se/2013/04/watchservice-combined-with-akka-actors.html) file system watch actor without using an extra thread and instead poll the watch service from the actor at regular intervals.
package markatta
import java.nio.file._
import java.nio.file.StandardWatchEventKinds._
import java.nio.file.attribute.BasicFileAttributes
import collection.JavaConversions._
import concurrent.duration._
import akka.actor.{Cancellable, ActorRef, Actor}
import markatta.FileSystemWatchActor._
@johanandren
johanandren / gist:6547569
Created September 13, 2013 07:14
Different handling for diferent kinds of images
trait ImageResource {
def publicUrl: String
}
case class URLImage(source: URL) extends ImageResource {
def publicUrl = source.url
}
case class CDNImage(bucketName: String, key: String, cdnBaseUrl: String) extends ImageResource {
lazy val cdnUrl = URL(cdnBaseUrl) :+ key
@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 / 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 {