Skip to content

Instantly share code, notes, and snippets.

@dakhnod
dakhnod / README.md
Last active September 15, 2025 14:58

Scammer IP reporter

I creates this little configuration in order to get notified whenever someone visits a particular URL I created.

More specifically, this configuration requires the following setup:

  1. Some program that sends a message to you, passed as parameters. In my case, an invocation could look like /root/bin/msg this is a message
  2. Apache2 running
  3. The ability to create and activate an apache2 configuration

The main purpose of this gist is to show to the world that apache can write log data not only to files, but also pipe it directly to scripts, in my case xargs.

@dakhnod
dakhnod / pause-all.sh
Last active September 1, 2025 13:20
Script to pause and resume all playback on your linux computer
#!/bin/bash
busses=$(dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.ListNames | grep -oP "(?<=string \")org.mpris.MediaPlayer2.*instance.*(?=\")")
for bus in $busses; do
dbus-send --print-reply --dest=$bus /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Pause
done
@dakhnod
dakhnod / 09-network
Created February 20, 2025 00:20
Control your GRUB boot device (and other settings) via HTTP!
#!/usr/bin/env cat
net_dhcp
source (http,destination_ip_or_host:destination_port)/grub/config
@dakhnod
dakhnod / 00-dns-clean
Last active December 7, 2025 02:09
Automatic certificate renewal using certbot, letsencrypt and hetzner API
#!/bin/bash
set -e
API_KEY='YOUR_HETZNER_API_TOKEN'
ids=`curl \
-s \
--header "Auth-API-Token: ${API_KEY}" \
"https://dns.hetzner.com/api/v1/records" \

mount.img

This utility allows mounting .img files containing multiple partitions to the FS.

Usage

mount.img /path/to/file.img 2 /mnt/mount/point

with 2 being the partition index, as fdisk -l /path/to/file.img reports. First partition is 1.

@dakhnod
dakhnod / README.md
Last active November 28, 2024 15:17
Pulse audio sine wave example

Sine wave player

This example demonstrates how to play a sine wave through Pulse audio. Keep in mind that this code does NOT do any error handling. This is about the minimal amount code needed to play a sine wave.

How to compile

sudo apt install libpulse-dev
gcc sine.c -o play -lm -lpulse-simple
@dakhnod
dakhnod / README.md
Created October 11, 2024 12:50
Comparison of Varta batteries

This information has been extracted from Varta datasheets.

Type Capacity
Longlife AA 2800
Longlife Power AA 2970
Longlife Max Power AA 2980
Industrial Pro AA 2970
Longlife AAA 1230
Longlife Power AAA 1270
@dakhnod
dakhnod / mount_file
Created October 10, 2024 14:06
Utility to mount a partition from a disk image
#!/bin/bash
if [[ ! "$1" || ! "$2" || ! "$3" ]]; then
echo "Usage: mount_file IMAGE PARTITION_NUMBER MOUNTPOINT"
exit 1
fi
line=(`fdisk -l "$1" | tr -d '*' | grep "$1$2"`)
mount -o loop,offset=$((512 * ${line[1]})),sizelimit=$((512 * ${line[3]})) $1 $3
@dakhnod
dakhnod / README.md
Last active October 7, 2024 11:57
One-liner Arduino binary counter

One-line arduino binary counter

let's talk about how this works. Firstly, the rightmost expression calculates the passed seconds using millis(). millis() returns the milliseconds since boot of the arduino. By dividing through 1000 we get the number of seconds passed, as int.

Now about the PORTB register: This register controls the data on the output pins. Looking at pinouts, we can determine that Arduino UNO pins 8, 9, and 10 (and so forth) are connected to PB0, PB1, PB2, ..., or PORTB in general. Thus, setting the first bit of PORTB to 1 will lead to voltage being applied to pin 8. Here are some example values:

@dakhnod
dakhnod / app.js
Created September 26, 2024 09:32
Benchmark RAM usage of multiple node instances
await new Promise((resolve) => {
setTimeout(resolve, 60000);
})