Skip to content

Instantly share code, notes, and snippets.

View KaiserWerk's full-sized avatar

Robin K. KaiserWerk

  • Germany
  • 17:28 (UTC +02:00)
View GitHub Profile
@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 / console_input_nonblocking.go
Created May 20, 2020 08:33
Golang read console input in a non-blocking way
go func() {
reader := bufio.NewReader(os.Stdin)
for {
input, _, err := reader.ReadLine()
if err != nil {
fmt.Printf("could not process input %v\n", input)
}
switch string(input) {
case "hello":
fmt.Println("hello world")
@KaiserWerk
KaiserWerk / gracefulShutdownWebserver.go
Last active February 29, 2024 18:06
Golang: Webserver with graceful shutdown
package main
import (
"context"
"fmt"
"net/http"
"os"
"os/signal"
"time"
)
@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);
@KaiserWerk
KaiserWerk / pdf_cracker.py
Last active March 10, 2022 19:52
Python Password Crackers
# From: https://github.com/nitin42/Python-Automation/blob/master/project15.py
# Brute-Force PDF Password Breaker
# Brute-Forcing the pdf files to break the encryption using dictionary attack
import os
import PyPDF2
@KaiserWerk
KaiserWerk / .gitignore
Created April 21, 2019 10:05
.gitignore template
/.idea/
/.git/
/vendor/
/var/*
!/var/cache
/var/cache/*
!var/cache/.gitkeep
!/var/lock
/var/lock/*
@KaiserWerk
KaiserWerk / file_list_2_file_size_order.php
Last active March 11, 2019 20:53
List files recusively ordered by file size
<?php
/**
* Source: https://www.jodyhatton.com/how-big-is-my-website-how-to-get-a-list-of-all-files-and-folders-directories-using-php/
*/
$pathLen = 0;
function prePad($level)
{
$ss = "";