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}
#!/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 / count.c
Created April 25, 2018 19:54
Atomic append test.
#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>
#include <stdlib.h>
#define LEN(x) (sizeof(x)/sizeof((x)[0]))
@hadrianw
hadrianw / blocks.c
Last active April 21, 2018 20:43
Blocks data structure for text editor.
#define _XOPEN_SOURCE
#include <assert.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
@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>