A collection of commands that are useful and I never seem to remember off the top of my head.
curl -i -X POST -H "Content-Type: multipart/form-data" -F "email@example.com" http://127.0.0.1:8000/files/upload
Setup a poor-man's secure tunnel and proxy traffic over ssh to a remote server. Useful when needing to access corporate networks without the benefit of a fully fledged VPN.
ssh -N -D 8080 [USER]@[SERVER_IP]
After setting up the tunnel, you need to setup your system to use the proxy. System Preferences -> Network -> Advanced -> Proxies
Tunnel a remote port to a local port on your machine. Useful for accessing remote ports (e.g. databases) as if they were running on localhost.
ssh -L <locally accessible port>:<ip address to bind to>:<remote port> firstname.lastname@example.org
ssh -L 5434:127.0.0.1:5432 email@example.com
Recursively find and replace all instances
foo and replace it with
hoge, excluding the migrations directory. Using ripgrep because it's fast / ignores files in your .gitignore. Does not create a backup of modified files because, you're using git, right?!
Command is for FreeBSD sed, as found on macOS.
rg 'foo' -g '!migrations/' --files-with-matches -0 | xargs -0 sed -i '' 's/foo/hoge/g'
Create a gif from a .mov (screen recording with Quicktime player). ffmpeg to split into frames -> ImageMagick convert -> gifsicle to optimize
ffmpeg -y -i input.mov -f image2pipe -vcodec ppm - | convert -delay 2 -loop 0 -layers Optimize - gif:- | gifsicle -d 3 -O3 -o optimized.gif
Batch Resize Directory
Depends on ImageMagick
mogrify -resize 66x66 -path /OUTPUT_PATH/ /INPUT_PATH/*.jpg
I always forget docker commands.
Recreate a Single Container
$ docker-compose up --build --force-recreate --no-deps <container_name>
Backup Named Volume
Shutdown all containers that are using the volume before starting.
- Create a directory to store your backup.
- Create (and removes) a temporary container that mounts the volumes for an existing container (e.g. your db container) and then tars a specific directory to a backup file.
- Move db.tar to the desired host.
$ mkdir ~/backup $ docker run --rm --volumes-from my_existing_container -v ~/backup:/backup ubuntu bash -c "cd /var/opt/mssql && tar cvf /backup/db.tar ."
Restore Named Volume
Make sure the volume doesn't exist locally on the new host.
- Create an empty volume with a name that matches your final volume name.
- Create (and remove) a container that mounts:
- Your named volume
- Your local directory where your .tar backup file is located
- Extract the backup tar into the named volume
$ docker volume create my_volume_name $ docker run --rm -v my_volume_name:/recover -v ~/Downloads:/backup ubuntu bash -c "cd /recover && tar xvf /backup/db.tar"