Skip to content

Instantly share code, notes, and snippets.

View cfra's full-sized avatar
🚀

Christian Franke cfra

🚀
View GitHub Profile
@cfra
cfra / telegraf-opendtu-http.toml
Created September 7, 2024 18:23
Use HTTP JSON API to collect OpenDTU information with Telegraf
[[inputs.http]]
name_override = "opendtu"
urls = [
"http://opendtu.example.com/api/livedata/status?inv=123456788", # Inverter 1
"http://opendtu.example.com/api/livedata/status?inv=123456789", # Inverter 2
]
data_format = "json_v2"
[[inputs.http.json_v2]]
[[inputs.http.json_v2.tag]]
path = "inverters.0.serial"
@cfra
cfra / wireguard-howto.md
Created August 3, 2024 15:47
Simple Wireguard Server Config

Wireguard auf dem Server

apt update
apt upgrade
apt install wireguard

cd /etc/wireguard
umask 077
wg genkey | tee server.priv | wg pubkey > server.pub
@cfra
cfra / steps.md
Last active January 10, 2024 19:58
Django Custom user Model migration path

Steps to migrate existing Django app to new user model

This all refers to PostgreSQL, on other databases it will probably be different.

  1. Create the new User model as an exact copy of django.contrib.auth.models.User (we assume it will be user.User then)

  2. Create the migrations and commit them

  3. Run the following SQL to simulate that the migration has run

SELECT * FROM django_migrations_id_seq;

@cfra
cfra / amp-calc.md
Created December 6, 2022 17:14
Musings about audio amplifiers and their gain/power aspects
@cfra
cfra / send-sms.py
Created September 27, 2021 21:31
Send SMS using the Huawei HiLink API
#!/usr/bin/env python
#
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
# Version 2, December 2004
#
# Copyright (C) 2004 Sam Hocevar 14 rue de Plaisance, 75014 Paris, France
# Everyone is permitted to copy and distribute verbatim or modified
# copies of this license document, and changing it is allowed as long
# as the name is changed.
#
@cfra
cfra / targeted-ddrescue.md
Last active May 7, 2023 10:41
How to use ddrescue to recover allocated areas or specific files from a filesystem on a failing disk

Situation

We have a failing disk.

There is data on the disk that we would like to recover, if at all possible.

We can still access the disk using ddrescue, but it is really slow, when we just try to dump the disk, estimated runtime is more than a year.

We are not actually interested in all the blocks of the disk: There are only specific

@cfra
cfra / passmenu-otp.diff
Created July 22, 2021 09:28
Use totp python package to generate totp tokens from pass menu
--- /usr/bin/passmenu 2021-06-12 18:06:38.000000000 +0200
+++ /usr/local/bin/mypassmenu 2021-07-22 11:19:24.138521764 +0200
@@ -28,6 +28,20 @@
[[ -n $password ]] || exit
+if [[ ${password%-otp} != ${password} ]]; then
+ code_file="$prefix/2fa/$password/code.gpg"
+ [[ -e "$code_file" ]] || {
+ mkdir -p "$prefix/2fa/$password"
@cfra
cfra / modeltranslation_edithandler.py
Created July 14, 2021 18:30
Wagtail EditHandler for fields translated with django-modeltranslations
from django.conf import settings
from django.db.models.fields import NOT_PROVIDED
from wagtail.admin.edit_handlers import FieldPanel, MultiFieldPanel
class TranslatedFieldPanel(MultiFieldPanel):
"""
Allow editing of translated fields.
@cfra
cfra / har_hosts.py
Created June 30, 2021 13:03
Extract Hosts from HAR
#!/usr/bin/env python3
import json
import sys
try:
file_path = sys.argv[1]
except IndexError:
sys.stderr.write(f"Usage: {sys.argv[0]} <file_path>\n")
sys.exit(1)
@cfra
cfra / async-network-reload.yml
Created June 29, 2021 13:20
Ansible: Use async task to work around unreachable Host while reloading networking configuration
---
- name: Reload networking (in-band)
service:
name: networking
state: reloaded
- name: Reload networking (out-of-band)
shell: ifreload --allow=mgmt
async: 45