Skip to content

Instantly share code, notes, and snippets.

View bluebrown's full-sized avatar

Nico Braun bluebrown

View GitHub Profile
@bluebrown
bluebrown / index.html
Last active May 6, 2021 14:16
Monaco Editor Setup
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Monaco</title>
<link href="https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.14.0/css/all.min.css"
@bluebrown
bluebrown / main.c
Created May 7, 2021 12:57
Posix Threads in C
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <unistd.h>
pthread_cond_t hasMsg = PTHREAD_COND_INITIALIZER;
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
void *work(void *ptr)
{
@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,
@bluebrown
bluebrown / replace-html.js
Created June 8, 2021 21:30
custom innerHTML function with improved performance
// taken from below url, which explains the why this function makes sense
// https://blog.stevenlevithan.com/archives/faster-than-innerhtml
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
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 / 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 / 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 / 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 / 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 / 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"