Here are some code snippets I've collected over time.
Ghostty
font-family = SF Mono
font-thicken = true
font-size = 14
cursor-style = block
shell-integration-features = no-cursor
window-height = 40
window-width = 120
background-opacity = 0.8
background-blur-radius = 20
adjust-cell-height = 5%
minimum-contrast = 1.1
window-padding-x = 8
copy-on-select = clipboard
mouse-scroll-multiplier = precision:3Command Line (CLI)
Find program that listens on a port using lsof (List Open Files)
# Find process listening on specific port
lsof -i :8080
# Find all listening ports
lsof -i -P -n | grep LISTENFinding Your Public IP Address
curl ifconfig.meFor a potentially faster result that doesn't rely on an external web service, you can use dig to query Google's DNS servers directly.
dig +short TXT o-o.myaddr.l.google.com @ns1.google.comNode.js
Clearing the NPX Cache
When you use npx to run a package, it caches it to speed up future executions. Sometimes, this cache can become corrupted or you might just want to ensure you're running the absolute latest version of a package. To clear the npx cache, you can simply remove its directory.
rm -rf ~/.npm/_npxmacOS
Inspecting App Entitlements with codesign
On macOS, applications have entitlements that define what resources and capabilities they are allowed to access. You can inspect these using the codesign command-line tool. This is useful for security audits or debugging.
Here's how you can check the entitlements for the Docker application. Note that the command syntax changed slightly in macOS 12.0.
For macOS versions before 12.0:
codesign -dvvvvv --entitlements :- /Applications/Docker.appFor macOS 12.0 and newer:
codesign -dvvvvv --entitlements - /Applications/Docker.appDocker
A Complete Docker Cleanup
If you want to reset your Docker environment to a clean slate, you'll need to stop and remove all containers, images, volumes, and networks. These commands will wipe your local Docker setup completely, so use them with caution!
# Stop all running containers
docker stop $(docker ps -qa)
# Remove all containers (stopped or running)
docker rm $(docker ps -qa)
# Remove all Docker images
docker rmi -f $(docker images -qa)
# Remove all Docker volumes
docker volume rm $(docker volume ls -qf)
# Remove all custom Docker networks
docker network rm $(docker network ls -q)
# A more direct way to prune volumes
docker volume prune -fAfter running these, your Docker installation should be pristine. You can verify by running docker ps -a, docker images -a, and docker volume ls, which should all return empty lists.
Upgrading Docker Compose Services
To update the images used by your services in a docker-compose.yml file to their latest versions, you can use docker compose (V2). First, pull the latest images, then restart the services with the new images.
Source: Stack Overflow
# Pull the latest versions of all images in the compose file
docker compose pull
# Recreate services with the new images
docker compose up -d --remove-orphans
# Optionally, you can clean up old, unused images
docker image pruneEnabling BBR for Better Network Performance
BBR is a TCP congestion control algorithm developed by Google that can significantly improve network throughput and latency. Here’s how you can enable it on a Linux-based system (like a server or a VM).
First, verify which congestion control algorithms are available.
sysctl net.ipv4.tcp_available_congestion_controlNext, you may need to install a newer kernel.
# Press Tab to see options
sudo apt install --install-recommends linux-generic-hwe-Then, edit the sysctl.conf file to enable BBR by default.
sudo vi /etc/sysctl.confAdd these lines to the file:
net.core.default_qdisc=fq
net.ipv4.tcp_congestion_control=bbrFinally, apply the changes and reboot the system for them to take effect.
sudo sysctl -p
reboot