Skip to content

Instantly share code, notes, and snippets.

View apsun's full-sized avatar

Andrew Sun apsun

View GitHub Profile
@apsun
apsun / build.gradle.kts
Last active May 10, 2024 14:17
Documented build.gradle for publishing an Android library to Maven Central
// This is a documented version of the build.gradle file from RemotePreferences:
// https://github.com/apsun/RemotePreferences/blob/master/library/build.gradle.kts
//
// It aims to explain exactly WTF is going on when you inevitably copy-paste
// someone's build.gradle from the internet and can't figure out why it's not
// working.
//
// It contains, to the best of my knowledge, the best practices as of Oct 2023 for
// building an Android library and publishing it to OSSRH (Maven Central).
//
@apsun
apsun / hax.c
Last active April 22, 2024 05:49
Hook main() using LD_PRELOAD
/*
* Hook main() using LD_PRELOAD, because why not?
* Obviously, this code is not portable. Use at your own risk.
*
* Compile using 'gcc hax.c -o hax.so -fPIC -shared -ldl'
* Then run your program as 'LD_PRELOAD=$PWD/hax.so ./a.out'
*/
#define _GNU_SOURCE
#include <stdio.h>
#!/bin/sh
#
# Sync music from Linux to iPhone using libimobiledevice + ifuse
# Only works with apps that can read songs from iTunes file sharing (e.g. Doppi)
set -euo pipefail
if [ $# -ne 1 ]; then
echo "usage: $0 <src dir>"
exit 1
/*
* tl;dr: C program initialization, written in C!
*
* This applies to an executable dynamically linked with glibc.
* It is current as of glibc 2.26.
*
* A LOT of information has been omitted for simplicity; hell,
* some of it might be flat-out wrong (I wrote this after about
* 3 hours of experimenting with GDB). If you want to know EXACTLY
* what goes on under the covers, I advise you to read the

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 / win7iso.md
Last active December 16, 2023 06:19

Windows 7 install ISO with slipstreamed updates

Preparation

Create three directories. For the sake of this tutorial, they will be:

  • c:\image - holds the contents of the ISO file
  • c:\mount - mount point for the install.wim file
  • c:\updates - holds the update files
@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
#!/bin/sh
#
# Sync photos from iPhone to Linux using libimobiledevice + ifuse
set -euo pipefail
if [ $# -ne 1 ]; then
echo "usage: $0 <dest dir>"
exit 1
fi