Skip to content

Instantly share code, notes, and snippets.

View hadrianw's full-sized avatar

Hadrian Węgrzynowski hadrianw

View GitHub Profile
@hadrianw
hadrianw / avahi-notify.py
Created April 9, 2024 20:19
Minimal notification service for Avahi services
#!/usr/bin/env python
"""
example use:
./avahi-notify.py - notify for all interfaces
./avahi-notify.py eth0 - notify only for eth0 interface
"""
import io
import subprocess
import sys
@hadrianw
hadrianw / merge.py
Last active February 21, 2024 22:11
Deep merge two Python dicts with dict comprehensions
def merge(original: dict, update: dict):
return {
k: (merge(original[k], v) if M and isinstance(v, dict) and k in original else v)
for d, M in ((original, False), (update, True))
for k, v in d.items()
}
if __name__ == "__main__":
base = {"foo": 1, "bar": {"abc": 123, "def": 456}, "baz": 2}
@hadrianw
hadrianw / siteprep.sh
Last active March 13, 2023 08:49
NIH syndrome induced SSG.
#!/bin/bash
set -e
VERSION="siteprep-1"
EXT=".html"
HEAD='<!DOCTYPE html>
<meta charset=utf-8>
<meta name=viewport content="width=device-width,initial-scale=1">
<style>
@hadrianw
hadrianw / shebang.c
Last active November 13, 2022 21:30
Make a C file executable with those few lines.
#if 0
set -e; [ "$0" -nt "$0.bin" ] &&
gcc -Wall -Wextra -pedantic -std=c99 "$0" -o "$0.bin"
exec "$0.bin" "$@"
#endif
#include <stdio.h>
int
main(int argc, char *argv[]) {
#!/usr/bin/env python3
"""
A service to toggle play/pause of a Chromecast via Play multimedia key.
Requires running as root because of the "keyboard" module.
requirements: pychromecast keyboard
"""
chromecast_name = "Salon"
@hadrianw
hadrianw / xbps-build-check.sh
Created June 23, 2019 11:37
Build check for xbps packages.
#!/bin/sh
set -x
set -e
pkg="$1"
repo="$2"
function __BUILD__() {
local pkg="$1"
local arch="$2"
@hadrianw
hadrianw / forktest.c
Last active January 29, 2019 13:51
Test Linux fork/vfork+exec(dynamic/static binary) performance. Dependecies: gcc, musl-dev, musl-tools (musl-gcc). Usage: $ chmod +x forktest.c $ ./forktest.c 100000
#if 0
set -e;
cflags="-O2 -Wall -Wextra -pedantic -std=c99"
[ "$0" -nt "$0-regular.bin" ] &&
gcc $cflags -lpthread "$0" -o "$0-regular.bin"
[ "$0" -nt "$0-static.bin" ] && {
mkdir -p musl-inc
@hadrianw
hadrianw / Rantfile.md
Last active July 5, 2018 10:36
I don't enjoy this software.

Rantfile

Google Maps

Problem:

  1. Click on some place that has a website.
  2. Middle-click on the apparent link to open it in a new tab - nothing happens.

Solution:

@hadrianw
hadrianw / gdb-strace.sh
Last active June 14, 2018 12:10
strace with backtrace thanks to gdb
#!/bin/sh
cmd=$1
shift
# FIXME: it would be good for every argument to be wrapped in quotes
echo run $@ | gdb "$cmd" -x strace.gdb &> gdb-strace-log
@hadrianw
hadrianw / index.c
Last active May 31, 2018 21:59
Dumb benchmark for VPS performance measurment.
#include <ftw.h>
#include <stdio.h>
#include <sqlite3.h>
#define INSERT_QUERY "INSERT INTO index VALUES (?, ?)",
static sqlite3 *db;
static sqlite3_stmt *insert_stmt;
static int step(const char *path, const struct stat *sb, int flag, struct FTW *ftwbuf)