posts-go/posts/2023-07-01-pastebin.md

319 lines
8.0 KiB
Markdown

# Throw away pastebin
Just a place to throw away some text.
## macOS
Never sleep:
```sh
caffeinate -u -t 3600
caffeinate -i
```
Use Touch ID in Terminal:
```sh
sudo cp /etc/pam.d/sudo_local.template /etc/pam.d/sudo_local
# Uncomment last line
sudo nano /etc/pam.d/sudo_local
```
Hide Developer in Spotlight:
```sh
cd /Applications
touch Xcode.app
# Xcode mini version
xcode-select --install
```
Reset launchpad:
```sh
defaults write com.apple.dock ResetLaunchPad -bool true; killall Dock
```
Reduce padding in menu bar (Log out then log in to apply):
```sh
defaults -currentHost write -globalDomain NSStatusItemSelectionPadding -int 6
defaults -currentHost write -globalDomain NSStatusItemSpacing -int 6
```
Tweak Finder:
```sh
# Use list view
defaults write com.apple.finder FXPreferredViewStyle -string "Nlsv"
# Show path bar
defaults write com.apple.finder ShowPathbar -bool true
# Show status bar
defaults write com.apple.finder ShowStatusBar -bool true
# Show filename extensions
defaults write NSGlobalDomain AppleShowAllExtensions -bool true
# Keep folders on top when sorting by name
defaults write com.apple.finder _FXSortFoldersFirst -bool true
killall Finder
```
Enable accent color:
```sh
defaults write -g NSColorSimulateHardwareAccent -bool YES
# Value 3-8
defaults write -g NSColorSimulatedHardwareEnclosureNumber -int 7
```
Disable IPv6:
```sh
sudo networksetup -listallnetworkservices
sudo networksetup -setv6off Wi-Fi
```
Clean up leftover data:
```txt
/Library/Application Support
/Library/LaunchAgents
/Library/LaunchDaemons
/Library/Preferences
/Users/Shared
~/Library/Application Support
~/Library/Fonts (Removed)
~/Library/LaunchAgents
~/Library/Preferences
```
Clean up leftover shell:
```txt
/etc/bashrc
/etc/profile
/etc/zshrc
/etc/paths.d
```
Clean up clipboard:
```sh
pbcopy < /dev/null
```
[Disable **Smart zoom** in **Track pad** settings to make right click instant](https://mastodon.online/@nikitonsky/112220593113484602)
Fix OpenVPN Client 3
```sh
sudo launchctl unload -w /Library/LaunchDaemons/org.openvpn.client.plist
sudo launchctl load -w /Library/LaunchDaemons/org.openvpn.client.plist
```
Bluetooth stutter:
```sh
sudo rm /Library/Preferences/com.apple.Bluetooth.plist
sudo pkill bluetoothd
```
Thanks:
- [Can Touch ID on Mac authenticate sudo in Terminal?](https://apple.stackexchange.com/a/466029)
- [Native fix for applications hiding under the MacBook Pro notch](https://flaky.build/native-fix-for-applications-hiding-under-the-macbook-pro-notch)
- [Can the spacing of menu bar apps be modified in macOS Big Sur and later?](https://apple.stackexchange.com/q/406316)
- [macOS: How to Disable IPv6](https://appletoolbox.com/macos-how-to-disable-ipv6/)
- [How to fully uninstall Logitech G HUB on macOS via terminal/command line](https://gist.github.com/timotgl/f3d8c49ad582ec1af8ff01143465e116)
- [Hardening macOS](https://www.bejarano.io/hardening-macos/)
- https://github.com/drduh/macOS-Security-and-Privacy-Guide
- [Mac Setup](https://mac.install.guide/mac-setup/)
- https://github.com/OpenVPN/openvpn3/issues/243
- https://stackoverflow.com/q/15872666
- [Reclaiming storage/space from 'System Data' in macOS: A tutorial on understanding the System Data usage](http://blog.greggant.com/posts/2022/04/10/reclaiming-space-from-system-data-in-macos.html)
- [Upgrading Homebrew and avoiding the failed to verify attestation error](https://til.simonwillison.net/homebrew/no-verify-attestations)
- [Use iMac M1 accent colours on any Mac](https://georgegarside.com/blog/macos/imac-m1-accent-colours-any-mac/)
- https://mahdi.jp/apps/accents
- [Why always something is running at port 5000 on my mac](https://stackoverflow.com/q/72369320)
## Firefox
`about:config`:
- Disable unused features:
- `extensions.pocket.enabled`: false
- `identity.fxaccounts.enabled`: false
- `reader.parse-on-load.enabled`: false
- Good settings:
- `media.videocontrols.picture-in-picture.video-toggle.always-show`: true
- `network.IDN_show_punycode`: true
- `browser.tabs.insertAfterCurrent`: true
- Encrypted Client Hello (ECH):
- `network.dns.echconfig.enabled`: true
- `network.dns.use_https_rr_as_altsvc`: true
- Experiment
- `image.jxl.enabled`: true
Extensions:
- https://github.com/gorhill/uBlock
- https://github.com/ajayyy/SponsorBlock
- https://github.com/mozilla/contain-facebook
- https://github.com/refined-github/refined-github
- https://github.com/openstyles/stylus
- https://github.com/Rayquaza01/HistoryCleaner
- https://github.com/h43z/audiocontextsuspender
Thanks:
- [My list of useful command line tools](https://boyter.org/posts/my-list-of-useful-command-line-tools/)
- [Useful Customizations for Firefox](http://www.quippd.com/firefox/wiki/useful-customizations/)
- [Encrypted Client Hello: the future of ESNI in Firefox](https://blog.mozilla.org/security/2021/01/07/encrypted-client-hello-the-future-of-esni-in-firefox/)
- [Phishing with Unicode Domains](https://www.xudongz.com/blog/2017/idn-phishing/)
- https://sizeof.cat/links/
## ssh config
Edit `~/.ssh/config`
```ssh
Host *
IdentitiesOnly yes
UseKeychain yes
```
Thanks:
- [OpenSSH client side key management for better privacy and security](https://tim.siosm.fr/blog/2023/01/13/openssh-key-management/)
- [Git keeps asking me for my ssh key passphrase](https://stackoverflow.com/a/41576222)
- [OpenSSH updates in macOS 10.12.2](https://developer.apple.com/library/archive/technotes/tn2449/_index.html)
## git clean up
```sh
# Delete untracked
git clean -fdx
git gc
```
## Delete `.DS_Store`
With [find](https://stackoverflow.com/q/30483670):
```sh
find . -name ".DS_Store" -print -type f -delete
```
With [fd](https://github.com/sharkdp/fd):
```sh
fd -H '^\.DS_Store$' -tf -X rm
```
## [sd](https://github.com/chmln/sd)
Remove proto options:
```sh
sd -F 'import "validate/validate.proto";' '' api/raw/*.proto
sd -F 'import "marshal-zap.proto";' '' api/raw/*.proto
sd -f s '\s\[.*?];' ';' api/raw/*.proto
```
## [fdupes](https://github.com/adrianlopezroche/fdupes)
Remove duplicated files:
```sh
fdupes -rdN .
```
## [rsync](https://github.com/WayneD/rsync)
```sh
# Result is dst/src
rsync -avzP src dst
# Result is dst/* with * is from src
rsync -avzP src/ dst
```
Commonly flags:
- `-v`: verbose
- `-z`: compress
- `-P`: enable both `--partial`, `--progress` to easily resume after interrupt
- `-n`: dry run
Be careful flags (need dry run if not sure):
- `-u`: skip if files in **dst** is already newer than in **src**, if you want
to sync both ways
- `--delete`: delete files in **dst** if not exist in **src**, useful to sync
dst with src
## [ffmpeg](https://github.com/FFmpeg/FFmpeg)
```sh
# -crf: quality, 0 is lossless, more is lower quality
# -an: no audio
# -c:a aac -b:a 128k: audio codec and bitrate
ffmpeg -i input -c:v libx265 -crf 26 -preset fast -an output.mp4
```
Links:
- [H.265/HEVC Video Encoding Guide](https://trac.ffmpeg.org/wiki/Encode/H.265)
## [libvips](https://github.com/libvips/libvips)
Convert:
```sh
# Add --vips-progress to show progress
vips jxlsave filename.jpg filename.jxl --keep=none
vips jpegsave filename.png filename.jpg --keep=none
# Batch convert (require fd)
fd "jpg|jpeg|png|webp|gif" --exec vips jxlsave {} {.}.jxl --keep=none
fd "jpg|jpeg|png|webp|gif" --exec-batch rm
fd "png|webp|gif" --exec vips jpegsave {} {.}.jpg --keep=none
fd "png|webp|gif" --exec-batch rm
# Rotate
vips rot filename.jxl new_filename.jxl d90
```
## [yt-dlp](https://github.com/yt-dlp/yt-dlp)
Download:
```sh
yt-dlp -f - "https://www.youtube.com/watch?v=video_id"
```
## [F2](https://github.com/ayoisaiah/f2)
Rename:
```sh
# If dry run, remove --exec
f2 --replace "{mtime.YYYY}{mtime.MM}{mtime.DD}_{mtime.H}{mtime.mm}{mtime.ss}_{hash.md5}{ext}" --exec
# Include ImageSize (require exiftool)
f2 --replace "{mtime.YYYY}{mtime.MM}{mtime.DD}_{mtime.H}{mtime.mm}{mtime.ss}_{xt.ImageSize}_{hash.md5}{ext}" --exec
# Not include time
f2 --exclude="\d+x\d+_[a-z\d]{32}" --sort=mtime --replace "{xt.ImageSize}_{hash.md5}{ext}" --exec
# Remove space in directory
f2 --find " " --replace "_" --string-mode --only-dir --exec
```