Skip to content

Instantly share code, notes, and snippets.

Avatar

Stephen Nancekivell stephennancekivell

View GitHub Profile
View main.tf
terraform {
required_providers {
http = {
source = "terraform-aws-modules/http"
version = "2.4.1"
}
}
required_version = ">= 0.13"
}
View update-ip.sh
#!/usr/bin/env bash
IP=$(curl ifconfig.me)
echo "ip is $IP"
MSG="{
\"Changes\": [
{
\"Action\": \"UPSERT\",
\"ResourceRecordSet\": {
View gist:fb5a3113daa6d47a1350cc25721f386f
terraform apply
2020/02/18 15:58:02 [INFO] Terraform version: 0.12.13
2020/02/18 15:58:02 [INFO] Go runtime version: go1.12.9
2020/02/18 15:58:02 [INFO] CLI args: []string{"/usr/local/Cellar/tfenv/1.0.2/versions/0.12.13/terraform", "apply"}
2020/02/18 15:58:02 [DEBUG] Attempting to open CLI config file: /Users/stephen/.terraformrc
2020/02/18 15:58:02 [DEBUG] File doesn't exist, but doesn't need to. Ignoring.
2020/02/18 15:58:02 [INFO] CLI command args: []string{"apply"}
2020/02/18 15:58:02 [DEBUG] checking for provider in "."
2020/02/18 15:58:02 [DEBUG] checking for provider in "/usr/local/Cellar/tfenv/1.0.2/versions/0.12.13"
2020/02/18 15:58:02 [DEBUG] checking for provider in ".terraform/plugins/darwin_amd64"
View gist:39eeabe0ef085cbcb7a06816628c7994
terraform apply
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
# docker_container.nginx will be created
+ resource "docker_container" "nginx" {
@stephennancekivell
stephennancekivell / diffjavamap.scala
Created Jun 7, 2018
scala diff recursive java Map[String,Any]
View diffjavamap.scala
val skip = Set.empty[String]
import java.util.{Map => JMap, List => JList}
def diff(a: JMap[String, Any], b: JMap[String, Any], prefix: String = ""): Unit = {
(a.keySet().asScala.toSet ++ b.keySet().asScala.toSet).filterNot(skip.contains).foreach { key =>
val prefixKey = s"$prefix.$key"
(Option(a.get(key)), Option(b.get(key))) match {
case (Some(av), Some(bv)) if av.isInstanceOf[JMap[String, Any]] && bv.isInstanceOf[JMap[String, Any]] =>
diff(av.asInstanceOf[JMap[String, Any]], bv.asInstanceOf[JMap[String, Any]], prefixKey)
View gist:82b481eda1653f5c0922a229fa4577a1
# results from https://github.com/stephennancekivell/circe-argonaut-compile-times
# 100 case classes with up to 15 values
play-json 2.12
23
19
play-json.topic 2.12
17
20
circe 2.12
View gatherUnordered.js
/*
* gather unordered takes an Array of promise's running them in parallel returning a single promise of their result and cancel function.
*
* If a error is encountered the first error will be returned, remaining unordered thunks will not be executed.
*
* @inputThunks Array[() => Promise[A]] an array of promises not yet started, thunks () => Promise
* @parallism number of promises to run at once
* @returns Object {
* promise: Promise[Array[A]]
* cancel: Function() to cancel
@stephennancekivell
stephennancekivell / traverseCancellable.js
Created Dec 1, 2017
javascript traverse cancellable
View traverseCancellable.js
/*
* traverse cancellable takes an Array of promise's running them in parallel returning a single promise of their result and cancel function.
*
* @inputThunks Array[() => Promise[A]] an array of promises not yet started, thunks () => Promise
* @returns Object {
* promise: Promise[Array[A]]
* cancel: Function() to cancel
* }
*/
export function traverseCancellable(inputThunks) {
@stephennancekivell
stephennancekivell / gather.scala
Created Aug 1, 2017
Scala Future gatherUnordered Usage
View gather.scala
import $ivy.`net.databinder.dispatch::dispatch-core:0.13.1`
import scala.concurrent.ExecutionContext
import scala.concurrent.Future
import dispatch._, Defaults._
val svc = url("http://httpbin.org/ip")
def get() = Http.default(svc OK as.String)
def getAndTime(idx: Int) = {
@stephennancekivell
stephennancekivell / FutureOps.scala
Last active Aug 1, 2017
Scala Future gatherUnordered
View FutureOps.scala
/**
* Like Future.sequence but but limits the parallelism to only process so many futures at once.
* Useful if you have lots of future operations but dont want to overload something with too many at once.
*/
def gatherUnordered[A, B](parallelism: Int,
xs: Seq[A])(fn: A => Future[B])(implicit ex: ExecutionContext): Future[Seq[B]] = {
def go(todo: Seq[A], inprogress: Seq[Future[B]], acc: Seq[B]): Future[Seq[B]] = {
if (inprogress.size < parallelism && todo.nonEmpty) {
val numToAdd = parallelism - inprogress.size
val (toStart, stillTodo) = todo.splitAt(numToAdd)