Skip to content

Instantly share code, notes, and snippets.

View kkroesch's full-sized avatar

Karsten Kroesch kkroesch

View GitHub Profile
@kkroesch
kkroesch / kibana-curl.sh
Created November 18, 2021 19:49 — forked from arpat/kibana-curl.sh
CURL the kibana endpoint to query Elasticsearch
#!/bin/bash
#
## CURL the kibana endpoint
## Use the kibana dev console to validate query json
curl -i --insecure --user User:Password -XPOST \
--header "kbn-version: 5.6.0" \
'https://kibana.yourdomain/api/console/proxy?path=_search&method=POST' \
--data '{"query":{"match_all":{}}}'
@kkroesch
kkroesch / Vagrantfile
Last active August 19, 2021 13:53
Lightweight Kubernetes Playground with K3S
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.define "controlplane", primary: true do |controlplane|
config.vm.box = "centos/7"
config.vm.hostname = "haithabu"
end
@kkroesch
kkroesch / numbers.py
Last active October 29, 2021 10:54
Readable large numbers in Python
""" Underscores in number literals are ignored: """
>>> ten_billion = 10_000_000_000
>>> ten_billion
10000000000
""" In output formatting, you can insert thousands separators: """
>>> f"{ten_billion:,}"
'10,000,000,000'
@kkroesch
kkroesch / plugin.py
Last active June 4, 2022 21:57
Plugin registry implementation
class Singleton(type):
_instances = {}
def __call__(cls, *args, **kwargs):
if cls not in cls._instances:
cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
return cls._instances[cls]
class Registry(metaclass=Singleton):
"""Management for plugins as a singleton.
@kkroesch
kkroesch / test_tracer.py
Last active July 18, 2021 07:53
Tracer Ammunition for Python code. See test case how to use it.
import sys, logging
from unittest import TestCase
from tracer import trace, profile, log, slow_down, timer, debug
class TestTrace(TestCase):
def setUp(self):
root = logging.getLogger()
root.setLevel(logging.DEBUG)
@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;