Skip to content

Instantly share code, notes, and snippets.

Avatar

Andrew Sun apsun

View GitHub Profile
@apsun
apsun / cleantags.py
Created Aug 2, 2021
Normalize ID3 tags from filename
View cleantags.py
import re
import os
import sys
import mutagen.id3
def main(filepath):
print(filepath)
# Save original mtime
stat = os.stat(filepath)
@apsun
apsun / build.gradle.kts
Created Feb 14, 2021
Documented build.gradle for publishing an Android library to Maven Central
View build.gradle.kts
// 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 Feb 2021 for
// building an Android library and publishing it to OSSRH (Maven Central).
//
View iphone-photo-sync.sh
#!/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
View iosnotes.md

iOS notes

Just some random stuff I'm learning as I make my first iOS app.

UIViewController: present vs show

present() will always show the view controller modally, whereas with show() it will bubble up the chain where it can be handled by some parent view controller.

View iphone-music-sync.sh
#!/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
View img2stkr.go
// Converts images into PNG format with the top-left corner transparent.
// Signal treats images sent via the keyboard with a transparent top-left
// corner as actual stickers, skipping one button click. This script
// automates batch conversion into this "sticker" format, for use with
// uSticker. Currently doesn't work with animated GIFs.
package main
import (
"flag"
@apsun
apsun / delet_tweets.md
Last active Apr 29, 2020
Delete your old tweets with this disgusting bash script
View delet_tweets.md

100% free. Runs completely locally on your machine. Bypasses the 3200 tweet limit. May require some eye bleach for the script. Here's how to use it:

  1. Go to settings -> account -> your Twitter data and request a download. This may take a few hours. You'll get an email with a link to download a zip file. Extract the zip file and navigate to the data directory.

  2. Go to Twitter in a web browser and find any Tweet you want to delete. We're going to use it to extract your authentication credentials for the next step. Open developer tools, delete the tweet, and find the request

View tax_calc.py
#!/usr/bin/env python3
# general non-company specific stuff
supplemental_withholding_rate = 0.22
pay_periods_per_year = 26
max_401k = 19500.00
standard_deduction = 12550
tax_brackets = [
(0.10, 9950),
(0.12, 40525),
View airpods-notify.sh
#!/bin/sh
old=""
while :; do
new="$(curl -s 'https://www.apple.com/shop/retail/pickup-message?parts.0=MWP22AM%2FA&location=94043' | jq '.body.stores[:4][].partsAvailability["MWP22AM/A"] | select (.pickupDisplay == "available") | .storePickupQuote' -r | head -n1)"
if [ "$new" != "$old" ]; then
if [ "$new" != "" ]; then
notify-send 'AirPods' "$new"
fi
old="$new"
fi
@apsun
apsun / tmenu.go
Last active Feb 13, 2020
A super bare-bones fzf clone. Inspired by https://github.com/sgtpep/pmenu
View tmenu.go
package main
import (
"bufio"
"flag"
"fmt"
"os"
"regexp"
"strings"