Skip to content

Instantly share code, notes, and snippets.

View kousu's full-sized avatar

Nick Guenther kousu

  • Asymmetric Research
  • Canada
View GitHub Profile
@kousu
kousu / nc-chdir.py
Created April 24, 2023 22:14
Prototype a workaround for unix domain socket length limit of 107.
#!/usr/bin/env python
# this is a tiny little clone of `nc -U -l path`
# but it creates the socket *after chdir()ing in a subprocess* to avoid ENAMETOOLONG:
#
# To test the difference, get openbsd-netcat and run:
#
# mkdir -p /tmp/abcdefhijklmnopqrstuvwxyz/abcdefhijklmnopqrstuvwxyz/abcdefhijklmnopqrstuvwxyz/abcdefhijklmnopqrstuvwxyz
# nc -v -U -l /tmp/abcdefhijklmnopqrstuvwxyz/abcdefhijklmnopqrstuvwxyz/abcdefhijklmnopqrstuvwxyz/abcdefhijklmnopqrstuvwxyz/ipc.sock
#
@kousu
kousu / README.md
Created January 12, 2023 23:50
Bridging Discord + XMPP

Just because the docs on https://github.com/42wim/matterbridge/wiki/ are a little bit obscure in some parts, here's a complete record of what I did:

  1. sudo pacman -S matterbridge
  2. Set up a generic systemd service file:
$ cat /etc/systemd/system/matterbridge\@.service 
[Unit]
Description=%I Chat Bridge
After=network-online.target
@kousu
kousu / .gitignore
Last active October 9, 2022 19:04
nifti demo
node_modules
@kousu
kousu / pip-integrity
Last active September 30, 2022 18:57
The missing `pip integrity` command
#!/usr/bin/env python3
#
# The missing 'pip integrity' command.
#
# This verifies the correctness of an unpacked pip package
# by examining the file hashes in the 'RECORD' file.
# spec at https://peps.python.org/pep-0427/#the-dist-info-directory
import sys
import base64
@kousu
kousu / README.md
Last active November 28, 2021 18:36
Linux du(1) de-duplication bug

I've found a confusing behaviour in Linux's version of du(1). du can take a single folder to recurse into, or list of files/folders either via --files0-from or in argv. But its behaviour is inconsistent if this list contains parents and children.

  1. A child given before its parent makes the parent count as empty
  2. With -s (or equivalently -d 0), a parent given before its child (vice versa) skips the child

OpenBSD's du conversely has consistent behaviour: it always outputs one line (or block of lines, if not given -s) per input, and always counts everything as full-sized, parent and child.

<?xml version='1.0' encoding='utf-8'?>
<MixxxControllerPreset schemaVersion="1" mixxxVersion="2.3.0">
<info>
<name>Akai MPK Mini</name>
</info>
<controller id="AkaiMPKMini">
<scriptfiles/>
<controls>
<!-- Master -->
@kousu
kousu / README.md
Created April 11, 2021 18:13
dockerize for travis-ci
@kousu
kousu / README.md
Last active April 8, 2021 22:13
extract functions

Extract an indented block from a file, starting from a given header line.

Usage: extract.awk HEADER file

e.g.

$ ./extract.awk a t
   a() {
@kousu
kousu / sanitize.py
Created April 5, 2021 09:31
Sanitize a file path against directory traversal in python
import os.path
def sanitize_path(path):
"""
Sanitize a path against directory traversals
Based on https://stackoverflow.com/questions/13939120/sanitizing-a-file-path-in-python.
>>> sanitize_path('../test')
'test'
@kousu
kousu / README.md
Last active March 26, 2021 19:50
showterm.io sh client, with https://github.com/ConradIrwin/showterm/issues/48 applied

showterm.io

Installation:

mkdir -p ~/.local/bin
curl https://gist.githubusercontent.com/kousu/855c164979af078f623fd44f0e1b5350/raw/6536924551c9de7143492c407f4e584389ba3f9f/showterm > .local/bin/showterm
chmod +x .local/bin/showterm