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

326 lines
8.2 KiB
Markdown
Raw Normal View History

2023-06-30 18:06:13 +00:00
# Throw away pastebin
Just a place to throw away some text.
2024-10-23 08:18:22 +00:00
## 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
```
2024-12-21 19:07:53 +00:00
Repeat key:
```sh
defaults write -g ApplePressAndHoldEnabled -bool false
```
2024-10-23 08:18:22 +00:00
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
```
2024-11-22 07:12:32 +00:00
Enable accent color:
```sh
defaults write -g NSColorSimulateHardwareAccent -bool YES
# Value 3-8
defaults write -g NSColorSimulatedHardwareEnclosureNumber -int 7
```
2024-10-23 08:18:22 +00:00
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)
2024-11-22 07:12:32 +00:00
- [Use iMac M1 accent colours on any Mac](https://georgegarside.com/blog/macos/imac-m1-accent-colours-any-mac/)
- https://mahdi.jp/apps/accents
2024-12-14 04:49:37 +00:00
- [Why always something is running at port 5000 on my mac](https://stackoverflow.com/q/72369320)
2024-10-23 08:18:22 +00:00
## 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
2024-11-16 01:26:55 +00:00
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
2024-10-23 08:18:22 +00:00
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
2023-06-30 18:06:13 +00:00
2023-08-03 10:33:40 +00:00
```sh
# Delete untracked
git clean -fdx
2023-06-30 18:06:13 +00:00
2023-08-03 10:33:40 +00:00
git gc
2023-07-30 10:23:34 +00:00
```
2023-06-30 18:06:13 +00:00
2023-08-03 10:33:40 +00:00
## Delete `.DS_Store`
2023-06-30 18:06:13 +00:00
2023-08-03 10:33:40 +00:00
With [find](https://stackoverflow.com/q/30483670):
```sh
find . -name ".DS_Store" -print -type f -delete
2023-07-30 10:23:34 +00:00
```
2023-06-30 18:06:13 +00:00
2023-08-03 10:33:40 +00:00
With [fd](https://github.com/sharkdp/fd):
2023-06-30 18:06:13 +00:00
2023-08-03 10:33:40 +00:00
```sh
fd -H '^\.DS_Store$' -tf -X rm
```
2024-01-28 07:10:04 +00:00
## [sd](https://github.com/chmln/sd)
```sh
2025-01-05 02:56:33 +00:00
# Remove proto option
2024-01-28 07:10:04 +00:00
sd -F 'import "validate/validate.proto";' '' api/raw/*.proto
sd -F 'import "marshal-zap.proto";' '' api/raw/*.proto
2025-01-05 02:56:33 +00:00
sd -f s '\s\[\s*\(.*?];' ';' api/raw/*.proto
2023-06-30 18:06:13 +00:00
```
2023-07-30 11:13:08 +00:00
2023-07-30 18:34:29 +00:00
## [rsync](https://github.com/WayneD/rsync)
```sh
# Result is dst/src
2023-08-03 09:22:08 +00:00
rsync -avzP src dst
2023-07-30 18:34:29 +00:00
# Result is dst/* with * is from src
2023-08-03 09:22:08 +00:00
rsync -avzP src/ dst
2023-07-30 18:34:29 +00:00
```
Commonly flags:
2023-08-03 09:22:08 +00:00
- `-v`: verbose
2023-07-30 18:34:29 +00:00
- `-z`: compress
2024-07-22 11:32:39 +00:00
- `-P`: enable both `--partial`, `--progress` to easily resume after interrupt
2023-07-30 18:34:29 +00:00
- `-n`: dry run
Be careful flags (need dry run if not sure):
2023-08-05 18:56:25 +00:00
- `-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
2023-07-30 18:34:29 +00:00
2025-01-05 02:56:33 +00:00
## [fclones](https://github.com/pkolaczk/fclones)
```sh
fclones group . | fclones remove
```
## [F2](https://github.com/ayoisaiah/f2)
```sh
# If dry run, remove --exec
2025-01-11 16:49:36 +00:00
f2 --replace "{mtime.YYYY}{mtime.MM}{mtime.DD}_{mtime.H}{mtime.mm}{mtime.ss}{ext}" --exec
# Include hash md5
2025-01-05 02:56:33 +00:00
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
```
2024-09-21 11:00:32 +00:00
## [ffmpeg](https://github.com/FFmpeg/FFmpeg)
2023-07-30 11:13:08 +00:00
```sh
2024-09-21 11:00:32 +00:00
# -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
```
2024-06-04 18:45:15 +00:00
2024-09-21 11:00:32 +00:00
Links:
2023-08-03 10:33:40 +00:00
2024-09-21 11:00:32 +00:00
- [H.265/HEVC Video Encoding Guide](https://trac.ffmpeg.org/wiki/Encode/H.265)
2023-08-03 10:33:40 +00:00
2025-01-05 02:56:33 +00:00
## [yt-dlp](https://github.com/yt-dlp/yt-dlp)
2023-08-03 10:33:40 +00:00
2025-01-05 02:56:33 +00:00
```sh
yt-dlp -f - "https://www.youtube.com/watch?v=video_id"
```
## [libvips](https://github.com/libvips/libvips)
2023-08-21 12:38:37 +00:00
```sh
2024-05-13 05:14:40 +00:00
# Add --vips-progress to show progress
2024-05-12 16:22:38 +00:00
vips jxlsave filename.jpg filename.jxl --keep=none
2024-06-23 10:30:11 +00:00
vips jpegsave filename.png filename.jpg --keep=none
2024-02-08 17:13:49 +00:00
2024-05-12 16:22:38 +00:00
# Batch convert (require fd)
2024-06-23 10:30:11 +00:00
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
2024-05-13 05:14:40 +00:00
# Rotate
vips rot filename.jxl new_filename.jxl d90
2024-02-08 17:13:49 +00:00
```
2024-06-24 17:29:20 +00:00
2025-01-05 02:56:33 +00:00
## [qpdf](https://github.com/qpdf/qpdf)
2024-09-21 11:00:32 +00:00
```sh
2025-01-05 02:56:33 +00:00
# Compress pdf
qpdf input.pdf output.pdf --verbose --linearize --optimize-images
2024-09-21 11:00:32 +00:00
```