Skip to content

Instantly share code, notes, and snippets.

View apsun's full-sized avatar

Andrew Sun apsun

View GitHub Profile

I recently decided to upgrade the headlight on my Brompton Electric bike to the Cyo Premium E. I followed https://www.youtube.com/watch?v=osCbgMQwlY0 but found the video lacking in detail, so this guide goes into more depth on the parts and procedure needed.

The main difficulty with this upgrade is that the Cyo headlight does not come with the Molex connector used on the stock Brompton headlight, so you'll need to either install the connector on the new light yourself, or remove both sides of the original connector and solder the wires together. I went with the former approach, as I found it a bit "cleaner", and avoids modifying the battery side of the wiring.

Requirements

Modding the Kinesis Advantage2

I recently became the owner of a Kinesis Advantage360, and thought it would be fun to replace the awful Cherry MX Browns in my old Advantage2 keyboard with some decent switches. I had read online that you could purchase replacement empty PCBs from Kinesis, but when I contacted them I was told that they stopped selling them years ago :-(

Well then, guess I'll have to do it myself!

Tools required

  • Phillips-head screwdriver
  • Soldering iron (I used the Pinecil, but any decent iron will do)
@apsun
apsun / repl.py
Last active December 22, 2023 06:12
One-liner to drop into a Python REPL
__import__("code").InteractiveConsole({**globals(), **locals()}).interact()
@apsun
apsun / ios-exif-rename.sh
Last active November 21, 2023 20:18
Rename iOS photos/videos using file metadata
#!/bin/bash
#
# A note on timezone handling: this script uses the local timezone in which
# the photo/video was originally taken.
#
# "CreateDate" stores the local time on images, but UTC on videos.
# "CreationDate" stores the full timestamp with timezone, but is only
# available on videos.
shopt -s nullglob

Windows 10 on an existing UEFI Linux setup

I will assume that we are starting from a Linux-only setup with free space available on the disk, e.g. by following everything at https://gist.github.com/apsun/1f7b1da40b028a9ed1e0409ca8c3b3cc.

Starting out, the disk should look like:

/dev/sda
  sda1 <-- ESP
  sda2 <-- Linux
@apsun
apsun / cpp_exceptions_tldr.md
Last active April 26, 2022 04:09
C++ Itanium ABI for exception handling

This aims to be a brief introduction to how C++ exceptions are implemented on Linux. It's based on an afternoon of reading and may contain serious inaccuracies, so read at your own risk.

We start from the point where an exception is thrown. First, we allocate an exception object on the heap using __cxa_allocate_exception. This exception object contains:

  • the actual object you're throwing (hereafter referred to as the "user exception")
  • a C++ exception library header (__cxa_exception) which contains:
    • the std::type_info and destructor of the user exception
    • a reference count for the exception
    • some other stuff which I'll gloss over for the sake of brevity
  • a language-agnostic unwind library header (_Unwind_Exception) which contains:
  • a tag specifying whether this is a C++ exception (it is!)
@apsun
apsun / lrucache.go
Last active May 15, 2022 13:10
LRU cache using Go 1.18 generics
package main
type lruNode[K comparable, V any] struct {
prev *lruNode[K, V]
next *lruNode[K, V]
key K
value V
}
type LRUCache[K comparable, V any] struct {
@apsun
apsun / archlinux.md
Last active November 21, 2023 20:16

Encrypted Arch Linux on UEFI

This documents how to install Arch Linux with full disk encryption under UEFI (not using secure boot, although it will be easy to enable later on if you want it). It assumes you're familiar with installing Arch Linux, but new to encryption/UEFI.

Partition the disk

Boot into the Arch Linux live USB and enter the installation environment.

Hereafter, /dev/sda refers to the disk you are installing Arch on. /dev/sda1 refers to the EFI system partition, and /dev/sda2 refers to the encrypted Linux partition.

@apsun
apsun / server.conf
Last active March 2, 2022 16:17
Unbound config for a forwarding DNS server for use with WireGuard
server:
verbosity: 1
interface: 0.0.0.0
interface: ::0
port: 53
tls-cert-bundle: /etc/ssl/certs/ca-certificates.crt
# allow access from anywhere
# access-control: 0.0.0.0/0 allow
# access-control: ::0/0 allow
@apsun
apsun / extdrv-backup.sh
Last active March 4, 2023 18:13
Backup files using rsync to an external disk encrypted with LUKS
#!/bin/bash
set -euo pipefail
EXTDRV_FILE='/dev/disk/by-uuid/408acd50-8b18-470c-b4f3-39d8e6351107'
EXTDRV_LABEL='extdrv'
EXTDRV_MOUNT='/mnt/extdrv'
SRC_ROOT='/home/andrew'
DEST_ROOT='/mnt/extdrv/andrew'