Skip to content

Instantly share code, notes, and snippets.

View hongkongkiwi's full-sized avatar
🤓

Andy hongkongkiwi

🤓
View GitHub Profile
@hongkongkiwi
hongkongkiwi / codesign-app
Created June 29, 2026 13:29
Ad-hoc re-codesign macOS .app bundles with optional xattr clearing
#!/bin/bash
set -euo pipefail
usage() {
cat <<EOF
Usage: $(basename "$0") [--clear-attrs] <path-to-app>
Re-codesign an .app bundle deeply with an ad-hoc signature.
Options:
@hongkongkiwi
hongkongkiwi / generate-dropbear-key
Last active April 8, 2026 19:34
Generate SSH Key in Dropbear with some options (by default it uses default id_dropbear as the name and ed25519 as the type)
#!/bin/sh +ux
# We set the sh +ux flags so that we error on undefined variables and error on bad commands
help() {
echo >&2 "$0 [-f] [-p] [-q] [<priv_key_file>] [<key_type>] [<key_comment>]"
echo >&2
echo >&2 "-q / --quiet to silent all output (except -p if passed)"
echo >&2 "-p / --pubkey to output public key after generation"
echo >&2 "-f / --force to force replacing existing key"
echo >&2
@hongkongkiwi
hongkongkiwi / firewall-start
Last active January 13, 2026 02:05
Bash script to allow some ports on Asus routers running Merlin firmware. This should be put in your /jffs/scripts and made executable (chmod +x /jffs/scripts/firewall-start). Now handles duplicate rules (it won't add again) and inserting before any final DROP in the INPUT chain. Quite useful ;)
#!/bin/sh
DEBUG="NO"
LOGGER_NAME="firewall"
PORTS="tcp:9443"
WAN="$1"
log() {
if [ "$DEBUG" == "YES" ]; then
echo "$1"
glm() {
unset ANTHROPIC_API_KEY
unset HTTP_PROXY
unset HTTPS_PROXY
export ANTHROPIC_BASE_URL="https://api.z.ai/api/anthropic"
export ANTHROPIC_AUTH_TOKEN="<YOUR_API_KEY>"
export ANTHROPIC_MODEL="glm-4.6"
export ANTHROPIC_DEFAULT_OPUS_MODEL="glm-4.6"
export ANTHROPIC_DEFAULT_SONNET_MODEL="glm-4.6"
export ANTHROPIC_DEFAULT_HAIKU_MODEL="glm-4.5-air"
@hongkongkiwi
hongkongkiwi / generate-ssh-key
Last active July 7, 2025 18:15
Simple one liner to generate an SSH key without a password in the default place with the comment as hostname then print out the public key for copy and paste.
HOSTNAME=`hostname` ssh-keygen -t rsa -C "$HOSTNAME" -f "$HOME/.ssh/id_rsa" -P "" && cat ~/.ssh/id_rsa.pub
@hongkongkiwi
hongkongkiwi / setup_unraid_ssh.sh
Created November 23, 2017 03:57
Small script to setup ssh keys and configs on Unraid to persist after boot. Supports multiple users.
#!/bin/bash
# Add this line into /boot/config/go where username is the user you want to setup, probably root
#/boot/config/ssh/setup_ssh_client.sh "username"
if [[ "$1" == "" ]]; then
echo "Invalid User!"
exit 1
fi
@hongkongkiwi
hongkongkiwi / writing-tasks.mdc
Last active April 23, 2025 11:36
Updated @trigger.dev rules for v4-beta
---
globs: **/trigger/**/*.ts, **/trigger/**/*.tsx,**/trigger/**/*.js,**/trigger/**/*.jsx
description: Guidelines for writing Trigger.dev tasks
alwaysApply: false
---
# How to write Trigger.dev tasks
## Overview of writing a Trigger.dev task
1. Run the CLI `init` command: `npx trigger.dev@v4-beta init`.
@hongkongkiwi
hongkongkiwi / ubuntu_fastest_package_mirror
Created June 20, 2022 04:49
One liner to find the fastest ubuntu mirror
curl -s http://mirrors.ubuntu.com/mirrors.txt | xargs -n1 -I {} sh -c 'echo `curl -r 0-102400 -s -w %{speed_download} -o /dev/null {}/ls-lR.gz` {}' | sort -g -r | head -1 | awk '{ print $2 }'
@hongkongkiwi
hongkongkiwi / fastest-server.sh
Last active March 27, 2025 09:21
Bash script to test a list of Astrill Servers and returns the one with the best ping. Currently only works for the TCP servers (I am open to a way to test UDP servers). Only tested on OSX, should work fine on linux too.
#!/bin/bash
# INSTRUCTIONS
# After generating the OpenVPN server certificates, download and unzip then run this script in the same directory.
# Don't forget to chmod +x fastest-server.sh after downloading
#
# To test all servers with UK in the name
# sudo ./fastest-server.sh UK
# To test all servers with USA in the name
# sudo ./fastest-server.sh USA
@hongkongkiwi
hongkongkiwi / sign-openwrt-packages
Last active January 25, 2025 08:32
Little script to sign OpenWRT packages after running a build. I used this because I couldn't figure out how to do it automatically when using the SDK.
#!/bin/bash
#
# AUTHOR: Andy Savage <andy@savage.hk>
# GITHUB: https://gist.github.com/hongkongkiwi/cfef6910c5c644eaebc9
# PURPOSE: After building one or more packages in OpenWRT this script signs them with a key file
# this can then be easily used in opkg to verify signatures.
#
KEY_DIR="$HOME/signify-keys"