Skip to content

Instantly share code, notes, and snippets.

View agemooij's full-sized avatar

Age Mooij agemooij

View GitHub Profile

Keybase proof

I hereby claim:

  • I am agemooij on github.
  • I am agemooij (https://keybase.io/agemooij) on keybase.
  • I have a public key ASDPU5iVgOTv_dmHI-Xf0la16UWZkfd8qxbb_YU3j1zkIAo

To claim this, I am signing this object:

@agemooij
agemooij / blue-green.groovy
Created February 21, 2017 09:46 — forked from klingerf/blue-green.groovy
Jenkins pipeline script to perform blue-green deploys to a Kubernetes cluster running linkerd and namerd
node {
def currentVersion = getCurrentVersion()
def newVersion = getNextVersion(currentVersion)
def frontendIp = kubectl("get svc l5d -o jsonpath=\"{.status.loadBalancer.ingress[0].ip}\"").trim()
def originalDst = getDst(getDtab())
stage("clone") {
git url: gitRepo + '.git', branch: gitBranch
}
@agemooij
agemooij / customformat.scala
Last active November 28, 2022 13:50
More advanced example of a custom spray-json format
implicit object ProductItemFormat extends RootJsonFormat[ProductItem] {
// some fields are optional so we produce a list of options and
// then flatten it to only write the fields that were Some(..)
def write(item: ProductItem) = JsObject(
List(
Some("product_number" -> item.productNumber.toJson),
item.ean.map(ean ⇒ "ean" -> ean.toJson),
Some("title" -> item.title.toJson),
item.description.map(description ⇒ "description" -> description.toJson),
Some("price" -> item.price.toJson),
@agemooij
agemooij / agnoster-agemooij.zsh-theme
Last active December 6, 2017 18:43
Customized version of the Agnoster @ohmyzsh theme
# vim:ft=zsh ts=2 sw=2 sts=2
#
# Age's version of Agnoster's Theme - https://gist.github.com/3712874
# A Powerline-inspired theme for ZSH
#
# # README
#
# In order for this theme to render correctly, you will need a
# [Powerline-patched font](https://github.com/Lokaltog/powerline-fonts).
#
@agemooij
agemooij / NormalizeSupport.scala
Last active September 22, 2022 11:02
Scala text normalization
package rfs.rebb
package common
/**
* Performs standard Java/unicode normalization on the trimmed and lowercased form
* of the input String and then adds a few extra tricks for dealing with special
* characters.
*
* JVM/Unicode normalization references (warning: learning curve black hole, beware!):
*
@agemooij
agemooij / README.md
Last active July 29, 2016 21:36
My SBT prompt config

My customized SBT shell prompt

Example screenshot

A heavily customied SBT shell prompt that shows the following information:

  • a handy marker to show you are in SBT
  • the current Git status (a clean working directory is green, a dirty one is yellow)
  • the current project, including the root project of a multi-project build

Requirements

@agemooij
agemooij / HttpsDirectives.scala
Last active April 15, 2020 23:21
Spray HttpDirectives
package scalapenos.spray.auth
import spray.routing._
import spray.routing.Directives._
import spray.http.HttpHeaders._
import spray.http.StatusCodes._
trait HttpsDirectives {
import HttpsDirectives._
def addItem(newItem: BasketItem): BasketState = {
copy(
items.foldRight((false, List.empty[BasketItem])) {
case (item, (_, out)) if (item.matchesProductAndSizeOf(newItem)) ⇒ (true, item.incrementNumberBy(newItem.numberOfProducts) :: out)
case (item, (didSomethingMatch, out)) ⇒ (didSomethingMatch, item :: out)
} match {
case (false, _) ⇒ newItem :: items
case (true, modifiedItems) ⇒ modifiedItems
}
)
@agemooij
agemooij / S3Signing.scala
Created June 6, 2014 20:07
Snippet from an S3 download/upload client based purely on spray-client
/**
* Amazon S3 uploads and downloads need to have an authorization header containing a signature based on a very specific formatting
* of several of the headers of the HTTP request. This method only implements the parts that are required for our use cases,
* thus very specific situations like headers spanning multiple lines are not supported.
* For the details of the string-to-sign that is constructed see http://docs.aws.amazon.com/AmazonS3/latest/dev/RESTAuthentication.html?r=1821
*/
def signAwsRequest(method: String, dateString: String, contentType: String, bucket: String, resource: String, amzHeaders: List[HttpHeader] = List.empty[HttpHeader], contentMd5: String = ""): String = {
val bucketResource = s"/$bucket$resource"
val signableAmzHeaders = amzHeaders.sortBy(_.name).map { header ⇒
@agemooij
agemooij / 1. README.md
Last active September 26, 2018 13:19
Quick spray-routing authentication example

Extremely bare example of Spray routing authentication using session cookies and XSRF tokens

This code was quickly ripped out of an active project to serve as an example. It will not compile in any way!

Any questions? Add them to the comments!

Notes

  • the application uses a version of the cake pattern to compose the Spray routing application together from various traits
  • a lot of those traits should be pretty self-explaining based on their name but if requested I can paste them into this Gist