Skip to content

Instantly share code, notes, and snippets.

View cristiklein's full-sized avatar

Cristian Klein cristiklein

View GitHub Profile
@cristiklein
cristiklein / Code.gs
Created April 13, 2024 09:37
Determine if the school is open on a given Date in Lomma, SE. Works as an App Script in Google Sheets.
/**
* Copy-pasted from here:
* https://lomma.se/utbildning-och-barnomsorg/grundskola/terminer-och-lov.html
*/
const text_from_lomma_se = `;
Vårterminen 2024
2024-01-10 - 2024-06-13
Studiedagar*
2024-01-08 (även fritidshemmet stängt)
2024-01-09
@cristiklein
cristiklein / rclone.service
Created December 10, 2023 18:19
autosync with rclone and systemd
[Path]
MakeDirectory=true
PathChanged=%h/Drive
[Install]
WantedBy=paths.target
@cristiklein
cristiklein / dataurify
Created September 9, 2023 21:13
Convert any file into a data: URI
#!/bin/sh
if [ $# -ne 1 ]; then
echo "Usage: $0 FILENAME"
exit 1
fi
mimetype=$(file -bN --mime-type "$1")
content=$(base64 -w0 < "$1")
echo "url('data:$mimetype;base64,$content')"
@cristiklein
cristiklein / tcpdump.service
Created March 12, 2023 12:46
systemd unit to record DNS and DHCP requests
# systemd unit to record DNS and DHCP requests
#
# Setup:
# sudo systemctl edit tcpdump --full --force
# # copy-paste the code below
# sudo systemctl enable tcpdump
# sudo systemctl status tcpdump # should show "loaded" and "active"
#
# Usage:
# # reboot your workstation
@cristiklein
cristiklein / get-laptop-and-screen-info.sh
Last active August 19, 2022 08:48
Get laptop and screen info, i.e., make, model and serial number
#!/bin/bash
sudo echo "Sudo successful"
echo "== START user info =="
echo "Username: $USER"
echo "Fullname: $(getent passwd $USER | cut -d: -f5 | cut -d, -f1)"
echo "== END user info =="
echo "== START laptop info =="
sudo dmidecode -t system | grep 'Manufacturer:'
@cristiklein
cristiklein / Dockerfile
Last active August 18, 2022 08:59
Open browser window in the host from a container
FROM ubuntu:22.04
RUN apt-get update && apt-get install -y \
socat \
&& rm -rf /var/lib/apt
COPY x-www-browser /usr/bin/x-www-browser
RUN chmod +x /usr/bin/x-www-browser
@cristiklein
cristiklein / remove-all-resources-in-a-Kubernetes-namespace.sh
Last active May 20, 2022 06:35
How to delete all resources in a Kubernetes namespace
# List of namespaced resources in a namespace
kubectl get $(kubectl api-resources --namespace=true -o name | paste -sd,)
# Actually delete them
kubectl delete $(kubectl api-resources --namespace=true -o name | paste -sd,) --all
@cristiklein
cristiklein / nuke-rook.sh
Created June 14, 2021 08:45
Nuke a Rook data
#!/bin/bash
ansible all -i inventory.ini --become --become-user=root -m shell -a 'hostname; rm -rf /var/lib/rook; umount /mnt; sgdisk --zap-all /dev/sdb; dd if=/dev/zero of="/dev/sdb" bs=1M count=100 oflag=direct,dsync; ls /dev/mapper/ceph-* | xargs -I% -- dmsetup remove %; rm -rf /dev/mapper/ceph-*; rm -rf /dev/ceph-*; partprobe /dev/sdb; ls -l /dev/mapper; lsblk'
@cristiklein
cristiklein / test-cloud-init.sh
Last active January 11, 2024 07:07
Short script to quickly test cloud-init configuration files
#!/bin/bash
set -e
IMAGE_URL=https://cloud-images.ubuntu.com/bionic/current/bionic-server-cloudimg-amd64.img
IMAGE_FILE=$(basename $IMAGE_URL)
if [ ! -e $IMAGE_FILE ]; then
wget $IMAGE_URL
fi
@cristiklein
cristiklein / mve.py
Created August 12, 2016 16:45
MVE for performance bug in `flask_restful.fields.Url`
#!/usr/bin/env python3
from flask import Flask
from flask_restful import fields, reqparse, Api, Resource, marshal
import time
app = Flask(__name__)
api = Api(app)
items_fields = {
'info': fields.String,