Skip to content

Instantly share code, notes, and snippets.

View KaiserWerk's full-sized avatar

Robin K. KaiserWerk

  • Germany
  • 17:38 (UTC +02:00)
View GitHub Profile
@KaiserWerk
KaiserWerk / Home.razor
Created September 9, 2024 18:29
Get User Claims (and ID) in Balzor page
@page "/"
@using System.Security.Claims
@inject AuthenticationStateProvider AuthenticationStateProvider
<PageTitle>Home</PageTitle>
<h1>Hello, world!</h1>
Welcome to your new app.
<h3>ClaimsPrincipal Data</h3>
@KaiserWerk
KaiserWerk / authorize.html
Last active August 18, 2024 15:10
Quick and dirty example for a discord social login with Golang
<!doctype html>
<html>
<head>
</head>
<body>
<h2>Discord login</h2>
Token: {{ .Token }}
@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() {