Skip to content

Instantly share code, notes, and snippets.

View MarkusH's full-sized avatar
🐍

Markus Holtermann MarkusH

🐍
View GitHub Profile
@MarkusH
MarkusH / serial-to-identity.sql
Last active April 25, 2024 12:26
A script that outputs the raw SQL to convert Django's serial columns to identity columns.
WITH tab AS (
SELECT
a.attrelid::regclass::text AS t,
a.attname AS c,
pg_get_serial_sequence(a.attrelid::regclass::text, a.attname) AS s,
nextval(pg_get_serial_sequence(a.attrelid::regclass::text, a.attname)) AS v
FROM pg_attribute a
JOIN pg_class c ON c.oid = a.attrelid
WHERE
a.attrelid::regclass::text LIKE '%'
@MarkusH
MarkusH / django_model_er_plantuml_plot.py
Created October 6, 2022 07:07
Print plantuml instructions for an ER diagram of all Django models
from django.apps import apps
HEADER = """@startuml
skinparam linetype ortho
"""
FOOTER = """@enduml"""
Models = apps.get_models()
use std::fs::File;
use std::io::prelude::*;
const BYTES_PER_LINE: usize = 16;
fn main() {
let mut f= File::open("/tmp/file.txt").unwrap();
let mut pos = 0;
let mut buffer = [0; BYTES_PER_LINE];
@MarkusH
MarkusH / ffmpeg.sh
Created May 9, 2021 16:40
Talk recording
#!/usr/bin/bash
ffmpeg \
-f alsa -sample_rate 44100 -thread_queue_size 1024 -itsoffset -0.5 -i hw:0 \
-f x11grab -r 30 -thread_queue_size 1024 -i :0.0 \
-f v4l2 -r 30 -video_size 320x180 -thread_queue_size 1024 -i /dev/video0 \
-filter_complex "
[1:v]scale=1920x1080[slides];
[slides][2:v]overlay=x=1580:y=20
" \
import base64
import hmac
import json
import secrets
def gen_token(key: bytes, data) -> str:
payload = json.dumps(data).encode()
mac = base64.urlsafe_b64encode(hmac.new(key, payload, "sha256").digest())
return base64.urlsafe_b64encode(payload).decode() + "." + mac.decode()
@MarkusH
MarkusH / remote.txt
Last active April 25, 2020 13:42
Speaker Checklist
╔═══════════════╤══════════════╤═══╗
║ Door │ CLOSED │ X ║
╟╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╢
║ Headphones │ OFF │ X ║
╟╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╢
║ Phone │ SILENT │ X ║
╟╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╢
║ Watch │ SILENT │ X ║
╟╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╢
║ Headset │ ON │ X ║
@MarkusH
MarkusH / arch-linux-install
Last active January 29, 2021 11:14 — forked from mattiaslundberg/arch-linux-install
Minimal instructions for installing arch linux on an UEFI system with full system encryption using dm-crypt and luks
# Install ARCH Linux with encrypted file-system and UEFI
# The official installation guide (https://wiki.archlinux.org/index.php/Installation_Guide) contains a more verbose description.
# Download the archiso image from https://www.archlinux.org/
# Copy to a usb-drive
dd if=archlinux.img of=/dev/sdX bs=16M && sync # on linux
# Boot from the usb. If the usb fails to boot, make sure that secure boot is disabled in the BIOS configuration.
# Optionally set another keyboard layout. E.g. German
data_dir = "/var/lib/vector"
# Sources
[sources.nginx_access_logs]
type = "file"
exclude = ["/var/log/nginx/error.log"]
include = ["/var/log/nginx/*.log"]
file_key = "log"
host_key = "server"
#import *;
PyCon_Day = "3";
while PyCon_Day == str(3):
print("It is ");
print("Monday");
"""Tells us it's Monday""";
def Need_Coffee(foo: Boolean):
if str(foo) == "True":
@MarkusH
MarkusH / b64uuid.py
Created July 10, 2019 22:06
Base64 Encoding of UUIDs
>>> import base64, binascii, uuid
>>>
>>> def encode(uid: uuid.UUID) -> str:
... return base64.urlsafe_b64encode(uid.bytes).decode().rstrip("=")
...
>>> def decode(uid: str) -> uuid.UUID:
... return uuid.UUID(binascii.b2a_hex(base64.urlsafe_b64decode(uid_b64 + "==")).decode())
...
>>> uid = uuid.UUID("12546fd8-6dd9-4923-9c0a-f1fefadd3e2b")
>>> uid