Skip to content

Instantly share code, notes, and snippets.

View kkroesch's full-sized avatar

Karsten Kroesch kkroesch

View GitHub Profile
@kkroesch
kkroesch / copyright.sh
Created October 26, 2023 14:31
Put a copyright notice on JPEG pictures
@kkroesch
kkroesch / jail.conf
Created October 16, 2023 11:06
Fail2ban filter 404-requests (unsolicited pentests) for Nginx
# in /etc/fail2ban/jail.conf
# ...
[nginx-4xx]
enabled = true
port = http,https
filter = nginx-4xx
logpath = /var/log/nginx/access.log
bantime = 3600
@kkroesch
kkroesch / webconsole.service
Last active October 30, 2023 13:51
Example systemd config for web application
a# /etc/systemd/system/webconsole.service
#
# Install with:
# # install https://github.com/yudai/gotty
# # systemctl daemon-reload
# # systemctl enable --now patchstatus.service
#
[Unit]
Description=Provide an ephemeral container with web console
@kkroesch
kkroesch / haproxy.cfg
Created June 22, 2023 10:34
HAProxy example config with tunneled SSH service
global
log /dev/log local0
log /dev/log local1 notice
chroot /var/lib/haproxy
stats socket /run/haproxy/admin.sock mode 660 level admin expose-fd listeners
stats timeout 30s
user haproxy
group haproxy
daemon
@kkroesch
kkroesch / kix_api.http
Created March 14, 2022 14:05
Kix REST API
### Requests for Kix API
@base_url = http://localhost:20000/api/v1
### Authorization
# @name request_auth_token
POST {{base_url}}/auth
{
@kkroesch
kkroesch / logstash.conf.j2
Created February 3, 2022 13:06
Logstash configuration template for polling weather api and store observations into Elasticsearch.
input {
http_poller {
urls => {
wunderground => "https://api.weather.com/v2/pws/observations/current?stationId=IDULLI1&format=json&units=m&apiKey={{ api_key }}"
}
request_timeout => 60
schedule => { cron => "0,15,30,45 * * * * UTC"}
codec => "json"
# A hash of request metadata info (timing, response headers, etc.) will be sent here
metadata_target => "http_poller_metadata"
@kkroesch
kkroesch / datamanager.py
Last active June 4, 2022 21:57
Persistent YAML with easy access.
import yaml
from dotmap import DotMap as DD
class DataManager:
""" Manages YAML data representation where members are accessible with dot notation.
"""
data_map = DD()
@kkroesch
kkroesch / qs.py
Created January 25, 2022 14:12
Calculate digit sum
def qs(k : int) -> int:
s = 0
while k:
s = s + k % 10
k = k // 10
return s
@kkroesch
kkroesch / phi.py
Last active January 21, 2022 12:25
Eulers Phi Function
from math import gcd
def φ(z):
return sum([gcd(z,k)==1 for k in range(1, z+1)])
@kkroesch
kkroesch / ast.py
Last active January 12, 2022 08:13
Model algebraic expressions
from dataclasses import dataclass
from numbers import Number
from unittest import TestCase
class Expression:
def derive(self, variable):
return self