Skip to content

Instantly share code, notes, and snippets.

View kkroesch's full-sized avatar

Karsten Kroesch kkroesch

View GitHub Profile
@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)
@kkroesch
kkroesch / ips.py
Last active January 28, 2019 14:58
Iterate IP range
from ipaddress import ip_address
""" Two IP addresses are known """
start = ip_address('192.168.1.0')
end = ip_address('192.168.1.254')
print("From {} to {}".format(start, end))
for ip in range(int(start), int(end)):
print(ip_address(ip))
""" Network address is known """
@kkroesch
kkroesch / aes.py
Created January 11, 2019 11:18
Ecryption/Decryption REST Service
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
Ecryption/Decryption REST Service
=================================
INSTALLATION
------------
@kkroesch
kkroesch / mailbox.cql
Last active April 11, 2018 07:56
Storing mail metadata in Cassandra DB.
CREATE KEYSPACE mail
WITH replication = {
'class': 'SimpleStrategy',
'replication_factor': 1
};
CREATE TABLE mailbox (
box_id text, year int,
received timestamp,
@kkroesch
kkroesch / test_certificate.py
Last active March 27, 2018 09:09
Test the expiry of a SSL certificate.
"""
Test validity of certificates.
Tested on Ubuntu with Python 3.5 and python3-openssl package.
"""
import ssl
from datetime import datetime
from warnings import warn
@kkroesch
kkroesch / search_query.py
Created October 18, 2016 15:37
A primitive search for keywords in a text.
import string
from collections import Counter
george_takei_tweet = "When the media gave him millions in free air time, Trump loved them. Now when they do their job and ask questions, it's a global conspiracy."
tweet = george_takei_tweet.lower()
tweet = ''.join(ch for ch in tweet if ch not in set(string.punctuation))
contains = Counter(tweet.split(' '))
eval("contains['trump'] and contains['conspiracy']")
# ==> 1