Skip to content

Instantly share code, notes, and snippets.

View adamw's full-sized avatar

Adam Warski adamw

View GitHub Profile
package com.softwaremill.mqperf
import com.softwaremill.mqperf.config.TestConfigOnS3
import com.softwaremill.mqperf.mq.Mq
object Receiver extends App {
new TestConfigOnS3().whenChanged { testConfig =>
println(s"Starting test (receiver) with config: $testConfig")
val mq = Mq.instantiate(testConfig)
package com.softwaremill.mqperf.mq
import com.amazonaws.services.sqs.buffered.AmazonSQSBufferedAsyncClient
import com.amazonaws.services.sqs.AmazonSQSAsyncClient
import scala.collection.JavaConverters._
import com.amazonaws.services.sqs.model.{DeleteMessageRequest, ReceiveMessageRequest, SendMessageBatchRequestEntry}
import com.softwaremill.mqperf.config.AWSCredentialsFromEnv
import com.amazonaws.regions.{Region, Regions}
class SqsMq(configMap: Map[String, String]) extends Mq {
val serverLocator = {
val nettyParams = new java.util.HashMap[String, Object]()
nettyParams.put(TransportConstants.HOST_PROP_NAME, "localhost")
nettyParams.put(TransportConstants.PORT_PROP_NAME, "5445")
val sl = HornetQClient.createServerLocatorWithHA(
new TransportConfiguration(classOf[NettyConnectorFactory].getName, nettyParams))
sl.setConfirmationWindowSize(1048576)
@adamw
adamw / gist:46c6550a6444156b434e
Last active August 29, 2015 14:10
Classifiers in MacWire
/*
A proposition on how classifiers can be implemented in MacWire. Based on @milessabin's https://gist.github.com/milessabin/89c9b47a91017973a35f
*/
// Infrastructure: would come in the library
// note that no changes in the macro are necessary. The qualifiers are purely type-based
type Tag[U] = { type Tag = U }
type @@[T, U] = T with Tag[U]
type Tagged[T, U] = T with Tag[U]
implicit class Tagger[T](t: T) {
@adamw
adamw / gist:5f68795f90b34abf7df1
Last active August 29, 2015 14:11
Supler actions
def carForm(removeAction: Car => ActionResult[Car]) = form[Car](f => List(
f.field(_.make).possibleValues(_ => carMakesAndModels.keys.toList).label("Make"),
// etc.
// trait Form[T] { def action(T => ActionResult[T]): Row[T] }
f.action(removeAction).label("Delete")
))
val personForm = form[Person](f => List)
f.field(_.firstName).label("label_person_firstname"),
// etc.
new SuplerForm(document.getElementById("container"), {
field_options: {
"age": {
// define render hint on frontend
"render_hint": "number"
},
"dateOfBirth": {
"after_render": function(inputElement, containerElement) {
$(inputElement).datepicker();
}
import akka.actor.{Props, ActorSystem, Actor}
import akka.pattern.ask
import akka.util.Timeout
import scala.concurrent.duration._
object Testing extends App {
case class Inc(n: Int)
class CounterActor extends Actor {
private var state = 0
@adamw
adamw / log.scala
Last active May 10, 2021 09:33
Logging request duration, path, status code using Akka HTTP
val rejectionHandler = RejectionHandler.default
def logDuration(inner: Route): Route = { ctx =>
val start = System.currentTimeMillis()
// handling rejections here so that we get proper status codes
val innerRejectionsHandled = handleRejections(rejectionHandler)(inner)
mapResponse { resp =>
val d = System.currentTimeMillis() - start
logger.info(s"[${resp.status.intValue()}] ${ctx.request.method.name} ${ctx.request.uri} took: ${d}ms")
resp
}(innerRejectionsHandled)(ctx)
Dec 04 08:14:57: 04/Dec/15 07:14:56.764 [app-akka.actor.default-dispatcher-6498] ERROR akka.stream.impl.fusing.ActorGraphInterpreter - Error during postStop in [akka.http.impl.engine.server.HttpServerBluePrint$WebsocketMerge@3e3fce20]
Dec 04 08:14:57: java.lang.IllegalArgumentException: requirement failed: Value wasn't set yet
Dec 04 08:14:57: at scala.Predef$.require(Predef.scala:219) ~[app.jar:0.1-SNAPSHOT]
Dec 04 08:14:57: at akka.http.impl.util.StreamUtils$OneTimeWriteCell.value(StreamUtils.scala:240) ~[app.jar:0.1-SNAPSHOT]
Dec 04 08:14:57: at akka.http.impl.engine.server.HttpServerBluePrint$$anon$7.installHandler(HttpServerBluePrint.scala:351) ~[app.jar:0.1-SNAPSHOT]
Dec 04 08:14:57: at akka.http.impl.engine.server.HttpServerBluePrint$$anonfun$apply$1$$anonfun$17.apply(HttpServerBluePrint.scala:142) ~[app.jar:0.1-SNAPSHOT]
Dec 04 08:14:57: at akka.http.impl.engine.server.HttpServerBluePrint$$anonfun$apply$1$$anonfun$17.apply(HttpServerBluePrint.scala:142) ~[app.jar:0.1-SNAPSHOT]
Dec 0
@adamw
adamw / windowing.scala
Created August 5, 2016 13:30
Windowing data in Akka
package com.softwaremill.akka
import java.time._
import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import akka.stream.scaladsl.Source
import scala.collection.mutable
import scala.concurrent.Await