Skip to content

Instantly share code, notes, and snippets.

View kkroesch's full-sized avatar

Karsten Kroesch kkroesch

View GitHub Profile
@kkroesch
kkroesch / main.rs
Last active October 25, 2024 18:16
Rust Tracing
//! ## Dependencies
//! [dependencies]
//! tracing = "0.1"
//! tracing-subscriber = { version = "0.3", features = ["fmt", "env-filter"] }
use tracing::{debug, error, info, instrument, warn};
use tracing_subscriber::{fmt, EnvFilter};
#[instrument(level = "trace")]
@kkroesch
kkroesch / consumer.rs
Last active October 23, 2024 11:08
RabbitMQ Producer and Consumer with Tokio Runtime.
use futures_util::stream::StreamExt;
use lapin::{
options::{BasicAckOptions, BasicConsumeOptions, QueueDeclareOptions},
types::FieldTable,
Connection, ConnectionProperties,
};
use std::error::Error;
use tracing::{info, instrument};
use tracing_subscriber;
@kkroesch
kkroesch / sonntagsfrage.R
Last active September 12, 2024 14:33
Sonntagsfrage
# Installiere ggplot2 und scales, falls noch nicht installiert
# install.packages("ggplot2")
# install.packages("scales")
library(ggplot2)
library(scales)
# Erstelle den Datensatz
partei_list = c("SPD", "CDU", "Grüne", "FDP", "AfD", "Linke", "BSW", "Sonstige")
# Definiere die Parteifarben
@kkroesch
kkroesch / exif.sh
Last active May 17, 2024 11:21
Manipulate EXIF Headers
exif --ifd=0 --tag=0x8298 --set-value='(c) 2010 Karsten Kroesch' campground.jpg
exif --ifd=0 --tag=0x010e --set-value='Campground Mojave Desert' -o campground.jpg campground.jpg.modified.jpeg
**Copyright Watermark:**
convert desert.jpg -fill white  -undercolor '#00000080'  -gravity South -annotate +0+5 ' (c) 2010 Karsten Kroesch ' desert.jpg
**Border:**
@kkroesch
kkroesch / playbook.yaml
Created May 16, 2024 11:56
Template Ansible Playbook
---
- name: Example Ansible Playbook
hosts: all
become: true
vars:
paketname: "htop"
quellpfad: "/pfad/zur/datei"
zielpfad: "/pfad/zum/ziel"
tasks:
@kkroesch
kkroesch / pods.nsh
Created May 16, 2024 11:04
Kubectl in Nu Shell
def pods [] { kubectl get pods -o yaml | from yaml | get items }
pods | get metadata.name
@kkroesch
kkroesch / chart.html
Last active April 26, 2024 09:53
Hugo Hextra Chart Shortcode
<!-- layouts/shortcodes/chart.html -->
<div id="{{ .Get "id" }}" style="width:{{ .Get "width" }}px;height:{{ .Get "height" }}px;">
</div>
<script>
let data = JSON.parse({{ .Inner }})
console.log(data)
canvas = document.getElementById('{{ .Get "id" }}');
Plotly.newPlot( canvas, [{x: data.ord, y: data.absz}], { margin: { t: 0 } } );
</script>
@kkroesch
kkroesch / cert_valid_days_local.sh
Last active May 22, 2024 13:09
Checking the remaining valid days for certificates.
#!/usr/bin/env bash
# Return the number of days the given certificate file is still valid
#
if [ "$#" -eq 0 ]; then
echo "Usage: crt_valid_days <certificate>"
exit 1
fi
if ! command -v openssl &> /dev/null; then
echo "ERROR: OpenSSL not installed."
@kkroesch
kkroesch / functional.go
Created March 27, 2024 20:40
Map, Reduce, Filter with Go Generics
package functional
func Map[TValue any](values []TValue, f func(TValue) TValue) {
for i, value := range values {
values[i] = f(value)
}
}
func Reduce[TValue, TResult any](values []TValue, f func(TValue, TResult) TResult) TResult {
@kkroesch
kkroesch / mkinventory.sh
Last active March 11, 2024 10:04
Manage VirtualBox VMs with Ansible
running_vms=($(VBoxManage list runningvms | awk '{print $1}' | tr -d '"'))
# Create Ansible inventory file
GROUP_NAME="local_vms"
for vm in $running_vms
do
vboxmanage guestproperty get "$vm" "/VirtualBox/GuestInfo/Net/0/V4/IP"
done |
awk -v group="$GROUP_NAME" '
BEGIN { printf("[%s]\n", group)}