Skip to content

Instantly share code, notes, and snippets.

View optician's full-sized avatar
🦉

Danila Matveev optician

🦉
  • Yerevan, Armenia
View GitHub Profile
@optician
optician / Main.scala
Last active August 29, 2015 14:26
Akka-http client sample
(Source.single(request -> 42) via Http().superPool() map {
case (Success(res), flag) => res.entity.toStrict(1 seconds).map(x => new String(x.data.toArray))
case (Failure(err), flag) => Future.failed(err)
}).mapAsyncUnordered(2)(???)
val f = scala.io.Source.fromFile("jm.log")
def trunk(value: Double): Double = BigDecimal(value).setScale(2, BigDecimal.RoundingMode.HALF_UP).toDouble
def percentile(ms: Map[Long, Long], amount: Long, lvls: List[Int]): List[Long] = {
val ls = ms.toList.sortBy(x => x._1)
val lvlValues = lvls map (lvl => Math.ceil(amount*lvl/100f).toLong)
def search(a: Long, xs: List[(Long, Long)], lvlValue: Long): Long = xs match {
case v::xs if a+v._2 < lvlValue => search(a+v._2, xs, lvlValue)
case v::xs => v._1
@optician
optician / resj.scala
Created March 25, 2015 19:51
Read and extract stats from jmeter.log
val f = scala.io.Source.fromFile("jm.log")
def trunk(value: Double): Double = BigDecimal(value).setScale(2, BigDecimal.RoundingMode.HALF_UP).toDouble
def percentile(ms: Map[Long, Long], amount: Long, lvls: List[Int]): List[Long] = {
val ls = ms.toList.sortBy(x => x._1)
val lvlValues = lvls map (lvl => Math.ceil(amount*lvl/100f).toLong)
def search(a: Long, xs: List[(Long, Long)], lvlValue: Long): Long = xs match {
case v::xs if a+v._2 < lvlValue => search(a+v._2, xs, lvlValue)
case v::xs => v._1
case Event(newConnection: ActorRef, FSMData.Datum(challengeRef, channels, state)) =>
context.watch(newConnection)
newConnection ! CurrentState(stateName).json
stay() using FSMData.Datum(challengeRef, channels + newConnection, state)
@optician
optician / CommandsByMatch
Created January 24, 2015 04:56
One entry point for commands. "Match" variant.
class WebSocketActor(out: ActorRef) extends Actor {
def receive = {
case msg: JsValue => distributeCommands(msg)
}
def distributeCommands(req: JsValue): Unit = {
(req \ "command").asOpt[String] match {
case Some("get all accounts") => mock.getAllAccounts pipeTo out
case Some("add account") => mock.addAccount pipeTo out