Skip to content

Instantly share code, notes, and snippets.

View hadrianw's full-sized avatar

Hadrian Węgrzynowski hadrianw

View GitHub Profile
@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 / 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 / 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 / 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"
#!/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 / 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 / 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