Skip to content

Instantly share code, notes, and snippets.

View kkroesch's full-sized avatar

Karsten Kroesch kkroesch

View GitHub Profile
@kkroesch
kkroesch / app.js
Created June 13, 2021 14:49
Load JSON data with async/await
let results;
const DEBUG = true;
const load_data = async () => {
try {
const url = "https://httpbin.org/json"
const response = await fetch(url)
results = await response.json()
if (DEBUG) console.log(response.ok)
if (DEBUG) console.log(results.slideshow)
@kkroesch
kkroesch / Vagrantfile
Created May 28, 2021 11:28
Vagrantfile to have an Ansible and Docker toolkit at hand on Windows machines
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile to have an Ansible and Docker toolkit at hand on Windows machines.
Vagrant.configure("2") do |config|
# Jeff Geerling must have Ansible on his box ;-)
config.vm.box = "geerlingguy/debian10"
@kkroesch
kkroesch / rdap.curl
Last active June 19, 2024 02:52
Get RDAP information about IP address.
curl -sL https://rdap.db.ripe.net/ip/85.0.0.116 | jq ". | .handle, .name, .country" | tr -d '"'
@kkroesch
kkroesch / test-imap.sh
Created December 18, 2019 11:49
Testing IMAP connection and credentials
echo -e "A LOGIN login(at)domain *********" | openssl s_client -crlf -ign_eof -connect imap.company.net:993
@kkroesch
kkroesch / bytes.cpp
Created December 13, 2019 09:17
Self-explaining memory sizes
#define KB *(1 << 10)
#define MB *(1 << 20)
#define GB *(1U << 30)
int buffer = 64 KB;
@kkroesch
kkroesch / backup.sh
Created September 21, 2019 19:44
Automated Backup with Borg
#!/bin/bash
export BORG_RSH='ssh -i ~/.ssh/id_ed25519'
export BORG_REPO='ssh://user@storage:22/./mail'
export BORG_PASSPHRASE='**********'
export ARCHIVE=$(date +'%a-%Y-%m-%d')
/usr/bin/borg create \
--verbose \
@kkroesch
kkroesch / colorize.sh
Created September 9, 2019 11:57
Colorize your shell script output
function header {
echo ""
echo "$(tput setaf 6)$1$(tput sgr0)"
echo ""
}
header "Creating MySQL database ..."
@kkroesch
kkroesch / lanparse.awk
Last active February 7, 2022 20:58
Make Nagios host definition from Nmap scan.
#!/usr/bin/awk -f
/Host:/ { print "define host {";
print "\tuse\tgeneric_host";
gsub(/[\(\)]/, ""); print "\thost_name\t", $3;
print "\taddress\t\t", $2;
print "}"; }
@kkroesch
kkroesch / demo.py
Created July 2, 2019 22:03
Simple Application server with plugin contract
from bottle import route, run, template, abort, Response
APP_VERSION = '0.1.1'
@route('/hello/<name>')
def index(name):
return template('<b>Hello {{name}}</b>!', name=name)
@kkroesch
kkroesch / namespace.py
Created May 20, 2019 10:45
Wrap dictionary in namespace to access values wit dot notation
class NestedNamespace(SimpleNamespace):
""" Wrapping dictionaries in namespace to access it with dot notation. """
def __init__(self, dictionary, **kwargs):
super().__init__(**kwargs)
for key, value in dictionary.items():
if isinstance(value, dict):
self.__setattr__(key, NestedNamespace(value))
else:
self.__setattr__(key, value)