Skip to content

Instantly share code, notes, and snippets.

@maciej
Last active November 30, 2015 08:50
Show Gist options
  • Select an option

  • Save maciej/20a5dbc967684f33cfc9 to your computer and use it in GitHub Desktop.

Select an option

Save maciej/20a5dbc967684f33cfc9 to your computer and use it in GitHub Desktop.
Snippets

Snippet collection

Various script and code snippets I collected or created

Docker

Remove all exited containers

docker ps -a | grep Exit | cut -d ' ' -f 1 | xargs docker rm

Removed unnamed images

docker images | grep '^<none>.*<none>' | sed -E 's/<none> +<none> +([0-9a-f]+).*/\1/' | xargs docker rmi

Scala

Aside from snippets, here are some useful links:

Akka Streams

Zip with index, similar to a combinator on Scala collections

Flow[E].zip(Source[Int](() => Iterator.from(0)))

or with a custom stage

def zipWithIndex[E]: Flow[E, (E, Int), Unit] = Flow[E].transform(() => new PushStage[E, (E, Int)] {
    private[this] var idx = 0
    override def onPush(elem: E, ctx: Context[(E, Int)]) = {
      val curIdx = idx
      idx += 1
      ctx.push(elem, curIdx)
    }
  })

Frame Source[ByteString, _] splitting strings by new line character (source):

Flow[ByteString]
    .via(Framing.delimiter(ByteString("\n"), maximumFrameLength = 256, allowTruncation = true))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment