Skip to content

Instantly share code, notes, and snippets.

View KaiserWerk's full-sized avatar

R. Kaiser KaiserWerk

  • Germany
View GitHub Profile
@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 / 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 / dummy.service
Last active July 24, 2022 11:13
Barebone systemd user service
// place into ~/.config/systemd/user/your-service-file.service
// more info: https://www.unixsysadmin.com/systemd-user-services/
[Unit]
Description=Run dummy service as user X
DefaultDependencies=no
After=network.target
[Service]
Type=simple
@KaiserWerk
KaiserWerk / IoC.cs
Last active December 30, 2020 20:54
C# MVVM Simple Implementation
using System;
using System.Collections.Generic;
namespace Mvvm
{
public class Ioc
{
private static Dictionary<Type, object> classes = new Dictionary<Type, object>();
public static void Register<T>(params object[] parameters) where T : class
{
@KaiserWerk
KaiserWerk / WriteCache.php
Last active April 7, 2020 06:26
Writing a PHP cache file using PHP
<?php
// reading data from any source
$array = call_procedure_here();
$output = '<?php' . PHP_EOL . '$myarray = ' . var_export($array, true) . ';' . PHP_EOL . '?>';
file_put_contents(__DIR__ . '/cache/cache_file.php', $output);
// include in other files
include __DIR__ . '/cache/cache_file.php';
?>
// just an example object
MyObj obj = // receive from somewhere
object temp = new object();
PropertyInfo[] properties = typeof(obj).GetProperties();
foreach (PropertyInfo property in properties)
{
var name = property.Name; // gets the name of the property as a string
var value = property.GetValue(temp, null); // get the value of the property
@KaiserWerk
KaiserWerk / FolderDialog.cs
Last active March 23, 2020 18:15
Dialogs
// Install NuGet package WindowsAPICodePack-Shell by Aybe
//
// using Microsoft.WindowsAPICodePack.Dialogs;
CommonOpenFileDialog dialog = new CommonOpenFileDialog();
dialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
dialog.IsFolderPicker = true;
if (dialog.ShowDialog() == CommonFileDialogResult.Ok)
{
Debug.WriteLine(dialog.FileName);