Skip to content

Instantly share code, notes, and snippets.

@jrudolph
jrudolph / branch-targets.sbt
Last active August 29, 2015 14:25
Setup per-branch target directories in sbt
// Helper snippet to enable per-git-branch target directories
//
// This will move the target directory for a sub-module away
// from <project-root>/<sub-module-name>/target
// to <project-root>/per-branch-targets/<branch-name>/<sub-module-name>
//
// Why?: shorter wait times if you switch branches often enough
// (Example: Akka's project file take 20+ seconds to compile and
// a single line change in AkkaBuild.scala will always
// trigger a complete rebuild.)
@jrudolph
jrudolph / analysis.txt
Last active November 2, 2016 05:46
Release Train for 2.12.0-M3
TargetVersion: Scala 2.12.0-M3 LastVersion: Scala 2.11
25 libraries available for Scala 2.12.0-M3 (see the end for sbt config lines)
akka-actor 3 versions: 2.4.3, 2.4.2, 2.4.1
akka-stream 2 versions: 2.4.3, 2.4.2
akka-http 2 versions: 2.4.3, 2.4.2
akka-osgi 3 versions: 2.4.3, 2.4.2, 2.4.1
akka-slf4j 3 versions: 2.4.3, 2.4.2, 2.4.1
akka-testkit 3 versions: 2.4.3, 2.4.2, 2.4.1
scala-xml 1 versions: 1.0.5
@jrudolph
jrudolph / TestMultipartFileUpload.scala
Last active February 13, 2023 18:09
akka-http Multipart file-upload client + server example
package akka.http.scaladsl
import java.io.File
import akka.http.scaladsl.unmarshalling.Unmarshal
import akka.util.ByteString
import scala.concurrent.duration._
import akka.actor.ActorSystem
@jrudolph
jrudolph / WhatScalaGenerates.scala
Created April 29, 2015 06:35
ParameterDirectives
// generated using a simple showTree macro:
parameter("name") // expands to:
parameters(directives.this.ParamDefMagnet.apply[String]("name")(directives.this.ParamDefMagnet2.forString(unmarshalling.this.Deserializer.liftToSourceOption[String, String](unmarshalling.this.Deserializer.fromFunction2Converter[String, String](scala.this.Predef.$conforms[String])))))
parameter("name", "address") // expands to (shapeless 1):
parameters(directives.this.ParamDefMagnet.apply[(String, String)](scala.Tuple2.apply[String, String]("name", "address"))(directives.this.ParamDefMagnet2.forTuple[(String, String), shapeless.::[String,shapeless.::[String,shapeless.HNil]], this.Out](shapeless.this.HListerAux.tupleHLister2[String, String], directives.this.ParamDefMagnet2.forHList[shapeless.::[String,shapeless.::[String,shapeless.HNil]]](shapeless.this.LeftFolder.leftFolder[shapeless.::[String,shapeless.::[String,shapeless.HNil]], spray.routing.Directive0, spray.routing.directives.ParamDefMagnet2.MapReduce.type, this.R](shapeless
@jrudolph
jrudolph / ClientFileUpload.scala
Created February 11, 2015 09:52
spray file upload example
import akka.actor.ActorSystem
import spray.client.pipelining._
import spray.http.{MediaTypes, BodyPart, MultipartFormData}
object UploadFileExample extends App {
implicit val system = ActorSystem("simple-spray-client")
import system.dispatcher // execution context for futures below
val pipeline = sendReceive
val payload = MultipartFormData(Seq(BodyPart(new File("/tmp/test.pdf"), "datafile", MediaTypes.`application/pdf`)))
@jrudolph
jrudolph / trace.log
Created December 19, 2014 13:02
Akka HttpServer trace
> 01 0 0 flow-1-1-map got ExposedPublisher
< 01 0 0 flow-1-1-map got ExposedPublisher
> 02 0 0 flow-1-1-map got SubscribePending$
< 02 0 0 flow-1-1-map got SubscribePending$
> 01 0 0 flow-1-2-1-foreach-stageFactory got ExposedPublisher
< 01 0 0 flow-1-2-1-foreach-stageFactory got ExposedPublisher
> 02 0 0 flow-1-2-1-foreach-stageFactory got SubscribePending$
< 02 0 0 flow-1-2-1-foreach-stageFactory got SubscribePending$
> 03 0 0 flow-1-2-1-foreach-stageFactory got OnSubscribe
< 03 0 0 flow-1-2-1-foreach-stageFactory got OnSubscribe
object Tcp {
trait ConnectionDescriptor {
def remoteAddress: InetSocketAddress
def localAddress: InetSocketAddress
}
sealed trait ConnectionFlow extends Flow[ByteString, ByteString] {
def remoteAddress(mMap: MaterializedMap): InetSocketAddress
def localAddress(mMap: MaterializedMap): InetSocketAddress
@jrudolph
jrudolph / type-test.scala
Created October 25, 2014 09:36
Getting return types of methods without actually calling them
import scala.reflect.{ classTag, ClassTag }
trait X {
def f: Seq[Int]
}
trait Getter[T] {
def apply[U: ClassTag, C[_]](f: T ⇒ C[U]): ClassTag[U] = implicitly[ClassTag[U]]
}
object Getter extends Getter[Any]
@jrudolph
jrudolph / CVE-2014-6271.md
Last active August 29, 2015 14:06
CVE-2014-6271

CVE-2014-6271

Environment variables

On a UNIX system there are two main ways of passing arguments from a parent to a child process when spawning a new process:

  • the command line: a string that is usually given explicitly by the user
  • the environment: a set of key/value pairs that is inherited from the parent process implicitly but that can also be modified explicitly when starting a process

(You can observe the values of the command line and the environment by looking at /proc/<pid>/cmdline and /proc/<pid>/environ.)

@jrudolph
jrudolph / sets.scala
Created September 8, 2014 11:52
Not so covariant sets
scala> class MySet[T](elements: Seq[T])(implicit ordering: Ordering[T]) extends scala.collection.immutable.Set[T] {
| // Members declared in scala.collection.GenSetLike
| def iterator: Iterator[T] = elements.iterator
|
| // Members declared in scala.collection.SetLike
| def -(elem: T): scala.collection.immutable.Set[T] = ???
| def +(elem: T): scala.collection.immutable.Set[T] = ???
|
| def contains(t: T): Boolean = elements.exists(ordering.equiv(t, _))
| }