Skip to content

Instantly share code, notes, and snippets.

View kinwahlai's full-sized avatar

KinWah Lai kinwahlai

  • Odd-e Singapore
  • Singapore
View GitHub Profile
@kinwahlai
kinwahlai / git.sh
Last active April 29, 2022 08:32
How to Delete Already Merged Git Branches
# To delete all local branches that are already merged into the currently checked out branch:
git branch --merged | grep -i -v -E "master|develop"| xargs git branch -d
# To delete all local branches that no longer exist on the Remote
git branch -vv | grep ': gone]' | grep -v '\*' | awk '{ print $1; }' | xargs -r git branch -d
@kinwahlai
kinwahlai / gist:4cc93f7abf5204d6f29d5fc015d3d592
Created January 30, 2022 09:39
scheduled task to restart OpenWRT router
# Reboot at 4:30am every day
# Note: To avoid infinite reboot loop, wait 70 seconds
# and touch a file in /etc so clock will be set
# properly to 4:31 on reboot before cron starts.
30 4 * * * sleep 70 && touch /etc/banner && reboot
@kinwahlai
kinwahlai / installAGH.sh
Last active January 30, 2022 09:38
Install AdGuardHome to OpenWRT router
#!/bin/sh
# Switch to Adguard setup
# Grab packages for AGH and updates.
opkg update
opkg install sudo ca-certificates ca-bundle curl wget tar unzip bind-tools
#grab and install AGH
curl -s -S -L https://raw.githubusercontent.com/AdguardTeam/AdGuardHome/master/scripts/install.sh | sh -s -- -c edge
#now move DNSMasq
@kinwahlai
kinwahlai / disable-swipe-tutorial.sh
Last active August 20, 2020 21:48
Disable swipe tutorial for simulator (ios13 above)
#!/bin/bash
# This script archive 2 things here
# 1. boot the fresh simulator once, so we can reduce the boot time in UI test
# 2. Simulator shows swipe tutorial on first use of keyboard (iOS13 above), this script will set simulator preferences so it wont show the tutorial
function get_simulator_udid() {
echo '' | xcrun simctl list devices | grep "iPhone" | grep -v "unavailable" | awk -F "[()]" '{ for (i=2; i<NF; i+=2) print $i }' | grep '^[-A-Z0-9]*$'
}
@kinwahlai
kinwahlai / stashExporter
Created July 28, 2020 14:06 — forked from VersionMismatch/stashExporter
Export git stashes to patch files using the stash name as the file name
git stash list| sed 's/\//\_/g'|sed 's/ /\_/g' | awk -F ":" '{ system("git stash show -p " $1 " >> " $1$2$3 ".diff" ) }'
#! /bin/sh
# credits to Dmitry Sabanin
# https://gist.github.com/dsabanin/e1fe9bdc03d429d6cbcc7be13add9e6d
XCODE=`xcode-select -p`
[ ! -d "$XCODE" ] && echo "Directory $XCODE DOES NOT exists." && exit 404
sudo mkdir -p $XCODE/AppleInternal/Library/Xcode
@kinwahlai
kinwahlai / snippet.sh
Created June 25, 2020 09:19
useful bash command
HERE="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" # get current folder
@kinwahlai
kinwahlai / tilde-switch.plist
Created April 19, 2020 08:35
the plist file to put into /Library/LaunchDaemons to swap the ± with ~ on UK keyboard
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.localhost.tilde-switch</string>
<key>StandardErrorPath</key>
<string>/tmp/tilde/tilde-err.log</string>
# Borrowed & adapted from: https://github.com/brantb/dotfiles/blob/master/tmux.conf
# Set prefix to Ctrl-Space
unbind C-b
set-option -g prefix C-a
# using C-a as the tmux prefix comes at the cost of some great features:
# bash: move to start of line (in emacs mode, aka when i'm ssh'd somewhere)
# vim: insert mode increment number
@kinwahlai
kinwahlai / mitmproxy cheat sheet
Created August 9, 2019 04:36 — forked from 2bard/mitmproxy cheat sheet
mitmproxy cheat sheet
Movement:
j, k down, up
h, l left, right (in some contexts)
space page down
pg up/down page up/down
arrows up, down, left, right