Skip to content

Instantly share code, notes, and snippets.

View Slakah's full-sized avatar

James Collier Slakah

View GitHub Profile
@Slakah
Slakah / build.sbt
Created March 31, 2015 10:22
To make gatling use the JAVA_OPTS environment variable for ssl settings, copy this into your build.sbt
// Copy JVM ssl settings to be used by gatling
val systemProps = new SystemProperties
javaOptions in Runtime ++= Seq(
mirrorProperty("javax.net.ssl.trustStore", "gatling.http.ssl.trustStore.file"),
mirrorProperty("javax.net.ssl.trustStorePassword", "gatling.http.ssl.trustStore.password"),
mirrorProperty("javax.net.ssl.keyStore", "gatling.http.ssl.keyStore.file"),
mirrorProperty("javax.net.ssl.keyStoreType", "gatling.http.ssl.keyStore.type"),
mirrorProperty("javax.net.ssl.keyStorePassword", "gatling.http.ssl.keyStore.password")
).flatten
@Slakah
Slakah / redis-playground.sh
Created October 18, 2017 08:43
Redis Playground
#! /bin/bash
set -uxe
# Runs a redis instance, and connects via redis-cli
docker stop redis-playground || true
docker rm redis-playground || true
docker run --name redis-playground -d redis
exec docker run -it --link redis-playground:redis --rm redis redis-cli -h redis -p 6379
@Slakah
Slakah / gsheets-crypto-price.js
Last active January 5, 2018 16:40
Fetch crypto prices using cryptocompare api (includes retries and caching)
// #loljavascript
var settings = {
cacheExpiresSec: 10,
extraParams: "&extraParams=your-id-here", // enter your id here
retry: {
factor: 2,
max: 5,
maxRetries: 5,
},
@Slakah
Slakah / ssm-to-env.sh
Created May 14, 2018 10:20
Convert AWS SSM parameters to environment variables, used as `eval $(./ssm-to-env.sh "<ssm-path>")`
#!/bin/bash
set -uxe
# Reads the ssm path and echos out the parameters in the form
# export NAME=some-value
readonly path=$1
exec aws --region us-east-1 ssm get-parameters-by-path --no-paginate --path $path --with-decryption --query Parameters | \
jq -r 'map("\(.Name | sub("'$path'";""))=\(.Value)") | join("\n")' | \
@Slakah
Slakah / encrypt-decrypt-usage.sh
Last active January 4, 2020 20:40
Encrypt plaintext using an kms encrypted data key, and the inverse decrypt is also supported.
# This guide outlines how to:
# 1. Generate a AWS KMS data key (https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#data-keys).
# 2. Encrypt a secret using the generated data key.
# 3. Decrypt the encrypted secret.
# generate a kms data key
aws kms generate-data-key-without-plaintext \
--key-id <key-id> \
--key-spec AES_256 \
@Slakah
Slakah / arbitrary-play-json.scala
Created June 20, 2018 13:39
Scalacheck arbitrary generators for play-json (https://github.com/playframework/play-json)
import org.scalacheck._
import play.api.libs.json._
val genJsArray: Gen[JsArray] =
for {
n <- Gen.chooseNum(0, 10)
arr <- Gen.containerOfN[IndexedSeq, JsValue](n, genJsValue).map(JsArray)
} yield arr
val genJsObject: Gen[JsObject] =
@Slakah
Slakah / aws-assume-role-env.sh
Last active July 31, 2018 14:26
Assume a AWS STS role using the AWS credentials environment variables
#!/bin/bash
set -ue
readonly roleArn="$1"
readonly durationSeconds="3600" # 1 hours
readonly roleSessionName="$USER-local"
# Use default profile to log in
unset AWS_ACCESS_KEY_ID
unset AWS_SECRET_ACCESS_KEY
@Slakah
Slakah / tag-release.sc
Created July 11, 2018 14:41
Bump a git tag using by specifying major, minor, patch. This will also output the commits since the last tag.
#!/usr/bin/env amm
import ammonite.ops._, ImplicitWd._
case class Version(major: Int, minor: Int, patch: Int, label: String) {
def tag = s"v$major.$minor.$patch$label"
}
def parseVersion(s: String) = {
val VersionPattern = "^v(\\d+).(\\d+).(\\d+)(-.+)?$".r
val VersionPattern(major, minor, patch, labelNullable) = s
@Slakah
Slakah / cats-in-ammonite.sc
Created July 16, 2018 13:56
How to use cats in ammonite
import $ivy.{
`org.typelevel::cats-effect:1.0.0-RC2`,
`org.typelevel::cats-core:1.1.0`
}
val scalacOptions = List("-Ypartial-unification")
interp.preConfigureCompiler(_.processArguments(scalacOptions, true))
// reload compiler
@
@Slakah
Slakah / HttpCaching.scala
Created August 27, 2018 12:42
http4s caching middleware
package com.gubbns
import cats.data.{Kleisli, OptionT}
import cats.effect._
import cats.implicits._
import com.github.blemale.scaffeine.{Cache, Scaffeine}
import org.http4s._
import org.http4s.headers._
import org.http4s.server.Middleware