Skip to content

Instantly share code, notes, and snippets.

View gsauthof's full-sized avatar

Georg Sauthoff gsauthof

View GitHub Profile
@gsauthof
gsauthof / compare_version.py
Created July 14, 2022 14:38
distutils.version.LooseVersion replacement
View compare_version.py
import operator
import re
split_version_re = re.compile('[.+-]')
class LooseVersion:
def __init__(self, s):
self.vs = split_version_re.split(s)
self.n = max(len(x) for x in self.vs)
def cmp(self, other, op):
@gsauthof
gsauthof / http_dump.py
Last active September 1, 2023 08:32
Listen for and dump HTTP requests to STDOUT
View http_dump.py
#!/usr/bin/env python3
# SPDX-FileCopyrightText: © 2022 Georg Sauthoff <mail@gms.tf>
# SPDX-License-Identifier: BSL-1.0
import argparse
import http.server
import json
import sys
@gsauthof
gsauthof / pwm_ir_send.ino
Created February 6, 2022 20:42
Arduino sketch for transmitting a raw IR remote control code without dependencies
View pwm_ir_send.ino
// 2022, Georg Sauthoff <mail@gms.tf>
void setup() {
Serial.begin(9600);
Serial.println("Ready.");
cli(); // atomic section
// set Arduino Pin 3 low
PORTD &= ~ _BV(PORTD3);
@gsauthof
gsauthof / samsung-860-evo-kern.log
Last active August 10, 2021 20:40
Samsung 860 EVO kernel errors
View samsung-860-evo-kern.log
Dec 20 21:24:24 sos.lru.li kernel: ata3.00: exception Emask 0x10 SAct 0xffffffff SErr 0x440100 action 0x6 frozen
Dec 20 21:24:24 sos.lru.li kernel: ata3.00: irq_stat 0x08000000, interface fatal error
Dec 20 21:24:24 sos.lru.li kernel: ata3: SError: { UnrecovData CommWake Handshk }
Dec 20 21:24:24 sos.lru.li kernel: ata3.00: failed command: READ FPDMA QUEUED
Dec 20 21:24:24 sos.lru.li kernel: ata3.00: cmd 60/00:00:00:50:42/01:00:13:00:00/40 tag 0 ncq dma 131072 in
res 40/00:08:00:51:cf/00:00:0f:00:00/40 Emask 0x10 (ATA bus error)
Dec 20 21:24:24 sos.lru.li kernel: ata3.00: status: { DRDY }
Dec 20 21:24:24 sos.lru.li kernel: ata3.00: failed command: WRITE FPDMA QUEUED
Dec 20 21:24:24 sos.lru.li kernel: ata3.00: cmd 61/00:08:00:51:cf/01:00:0f:00:00/40 tag 1 ncq dma 131072 out
res 40/00:08:00:51:cf/00:00:0f:00:00/40 Emask 0x10 (ATA bus error)
@gsauthof
gsauthof / samsung-860-evo-smart.log
Created December 7, 2020 20:49
smartctl -a output for a samsung SSD as discussed in https://unix.stackexchange.com/q/623238/1131
View samsung-860-evo-smart.log
smartctl 7.1 2019-12-30 r5022 [x86_64-linux-5.8.18-300.fc33.x86_64] (local build)
Copyright (C) 2002-19, Bruce Allen, Christian Franke, www.smartmontools.org
=== START OF INFORMATION SECTION ===
Model Family: Samsung based SSDs
Device Model: Samsung SSD 860 EVO 250GB
Serial Number: [..]
LU WWN Device Id: [..]
Firmware Version: RVT04B6Q
User Capacity: 250,059,350,016 bytes [250 GB]
View ptp-offset-ioctl.log
# I218-V rev 4, e1000e, Core i5 Haswell, CentOS 7
ptp-clock-offset /dev/ptp0
## Testing PTP_SYS_OFFSET ioct (1128283397)
PTP_SYS_OFFSET no 1: -710924824 ns, delay: 6734 ns
PTP_SYS_OFFSET no 2: -710922059 ns, delay: 3873 ns
PTP_SYS_OFFSET no 3: -710922092 ns, delay: 3889 ns
PTP_SYS_OFFSET no 4: -710922078 ns, delay: 3888 ns
PTP_SYS_OFFSET no 5: -710922096 ns, delay: 3939 ns
## Testing PTP_SYS_OFFSET_EXTENDED ioctl (3300932873)
@gsauthof
gsauthof / enter_chroot.sh
Created March 21, 2020 21:31
Chroot Example
View enter_chroot.sh
# assuming /mnt/root/{root,home} are mounts of anothers system root+home filesystems
cd /mnt/root/root
mount --bind /proc proc
mount --bind /sys sys
mount --bind /dev dev
cp /etc/resolv.conf etc/
cd /mnt/root
mount --bind home root/home
chroot root /usr/bin/zsh
@gsauthof
gsauthof / filter_env.c
Created February 6, 2020 20:24
Remove environment variable from /proc/$pid/environ under Linux
View filter_env.c
/* Demonstrate how to remove an environment variable from /proc/$pid/environ,
under Linux.
This pseudo file is accessible by other processes with sufficient privileges
(i.e. same user or root) and exposes the original environment vector.
Removing sensitive variables from it can be part of a defense in depth
strategy (i.e. to make it harder for a casual attacker to access it).
*/
/** {{{ MIT No Attribution
@gsauthof
gsauthof / futex_demo.c
Created October 25, 2019 17:25
Fix deadlock, busy waiting and comments in futex example from http://man7.org/linux/man-pages/man2/futex.2.html
View futex_demo.c
/* futex_demo.c
Usage: futex_demo [nloops]
(Default: 5)
Demonstrate the use of futexes in a program where parent and child
use a pair of futexes located inside a shared anonymous mapping to
synchronize access to a shared resource: the terminal. The two
processes each write 'num-loops' messages to the terminal and employ
a synchronization protocol that ensures that they alternate in
@gsauthof
gsauthof / redact_env.c
Created July 27, 2019 11:59
Redact environment variable under Linux
View redact_env.c
/* Demonstrate how to overwrite the original value of
an environment variable in the original environment vector
that is easily observable from other processes
(with sufficient permissions, i.e. same user or root).
*/
/** {{{ MIT No Attribution
Copyright 2019 Georg Sauthoff <mail@georg.so>