Skip to content

Instantly share code, notes, and snippets.

View MarkusH's full-sized avatar
🐍

Markus Holtermann MarkusH

🐍
View GitHub Profile
@MarkusH
MarkusH / warn_too_many_queries.py
Created June 13, 2019 14:33
Warn on too many queries in context
import logging
from contextlib import contextmanager
from inspect import getframeinfo, stack
from django.db import connections
logger = logging.getLogger(__name__)
@contextmanager
@MarkusH
MarkusH / create.py
Last active February 1, 2019 21:59
GraphQL graphene-python pain
from graphene import Argument, InputObjectType, Mutation, String
class ThingInput(InputObjectType):
foo = String(required=True)
class OtherInput(InputObjectType):
bar = String(required=True)
class ComponentsInput(InputObjectType):
thing = Argument(ThingInput, required=True)
@MarkusH
MarkusH / mail.md
Last active November 22, 2018 20:15
Datenleck Mathekalender (Matheon, TU Berlin)

Sehr geehrte Damen und Herren,

Sie haben in den letzten Jahren am MATHEON-Adventskalender teilgenommen und im Rahmen der Anmeldung Ihre E-Mail-Adresse und, falls Sie an dem Gewinnspiel teilgenommen haben, die folgenden Daten angegeben:

  • Name, Geschlecht, Adresse, Telefonnummer, Status (Schüler/Erwachsener), woher Sie den Mathekalender kennen
  • Für Schüler: Klassenstufe, Name und Adresse der Schule
  • Für Erwachsene: Abschluss, Titel und Beruf

Außerdem wurden die IP-Adresse, der Host (z.B. "beispiel.inf.fu-berlin.de" oder "beispiel.di0.t-ipconnect"), der Browser (user agent) und natürlich die Ergebnisse bzw. abgegebenen Antworten bei dem Mathekalender gespeichert.

Am 19.10. haben wir alle alten Benutzerdaten aus der Mathekalender-Datenbank gelöscht und davor ein Backup gemacht, um die Datenbank wiederherstellen zu können, falls bei dem Löschen etwas schiefgehen sollte. Die Funktionsfähigkeit des Backups haben wir auf einem Server der TU Berlin getestet. Am 19.11. fiel uns auf, dass die Ordner auch auf ander

@MarkusH
MarkusH / totp.sh
Last active September 24, 2019 01:14
Simple Bash TOTP client
#!/bin/bash
# Copyright (c) 2018, info AT markusholtermann DOT eu
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
@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
# Copyright 2017, Markus Holtermann
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
@MarkusH
MarkusH / 2016-11-15.md
Created November 15, 2016 18:42
Last Month in Django
convert file1 file2 file3 -compress JPEG -resize 1140x1653 -gravity Center -extent 1240x1753 -units PixelsPerInch -density 150x150 out.pdf
@MarkusH
MarkusH / test.sh
Created September 21, 2016 06:32
Check if GPG key is expiring soon (next 30 days)
#!/usr/bin/sh
test $(($((`gpg --with-colons --fixed-list-mode --list-keys 0xAFE79D68D41C7E39 | egrep '^(pub|sub):' | cut -d: -f7 | sort | head -n 1` - `date +"%s"`))/86400)) -le 30 && echo "expiring soon" || echo "still good"
@MarkusH
MarkusH / migrations.md
Last active September 1, 2016 03:43
Move a model to another app

Definitions

  • old_app -- App that holds the old model
  • new_app -- App that holds the new model
  • others -- Placeholder for all apps that reference this model with a FK, O2O, M2M field or by inheriting from it (not for abstract model inheritance)

old_app

0001_rename_model_table

A migration with AlterModelTable('old_app_mymodel', 'new_app_mymodel')