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 / README.md
Last active September 5, 2021 12:58 — forked from quiver/README.md
Python PostgreSQL PubSub

Pub/Sub pattern with PostgreSQL's LISTEN/NOTIFY command

This is a simple chat-like program using pub-sub pattern, backed by PostgreSQL's LISTEN/NOTIFY command.

Publish

publish message to foo channel from user nickname.

$ python pub.py foo nickname
PUBLISH to channel #foo
@MarkusH
MarkusH / turn-off-bluetooth-mic.sh
Created April 26, 2017 14:55
QC35 PulseAudio A2DP / HFP+HSP switcher
#!/bin/sh
MAC=XX_XX_XX_XX_XX_XX
NEW_SINK=bluez_sink.$MAC.a2dp_sink
pactl set-card-profile bluez_card.$MAC a2dp_sink
pactl set-default-sink $NEW_SINK
sink_inputs=$(pactl list | grep -P "Sink Input #\d+" | grep -Po "\d+")
for sink_input in $sink_inputs ; do
@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
" \
@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 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 / changes.patch
Created April 14, 2015 19:49
Postgresql function based indexes in Django (based on 825bb0ab08cec353edcd2b9aea651bfe9392ef97)
diff --git a/django/db/backends/postgresql_psycopg2/schema.py b/django/db/backends/postgresql_psycopg2/schema.py
index 8340059..692866e 100644
--- a/django/db/backends/postgresql_psycopg2/schema.py
+++ b/django/db/backends/postgresql_psycopg2/schema.py
@@ -1,6 +1,21 @@
import psycopg2
from django.db.backends.base.schema import BaseDatabaseSchemaEditor
+from django.db.models.expressions import Func
+from django.db.models.sql.compiler import SQLCompiler