Skip to content

Instantly share code, notes, and snippets.

@ryu1kn
ryu1kn / README.md
Last active August 14, 2021 14:46
Parallel job execution and aggregated exit status with Bash
View README.md
@ryu1kn
ryu1kn / Makefile
Last active December 27, 2020 12:09
Use SonarQube to analyse a project
View Makefile
# 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 / Makefile
Created May 20, 2020 13:26
DynamoDB Local
View Makefile
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 / App.kt
Last active May 8, 2020 11:07
Kotlin + Vert.x simple web server
View App.kt
// 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 / WithReader.purs
Last active May 3, 2020 12:51
Same code with and without Reader monad
View WithReader.purs
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 / core.clj
Last active March 13, 2023 18:59
Use clojure to fetch Dialogflow log from Stackdriver
View core.clj
; 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 / main.js
Created March 29, 2020 09:21
GCP KMS node.js client (googleapis and @google-cloud/kms) usage
View main.js
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 / Makefile
Created March 11, 2020 09:56
Terraform, instantiate the same module multiple times
View Makefile
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 / GetPage.java
Last active February 8, 2020 02:18
Page get with no external dependencies
View GetPage.java
import java.io.*;
import java.net.URL;
import java.util.Scanner;
class GetPage {
public static void main(String[] args) throws IOException {
String endpoint = System.getProperty("endpoint");
if (endpoint == null) printUsage();
else printPage(endpoint);
@ryu1kn
ryu1kn / README.md
Last active November 24, 2023 18:35
Getting GCP access token from a service account key JSON file
View README.md

Getting GCP access token from a service account key

Use your service account's key JSON file to get an access token to call Google APIs.

Good for seeing how things work, including the creation of JWT token.

To create a JWT token, you can replace create-jwt-token.sh script with tools like step.

If you just want to get an access token for a service account,