Skip to content

Instantly share code, notes, and snippets.

View hermanbanken's full-sized avatar
🇳🇱

Herman hermanbanken

🇳🇱
View GitHub Profile
FROM node:alpine
COPY server.js /srv/www/
COPY server.js.map /srv/www/
ENV API_URL=http://example.com NODE_OPTIONS=--enable-source-maps
ENTRYPOINT [ "node", "/srv/www/server.js" ]
@hermanbanken
hermanbanken / bootstramp.yaml
Last active May 17, 2022 22:02
Envoy xDS syntax highlighting with https://github.com/redhat-developer/vscode-yaml Extension
# yaml-language-server: $schema=https://github.com/jcchavezs/envoy-config-schema/releases/download/v1.21.0/v3_Bootstrap.json
node:
id: "something"
cluster: "some-cluster"
metadata:
any: {}
key: can
be: used-here
locality:
zone: "europe-west4-a"
@hermanbanken
hermanbanken / README.md
Last active March 18, 2022 15:01
Middleware

Sadly we can't have nice things in TypeScript (see https://www.ackee.agency/blog/typescript). Specifically middleware that:

  1. Notifies when the chain is broken
pipe(
   () => 21,
   (n: number) => n * 2,
 (n: string) => n.repeat(5), // Error: number is not assignable to string
@hermanbanken
hermanbanken / auth.go
Created January 18, 2022 23:59
Triple JWT audience/issuer server
package main
import (
"context"
"fmt"
"log"
"net/http"
"os"
"github.com/golang-jwt/jwt/v4"
@hermanbanken
hermanbanken / NativeHttpServer.java
Created December 17, 2021 10:17
java server serving 404 without dependencies
package main;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Map;
@hermanbanken
hermanbanken / README.md
Last active December 12, 2021 14:15
Cloud Function for GKE upgrade notifications

We want to receive notifications when a Kubernetes cluster upgrades. For this we can configure PubSub subscriptions:

const exec = require("child_process").execSync;

const mapping = {
  "my-dev-project": [{ name: "clusterA", region: "europe-west4" }, { name: "clusterB", region: "us-east1" }],
  "my-prod-project": [{ name: "clusterC", region: "europe-west4" }, { name: "clusterD", region: "us-east1" }],
};
@hermanbanken
hermanbanken / gitlab_list_variables.js
Created September 9, 2021 13:09
GitLab list pipeline variables
#!/bin/env node
const PRIVATE_TOKEN = "redacted";
const headers = { "PRIVATE-TOKEN": PRIVATE_TOKEN };
const root = "https://gitlab.com/api/v4";
const project = 24418136; // "hue-contract-tests";
const { default: fetch } = require("node-fetch");
fetch(`${root}/projects/${project}/pipelines`, { headers }).then((res) => res.json())
.then(async (pipelines) => {
@hermanbanken
hermanbanken / blog.md
Created September 6, 2021 15:08
Raft cluster completely blocked

Raft issue

When developing my first hashicorp/raft implementation I was stuck at a stone wall it seemed. Somehow I could bootstrap one of the nodes and this would win the election and the raft observation for it becoming Leader also made it in, but then nothing. I couldn't figure out why all RPCs timed out after that.

I started to run locally and debugged using VS Code Launch configuration (which uses Delve) and found that before bootstrapping there was a "runCandidate" goroutine, but after bootstrapping there was no "runLeader" goroutine. Turns out the leader loop never started! How could this be? Then my mind wandered to the observer that I added:

	ch := make(chan raft.Observation, 1)
	r.RegisterObserver(raft.NewObserver(ch, true, func(o *raft.Observation) bool {
		// *RequestVoteRequest
@hermanbanken
hermanbanken / _README.md
Last active August 23, 2021 09:28
LimitedSampler

Limited Sampler

flow chart

@hermanbanken
hermanbanken / .gitmodules
Last active June 6, 2021 10:45
Protobuf ramblings
[submodule "proto/googleapis"]
path = proto/vendor/googleapis
url = https://github.com/googleapis/googleapis.git