Skip to content

Instantly share code, notes, and snippets.

@ryu1kn
ryu1kn / Makefile
Created March 11, 2020 09:56
Terraform, instantiate the same module multiple times
export AWS_PROFILE := your-aws-profile
auto_approve_target = apply destroy
init apply destroy:
cd infra && terraform $@ $(if $(filter $@,$(auto_approve_target)),-auto-approve)
@ryu1kn
ryu1kn / main.js
Created March 29, 2020 09:21
GCP KMS node.js client (googleapis and @google-cloud/kms) usage
const locationId = "KMS key's region ID"
const projectId = "KMS key's project ID"
const keyRring = "KMS key's key ring"
const keyId = "KMS key's ID"
const encryptedText = 'CiQAfn8U68PD1weop5nXO43I8srZ2pMLaxXci2tcaDnfwLt2YOUSMwDNtppaQLU82bYtoRXx/NCnLnUt05WtHl8Y2QKUNCq6QS9FJdoxCszzjsnpym7SktWn+g==';
async function useGoogleapisModule() {
console.log('Use `googleapis` module to decrypt KMS encrypted secret')
const {google} = require('googleapis')
@ryu1kn
ryu1kn / WithReader.purs
Last active May 3, 2020 12:51
Same code with and without Reader monad
module WithReader where
import Prelude
import Control.Monad.Reader (Reader, asks, runReader)
import Data.String (toLower)
import Effect (Effect)
import Effect.Console (log)
type Config = {username :: String}
@ryu1kn
ryu1kn / App.kt
Last active May 8, 2020 11:07
Kotlin + Vert.x simple web server
// src/App.kt
import io.vertx.core.Vertx
import io.vertx.ext.web.Router
fun main(args: Array<String>) {
val vertx = Vertx.vertx()
val router = Router.router(vertx)
router.get("/health").handler { ctx -> ctx.response().end("OK") }
@ryu1kn
ryu1kn / Makefile
Created May 20, 2020 13:26
DynamoDB Local
export AWS_REGION := ap-southeast-2
export AWS_ACCESS_KEY_ID := fakeForLocalDynamodb
export AWS_SECRET_ACCESS_KEY := fakeSecretForLocalDynamodb
endpoint := --endpoint-url http://localhost:8000
table_name := people
container_name := dynamodb-local
dynamo = aws dynamodb $(endpoint)
@ryu1kn
ryu1kn / Makefile
Last active December 27, 2020 12:09
Use SonarQube to analyse a project
# Usage:
#
# 1. `make qube` to bring up SonarQube server
# 2. Open http://localhost:9000 with your browser,
# setup a new project (e.g. my-first-project) and generate a token.
# Put the token and project key in this Makefile
# 3. `make scan` against the repository you want to analyse
# Refs
#
@ryu1kn
ryu1kn / JsonSpec.scala
Last active August 3, 2021 13:38
spray-json. Remove empty string before deserialising JSON
import org.scalatest.{Matchers, WordSpec}
import spray.json._
object JsonHelper {
implicit class JsObjectWrap(obj: JsObject) {
def removeEmptyValues: JsObject = JsObject(obj.fields
.map {
case (key, value: JsObject) => (key, value.removeEmptyValues)
@ryu1kn
ryu1kn / README.md
Last active August 14, 2021 14:46
Parallel job execution and aggregated exit status with Bash
@ryu1kn
ryu1kn / core.clj
Last active March 13, 2023 18:59
Use clojure to fetch Dialogflow log from Stackdriver
; src/clojure__gcp/core.clj
(ns clojure--gcp.core
(:import (com.google.cloud.logging LoggingOptions Logging$EntryListOption Logging)))
; Advanced logs queries: https://cloud.google.com/logging/docs/view/advanced-queries
(defn make-filter [project-id]
(str "logName = \"projects/" project-id "/logs/dialogflow_agent\"
labels.type = \"dialogflow_response\"
timestamp >= \"2020-04-05T00:00:00+11:00\""))
@ryu1kn
ryu1kn / Makefile
Last active March 19, 2023 13:02
Encrypt/decrypt with AWS KMS using AWS cli
# How to encrypt/decrypt your text/blob secret with AWS KMS with AWS cli
KEY_ID=alias/my-key
SECRET_BLOB_PATH=fileb://my-secret-blob
SECRET_TEXT="my secret text"
ENCRYPTED_SECRET_AS_BLOB=encrypted_secret_blob
DECRYPTED_SECRET_AS_BLOB=decrypted_secret_blob # Result of decrypt-blob target
encrypt-text: