Skip to content

Instantly share code, notes, and snippets.

Avatar

Komu Wairagu komuw

View GitHub Profile
@komuw
komuw / check_mux.go
Last active Nov 23, 2021
golang muxes do not inherit middlewares. Also middlewares are not deduped.
View check_mux.go
package main
import (
"fmt"
"net/http"
"github.com/go-chi/chi"
"github.com/gorilla/mux"
)
@komuw
komuw / cert-manager.yaml
Created Sep 16, 2021
create a golang k8(kubernetes) struct from yaml file
View cert-manager.yaml
# gotten from; https://github.com/jetstack/cert-manager/releases/download/v1.3.3/cert-manager.yamlhttps://github.com/jetstack/cert-manager/releases/download/v1.3.3/cert-manager.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: cert-manager
app.kubernetes.io/component: controller
app.kubernetes.io/instance: cert-manager
app.kubernetes.io/name: cert-manager
name: cert-manager
@komuw
komuw / three_sigma_sampling.py
Last active Dec 4, 2020
In a normal distribution, 99.7% of the values are not anomalous. Which means you can throw away 99.7% without losing context. This is useful in sampling.
View three_sigma_sampling.py
def sample_anomalous(samples):
"""
Sampling:
- Central limit theorem(Alan Turing)
- 3-sigma rule: In a normal distribution, 99.7% of the values are not anomalous.
Which means you can throw away 99.7% without losing context.
- You may also use 2-sigma(95%) or 1-sigma(68%)
see:
1. https://youtu.be/inrqE0Grgk0?t=26080 (Emmanuel T Odeke)
2. https://en.wikipedia.org/wiki/68%E2%80%9395%E2%80%9399.7_rule
@komuw
komuw / variable_shadowing_race.go
Created Nov 5, 2020
Golang variable shadowing can mask race conditions
View variable_shadowing_race.go
package main
import "time"
type cool struct{}
func (c *cool) add() error {
return nil
}
@komuw
komuw / complex_types.go
Last active Oct 29, 2020
pointer receiver versus value receiver benchmarks
View complex_types.go
package main
import (
"fmt"
"math"
"testing"
)
/* ---------- package ---------- */
type h struct {
@komuw
komuw / fdatasync_vs_fsync.go
Last active Jul 7, 2021
Benchmark fdatasync vs fsync
View fdatasync_vs_fsync.go
package main
import (
"log"
"math/rand"
"os"
"syscall"
"testing"
"time"
@komuw
komuw / panic_handler.go
Last active Dec 16, 2020
global panic handler in Go
View panic_handler.go
package main
import "fmt"
// Usage:
//
// func main() {
// defer panicHandler()
// }
//
@komuw
komuw / wireguard.md
Last active Feb 28, 2020
wireguard problems
View wireguard.md

I'm having trouble setting up wireguard(and packet forwarding).
Both peers are running Ubuntu 19.10

A. Server(Peer 1)

1. The config is as follows:

cat /etc/wireguard/wg0.conf

[Interface]
Address = 10.66.66.1/24, fd42:42:42::1/64
@komuw
komuw / go_errors_with_stacktrace.go
Created Nov 9, 2019
Golang errors with stack traces
View go_errors_with_stacktrace.go
package main
import (
"fmt"
"runtime"
"strconv"
"strings"
)
/*