Skip to content

Instantly share code, notes, and snippets.

View tuergeist's full-sized avatar

Christoph Becker tuergeist

View GitHub Profile
@tuergeist
tuergeist / kill_processes_for_port.sh
Created September 8, 2016 12:39
Kill all processes that appear to listen to a specific port
PORT=10514
while n=$(netstat -tupln | grep $PORT | egrep -oh '(([0-9]*))\/' | grep -oh '[0-9]*') ; do kill $n ; done
from copy import deepcopy
def get_parents(parents_dict, node):
parents = parents_dict.get(node,{})
for parent in deepcopy(parents):
parents += get_parents(parents_dict, parent)
return parents
@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
# 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 / 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
@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: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 / 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 / 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 / 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": {