Skip to content

Instantly share code, notes, and snippets.

View tuergeist's full-sized avatar

Christoph Becker tuergeist

View GitHub Profile
@tuergeist
tuergeist / AveryLabels.py
Last active May 28, 2024 12:23 — forked from timrprobocom/AveryLabels.py
A class to manage printing on Avery labels with ReportLab
import os
from collections.abc import Iterator
from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import LETTER, landscape
from reportlab.lib.units import inch, mm, cm
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
# Usage:
# label = AveryLabels.AveryLabel(5160)
@tuergeist
tuergeist / packme.sh
Created November 20, 2021 12:02
Pack dpendencies for aws lambda
echo "*** Packing environment ***"
pipenv lock --requirements > requirements.txt
pip install -r requirements.txt --prefix $LOCAL_PKG
PACKAGES_DIR=$(find . -name site-packages)
cd $PACKAGES_DIR
zip -r $ZIPFILE .
cd $OUR_WORKDIR
@tuergeist
tuergeist / website.py
Created November 20, 2021 11:30
Lamdba envent handler serving an HTML file
from pathlib import Path
def handler_name(event, context):
with Path('web/index.html').open() as file:
html = file.read()
response = {
"statusCode": 200,
"body": html,
"headers": {
@tuergeist
tuergeist / api.py
Last active November 19, 2021 19:03
Event handle for multipart form data
def handler_name(event, context):
try:
result = ''
content_type_header = event['headers']['content-type']
post_data = base64.b64decode(event['body']).decode('iso-8859-1')
for part in decoder.MultipartDecoder(
post_data.encode('utf-8'),
content_type_header
).parts:
result = reverse_it(part.text.split('\n'))
@tuergeist
tuergeist / get_container_ips.sh
Created March 10, 2021 09:51
Get docker container IP addresses
#!/usr/bin/env bash
# Docker Container IP
# Usage:
# get_container_ips.sh
# Prints out all IPs for running containers
#
# get_container_ips.sh <ID|name>
# Prints out the IP for a given container or ID
# https://docs.docker.com/engine/reference/commandline/ps/#formatting
@tuergeist
tuergeist / gist:7f0c418f556f312e942317eb09f2cf9d
Created January 20, 2020 14:00
ntopng admin password reset
# according to https://github.com/ntop/ntopng/issues/153
$ echo -n 'admin' |md5sum
21232f297a57a5a743894a0e4a801fc3
$ redis-cli SET ntopng.user.admin.password 21232f297a57a5a743894a0e4a801fc3
OK
# check
$ redis-cli GET ntopng.user.admin.password
@tuergeist
tuergeist / backup_lamda.sh
Created January 9, 2019 15:53
Backup all your AWS lambda functions code to local disk
for funcname in $(aws lambda list-functions| jq -rc '.Functions|.[]|.FunctionName') ; do
echo -n $funcname ...
wget $(aws lambda get-function --function-name $funcname | jq -rc '.Code.Location') -O $funcname -o /dev/null && echo ok || echo failed
done
@tuergeist
tuergeist / gist:340ab126a06d24d75965d9b0ec602635
Created January 9, 2019 07:26
kworker causes high load problem
# kworker has high load
# perf tools like `perf top` show acpi_ns_search_one_scope with high cpu
sudo perf record -g -a sleep 10
sudo perf report
# find bad interrupts
grep . -r /sys/firmware/acpi/interrupts/
# diasble bad interrupt
https://gist.github.com/StefanoBelli/0aab46b858a797c4eedb90e8799dffa2
# create pipenv shell elsewere and install django
pipenv install django
# go to the directory where your project shall reside in
export PROJECT=myproject
django-admin.py startproject --template=https://github.com/heroku/heroku-django-template/archive/master.zip --name=Procfile $PROJECT
# leave the current shell
# create / open a new shell in the project dir
cd $PROJECT
@tuergeist
tuergeist / iterm2.md
Last active June 29, 2018 06:03 — forked from aklap/iterm2.md
iTerm2 cheatsheet

iTerm2 Cheatsheet

Tabs and Windows

Function Shortcut
New Window + n
Go to Window Option + + Number
Fullscreen + Enter