Skip to content

Instantly share code, notes, and snippets.

@kousu
kousu / README.md
Last active December 1, 2025 23:33
CGNat hole punching

NAT Hole Punching

I've never fully understood how NAT traversal works and I went on a dive today.

Run whatismyip.py on a public server. This plays the role of a STUN server.

Run easynat.py on a laptop behind a home router.

You could run hardnat.py also on a laptop behind a home router, but don't do it on the same home router because "hairpinning" is almost always broken.

@kousu
kousu / README.md
Created July 2, 2025 14:52
Magic Wormhole Receive for Android

This makes magic-wormhole(1) much more accessible by putting it on your Android home screen.

Once installed, usage is:

  1. scan QR code from wormhole send or have sender tell you the code and copy it to your clipboard
  2. Run 'wormhole-receive'
  3. Paste scanned/copied code into prompt
  4. Downloads end up in /sdcard/Downloads/

TODO

@kousu
kousu / README.md
Last active June 27, 2025 23:31
DIY markdown wiki sync

Cloud-reduced Markdown Wiki (WIP)

This is a way to write and share notes for yourself between multiple devices, without signing up for locked-in cloud services, using only future-proof formats and open tools!

This is built on Android and Obsidian, which are only semi-open, but because it's built on syncing with git and markdown if you need to replace the platform you can, because markdown and git work everywhere and will continue to work everywhere for a long time.

@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'

For all of you wanting this feature there's a great option out there if you're willing to step beyond Signal: Conversations. There's no primary/secondary distinction: it does true-multi-device multi-key encryption (they adopted libsignal and built on it and I'm very grateful that OWS developed and released it so it could be built upon), as well as video chat, file attachments (encrypted, of course), and cross-device history syncing, and all that at 1/3rd the size of Signal, and without a dependency on push notifications. And you can pretty easily set up alt identities and use them on the same devices so there's no need to worry about [giving out a private number](https://www.vice.com/en_us/article/9kaxge/how-to-use-signal-without-giving-out-your-phone-number-a-gender

@kousu
kousu / README.md
Last active May 7, 2025 04:39
Upgrading Galaxy Tab E SM-560NU (gtelwifiue) to LineageOS 19.1

The Galaxy Tab E is an unsupported and somewhat dated device now, but there are a lot of them in the world and they have a nice screen that's comfortable for reading or watching shows. Here is how to keep one alive, if you have it, by updating its OS to 2025. Credit for the build goes to @retiredtab (https://sourceforge.net/projects/retiredtab/). Google(?) is no longer doing firmware security updates, and so @retiredtab has decided this is the last build they are going to make, so there will be no more updates unless someone else picks maintenance up. Do not put any sensitive data on this device, but it makes a good e-book reader or youtube/Netflix viewer.

This guide assumes you have a desktop machine with Linux and ~1GB of free space.

Verify model

Look at Tablet > Settings > About Tablet > model. Verify it says SM-T560NU.

@kousu
kousu / README.md
Last active April 14, 2024 00:55
Using jose-util with ed25519 (aka EdDSA), PEM-formatted, keys

Using jose-util with ed25519 (aka EdDSA), PEM-formatted, keys

Using go-jose takes a bit of a knack. And it turns out there's a snag if you want to use the latest and greatest crypto.

I installed jose-util from the latest git version:

$ pwd
/Users/kousu/src/go-jose
anaesthetic-mac:go-jose kousu$ git log HEAD~1..HEAD
@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