Skip to content

Instantly share code, notes, and snippets.

View KaiserWerk's full-sized avatar

Robin K. KaiserWerk

  • Germany
View GitHub Profile
@KaiserWerk
KaiserWerk / main.go
Created September 12, 2022 20:49
Custom JSON (Un)Marshaler in Go
package main
import (
"encoding/json"
"fmt"
"log"
"net/url"
"strings"
)
@KaiserWerk
KaiserWerk / README.md
Created August 21, 2022 23:19
Golang benchmark testing different HTTP router implementations

Please observe the difference in speed when calling resp.Body.Close().

@KaiserWerk
KaiserWerk / main.go
Created June 25, 2022 15:21
A tiny tool to generate a selectable number of Loprem Ipsum paragraphs.
package main
import (
"fmt"
"os"
"strconv"
)
var (
paragraphs = []string{
@KaiserWerk
KaiserWerk / Program.cs
Created May 9, 2022 17:44
C#: De- and Encryption using RSA
using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Crypto.Encodings;
using Org.BouncyCastle.Crypto.Engines;
using Org.BouncyCastle.Crypto.Generators;
using Org.BouncyCastle.OpenSsl;
using Org.BouncyCastle.Security;
using System.Text;
namespace RSATest
@KaiserWerk
KaiserWerk / addslashes.go
Created November 25, 2021 12:55
Add slashes to escape special characters
func Addslashes(str string) string {
var buf bytes.Buffer
for _, char := range str {
switch char {
case `'`, `"`, `\`:
buf.WriteRune(`\`)
}
buf.WriteRune(char)
}
return buf.String()
@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 February 8, 2023 17:12
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();