Skip to content

Instantly share code, notes, and snippets.

View KaiserWerk's full-sized avatar

Robin K. KaiserWerk

  • Germany
  • 14:06 (UTC +02:00)
View GitHub Profile
@KaiserWerk
KaiserWerk / certmaker-bot.service
Last active December 16, 2021 14:06
Homelab Service unit templates
[Unit]
Description=CertMaker Bot (to cover your cert needs)
After=network.target
[Service]
Type=simple
ExecStart=/home/certmaker-bot/bin/certmaker-bot
WorkingDirectory=/home/certmaker-bot/bin
User=certmaker-bot
Group=certmaker-bot
@KaiserWerk
KaiserWerk / build.ps1
Last active June 2, 2025 23:30
A small PowerShell script to automate cross-compilation (release) for a Go project
$sourcecode = ".\main.go"
$target = "build\binary-name"
# Windows, 64-bit
$env:GOOS = 'windows'; $env:GOARCH = 'amd64'; go build -o "$($target)-win64.exe" -ldflags "-s -w" $sourcecode
# Linux, 64-bit
$env:GOOS = 'linux'; $env:GOARCH = 'amd64'; go build -o "$($target)-linux64" -ldflags "-s -w" $sourcecode
# Raspberry Pi
$env:GOOS = 'linux'; $env:GOARCH = 'arm'; $env:GOARM=5; go build -o "$($target)-raspi32" -ldflags "-s -w" $sourcecode
# macOS
$env:GOOS = 'darwin'; $env:GOARCH = 'amd64'; go build -o "$($target)-macos64" -ldflags "-s -w" $sourcecode
@KaiserWerk
KaiserWerk / auto-cert-reload.go
Last active December 27, 2023 06:09
Golang: Automatic TLS Certificate Reload
package main
import (
"crypto/tls"
"fmt"
"io"
"net/http"
)
func main() {
@KaiserWerk
KaiserWerk / Bitmask.cs
Last active January 10, 2021 00:00
C# Example Bitmask Implementation
using System;
namespace BitmaskTest
{
[Flags]
public enum Names
{
NoOne = 0,
Tim = 1,
Alfred = 2,
@KaiserWerk
KaiserWerk / ConcurrentList.cs
Last active January 12, 2021 12:12
C' Example Concurrent Collection Implementations
using System;
using System.Collections.Generic;
using System.Linq;
namespace ConcurrencyTests
{
public class ConcurrentList<T>
{
private List<T> internalList = new List<T>();
private object listLock = new object();
@KaiserWerk
KaiserWerk / GenericRepository.cs
Last active January 9, 2021 22:28
C# Repository pattern
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
namespace Core.Repositories
{
public abstract class GenericRepository<T> : IRepository<T> where T : class
{
protected MyDbContext context;
// inspired by https://gist.github.com/samuel/8b500ddd3f6118d052b5e6bc16bc4c09
func generateSelfSignedCert(certPath string, keyPath string) {
// priv, err := rsa.GenerateKey(rand.Reader, *rsaBits)
priv, err := ecdsa.GenerateKey(elliptic.P521(), rand.Reader)
if err != nil {
log.Fatal(err)
}
template := x509.Certificate{
SerialNumber: big.NewInt(time.Now().UnixNano()),
@KaiserWerk
KaiserWerk / populate_templates.go
Created October 31, 2020 20:56
Populate template map in Go
func populateTemplates(fm template.FuncMap) map[string]*template.Template {
result := make(map[string]*template.Template)
const basePath = "templates"
layout := template.Must(template.ParseFiles(basePath + "/_layout.html")).Funcs(fm)
dir, err := os.Open(basePath + "/content")
if err != nil {
panic("failed to open template base directory: " + err.Error())
}
defer dir.Close()
fis, err := dir.Readdir(-1)
@KaiserWerk
KaiserWerk / slices1.go
Last active November 17, 2020 18:25
Why does this not work?
package main
import "fmt"
type myStruct struct {
id int
messages []Message
}
type Message struct {
@KaiserWerk
KaiserWerk / basic_webserver_setup.go
Last active November 24, 2020 18:03
Basic Golang Webserver Setup
package main
var (
env string
)
func main() {
flag.StringVar(&env, "e", "dev", "The environment to run at (prod, test, dev)")
flag.Parse()