Skip to content

Instantly share code, notes, and snippets.


Nico Braun bluebrown

View GitHub Profile
bluebrown / openapi.go
Created November 18, 2022 17:45
Validate http requests based on openapi spec
View openapi.go
type ValidationInterceptor struct {
router http.Handler
val routers.Router
func (s *ValidationInterceptor) ServeHTTP(w http.ResponseWriter, r *http.Request) {
route, pathParams, err := s.val.FindRoute(r)
if err != nil {
log.Printf("no route: %v", err)
bluebrown / server.go
Last active November 1, 2022 00:02
Basic tcp server handling http requests written in Go
View server.go
package main
import (
bluebrown /
Created October 31, 2022 07:23
dump a deployed helm release into individual manifest files
#!/usr/bin/env bash
set -euo pipefail
# ./ [target-chart] [output-dir] [namespace]
# $1: the target char
# $2: the output directory, must be a relative path
# $3: optional namespace, if not provided the current namespace is used
bluebrown /
Created May 1, 2022 08:36
install dqlite from source
#!/usr/bin/env sh
set -e
# install build tools
apt-get -y update
apt-get -y --no-install-recommends install autoconf make
# get & compile raft
bluebrown /
Created April 17, 2022 16:35
Container Tools

Container Tools

Helper Commands


Create a bin folder

mkdir -p bin
bluebrown /
Created January 21, 2022 17:18
check if python code runs inside a kubernetes pod container or docker container
# check if running in a container in kubernetes or docker
is_container = (
or path.exists("/.dockerenv")
or (
and (
any("kubepods" in line for line in open("/proc/self/cgroup"))
or any("docker" in line for line in open("/proc/self/cgroup"))
bluebrown / batch_request_handler.go
Created December 21, 2021 09:47
Go HTTP Batch Request Handler
View batch_request_handler.go
import (
bluebrown / wait-for-job.yaml
Created November 8, 2021 06:22
use kubectl init container to wait for job to complete before unblocking the actual pod
View wait-for-job.yaml
apiVersion: batch/v1
kind: Job
name: myjob
ttlSecondsAfterFinished: 10
bluebrown / replace-html.js
Created June 8, 2021 21:30
custom innerHTML function with improved performance
View replace-html.js
// taken from below url, which explains the why this function makes sense
function replaceHtml(el, html) {
var oldEl = typeof el === "string" ? document.getElementById(el) : el;
/*@cc_on // Pure innerHTML is slightly faster in IE
oldEl.innerHTML = html;
return oldEl;
var newEl = oldEl.cloneNode(false);
newEl.innerHTML = html;
bluebrown / compute-note.js
Last active June 18, 2021 05:51
Compute musical note from arbitrary scale
View compute-note.js
export function computeNote(
// how far from the base note to go in either direction
distance = 0,
scale = {
// use this frequency as basis
// standard A4 is 440hz
base: 440.0,
// claim that its in the 4 repetition of made up sequence,
// on a normal piano it is saying this is A4
position: 4,