macOS
Softwares
- Keyboard and Mouse
- https://github.com/pqrs-org/Karabiner-Elements
- https://github.com/linearmouse/linearmouse (deprecated after macOS Sonoma)
- https://github.com/Caldis/Mos
- Windows Manager
- Utilities
- Side loading
Defaults
- Dock Icon Size
defaults write com.apple.dock "tilesize" -int "48" && killall Dock
- Dock Animation Time
defaults write com.apple.dock "autohide-time-modifier" -float "0.2" && killall Dock
- TextEdit Plain Text
defaults write com.apple.TextEdit "RichText" -bool "false" && killall TextEdit
Audio HUD
SwiftUI daemon that can be run as a service and act upon signals, the lifecycle is as follows
- Receive a signal
- Call a bash script to switch the audio device, which returns the new audio device name, then
- Prevent the hud from fading if additional signal is received, otherwise fade the hud after 1 second
- Using signals in Swift
- Directly calling the macOS OSD
- Cannot run the code
IP Address
Public IP
dig -4 TXT +short o-o.myaddr.l.google.com @ns1.google.com
Local Wireless IP
ipconfig getifaddr en1
Local Ethernet IP
ipconfig getifaddr en0
https://apple.stackexchange.com/a/20553
Disable Special Characters by Option Key
https://stackoverflow.com/a/16019737
- Download the layout from http://wordherd.com/keyboards/
- Put the file in
~/Library/Keyboard Layouts - Log out, log in
- System Settings > Keyboard > Text Input > Input Sources > Edit > + > Others
Changing Bundle Name
Modify CFBundleName within `Applications/<application_name>.app/Contents/InfoPlist.strings1
https://apple.stackexchange.com/questions/385073/how-do-i-rename-an-app-in-macos-properly
Docker
Rebuild
docker compose up -d --no-deps --build <service_name>
C++
Compilation
g++ -std=c++11 -o <output> <input>.cpp && ./<output>
ASCII Chart
https://en.cppreference.com/w/cpp/language/ascii
Bitwise Operators
https://www.programiz.com/cpp-programming/bitwise-operators
Git
Ignore after committing
Terminal
Simple HTTP Server
https://github.com/TheWaWaR/simple-http-server
simple-http-server -u -p 80 -l 1000000000
Allow upload, port 80, size limit 1GB
Date Difference
d1=$(gdate +%s)
d2=$(gdate -d "YYYYMMDD" +%s)
printf "Days\t%.2f\nMonths\t%.2f\nYears\t%.2f\n" $(((d1 - d2) / 86400.0)) $(((d1 - d2) / 86400 / 30.0)) $(((d1 - d2) / 86400 / 365.0))GZIP
// Compress
tar -czvf <out>.tar.gz <dir>
// Decompress
tar -xzvf <in>.tar.gz
// List
tar -tzvf <in>.tar.gz
Prune ZIP
zip -vr <output>.zip <input_dir> -x '**/.DS_Store' -x '**/__MACOSX'`
https://apple.stackexchange.com/a/239587
Unzip Multiple Archives
for i in *.zip; do unzip "$i" -d "${i%%.zip}"; done
https://askubuntu.com/a/962876
Split Image
Vertically
convert -crop 100%x<height>% <input>.png <output>.png
Horizontally
convert -crop <width>%x100% <input>.png <output>.png
“
Useful when dealing with long screenshots
https://unix.stackexchange.com/a/169548
Unlock PDF
qpdf --decrypt --password=<passoword> <input>.pdf <output>.pdf
Prune Metadata
- Using
exiftool
exiftool -all= <inpt>
- Using the Python package
mat2
mat2 <input> <output> or mat2 --inplace <input>
Execution Permission
chmod +x <input>.sh
One Line If
https://unix.stackexchange.com/a/90995
Math
Reading Multiple Predicates
https://math.stackexchange.com/a/2582522
Finding GCD (Euclidean Algorithm)
- then take the numerator as
- is the GCD
e.g. GCD(35, 55) = 5, by the method,
Spreadsheet
Custom Number Formats
- Percentage that display a dash if it is zero (e.g. 64%)
0.0%;-0.0%;-
- Accounting (e.g. $ 2,048.0)
_($* #,##0.0_);_($* (#,##0.0);_($* "-"??_);_(@_)
App Scripts
API for iOS shortcuts
var sheet = SpreadsheetApp.openById("1VIXHPp4d_L0gv2h9FdP1beyeZbeg-DYG88d47FSqAUw").getSheetByName('Outgoing');
function doGet(e) {
var date = Utilities.formatDate(new Date(), "GMT+8", "yyyy/MM/dd");
var item = JSON.parse(e.parameters.item)
var quantity = JSON.parse(e.parameters.quantity)
var amount = JSON.parse(e.parameters.amount)
var type = JSON.parse(e.parameters.type)
var person = JSON.parse(e.parameters.person)
sheet.appendRow([date, item, +quantity, +amount, "", type, person]);
}
Go to Last Row
function goToLastRow() {
let ss = SpreadsheetApp.getActiveSpreadsheet();
let sheet = ss.getSheetByName(ss.getSheets()[0].getName());
sheet.setActiveRange(sheet.getRange(sheet.getLastRow(),1));
}
function onOpen() {
SpreadsheetApp.getUi().createMenu("Last Row").addItem("Go to Last Row", "goToLastRow").addToUi();
}