Skip to content

Instantly share code, notes, and snippets.

View bluebrown's full-sized avatar

Nico Braun bluebrown

View GitHub Profile
@bluebrown
bluebrown / batch_request_handler.go
Created December 21, 2021 09:47
Go HTTP Batch Request Handler
import (
"bufio"
"bytes"
"fmt"
"io"
"log"
"mime/multipart"
"net/http"
"net/http/httptest"
"net/textproto"
@bluebrown
bluebrown / openapi.go
Created November 18, 2022 17:45
Validate http requests based on openapi spec
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)
w.WriteHeader(http.StatusNotFound)
@bluebrown
bluebrown / server.go
Last active November 1, 2022 00:02
Basic tcp server handling http requests written in Go
package main
import (
"bufio"
"bytes"
"context"
"errors"
"fmt"
"io"
"log"
@bluebrown
bluebrown / helmdump.sh
Created October 31, 2022 07:23
dump a deployed helm release into individual manifest files
#!/usr/bin/env bash
set -euo pipefail
# ./helmdump.sh [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
targetChart="$1"
@bluebrown
bluebrown / dqlite-from-source.sh
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
bluebrown / container-tools.md
Created April 17, 2022 16:35
Container Tools

Container Tools

Helper Commands

Preparation

Create a bin folder

mkdir -p bin
@bluebrown
bluebrown / is_container.py
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 = (
path.exists("/var/run/secrets/kubernetes.io/serviceaccount/namespace")
or path.exists("/.dockerenv")
or (
path.isfile("/proc/self/cgroup")
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
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
---
apiVersion: batch/v1
kind: Job
metadata:
name: myjob
spec:
ttlSecondsAfterFinished: 10
template:
spec:
containers:
@bluebrown
bluebrown / Dockerfile
Last active June 26, 2021 22:48
Docker - call command from entrypoint.sh
FROM alpine
COPY entrypoint.sh /
RUN chmod +x /entrypoint.sh
ENTRYPOINT [ "/entrypoint.sh" ]
CMD echo 'hello, captain!'
ENV FOO=bar
@bluebrown
bluebrown / compute-note.js
Last active June 18, 2021 05:51
Compute musical note from arbitrary scale
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,