This file contains 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
// scala task magnet for akka http | |
implicit def taskMagnet[T](task: => Task[T]) | |
(implicit tupler: Tupler[T]) = new OnSuccessMagnet { | |
type Out = tupler.Out | |
val directive = OnSuccessMagnet(task.runStdFuture()).directive | |
} |
This file contains 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
#!/bin/bash | |
set -e | |
HPN_DOCKER_HOST=`/sbin/ip route | awk '/default/ { print $3 }'` | |
echo "$HPN_DOCKER_HOST docker" >> /etc/hosts | |
# exec ... |
This file contains 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 scalatags.Text.all._ | |
object nl2br { | |
def apply(s: String): Modifier = { | |
val lines = s.replaceAllLiterally("\r\n", "\n").replaceAllLiterally("\r", "\n").split('\n') | |
lines.foldLeft(None: Option[Modifier]) { case (step, line) => | |
Some(step.fold[Modifier](line)(previous => Vector[Modifier](previous, br, line))) | |
}.getOrElse("") | |
} |
This file contains 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
/* | |
name := "bug" | |
version := "1.0" | |
organization := "com.github.longshorej" | |
libraryDependencies ++= Seq( | |
"com.typesafe.akka" %% "akka-http-experimental" % "1.0" | |
) |
This file contains 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
// sbt dependencies: shapeless and org.reflections.reflections | |
val reflections = new Reflections("org.example") | |
def findAllObjects[T](cl: Class[T])(implicit t: Typeable[T]): Vector[T] = { | |
reflections.getSubTypesOf(cl).toVector.flatMap(cl => cl.getField("MODULE$").get(null).cast[T]) | |
} | |
findAllObjects(classOf[com.hpn.wms2.core.common.ClientDef]).foreach(println) |
This file contains 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 com.hpn.libs.akka.http | |
// no time to properly open source, but maybe this someone finds this useful. It's used | |
// as part of our graceful shutdown logic for akka HTTP | |
import akka.http.scaladsl.model._ | |
import akka.stream._ | |
import akka.stream.stage._ | |
import java.util.concurrent.atomic.AtomicLong |
This file contains 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 threaded(numThreads: Int)(block: => Unit) = { | |
val threads = for (n <- 1 to numThreads) yield new Thread(new Runnable { | |
def run() = block | |
}) | |
threads foreach (_.start()) | |
} |
This file contains 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 time[A](f: => A) = { | |
val s = System.nanoTime | |
val ret = f | |
println("time: "+(System.nanoTime-s)/1e6+"ms") | |
ret | |
} | |
def timeAvg[A](avg: Int)(f: => A) = { | |
val s = System.nanoTime |
NewerOlder