Snippets are one of my favorite parts of programming. The shear endless depth of command line tricks and customizations is so exciting! Here is a collection I maintain for myself to comeback to.

Also navigable by list of snippet types here.

markdown to org file conversion -- 21.06.2021 %

I use the Bear Notes app on IOS which has a nice markdown export feature. From there it is easy to air drop the file to my mac then I paste it into my org notes after converting it.

$ pandoc -f markdown -t org -o /tmp/ && pbcopy < /tmp/

source: stackexchange

\- [ org, markdown ]

gpg usb workflow -- 13.06.2021 %

How to use a GPG key stored on a flash drive to encrypt files? I was perplexed for sometime. Eventually I figured out instead of exporting, importing, file system linking.. you just use a remote key ring that contains the keys you want!

  1. Create the new key on the flash drive with
$ gpg --full-generate-key --homedir /Volumes/usb_flash_stick/key_homedir
  1. Use that new public key to encrypt files
$ gpg --encrypt-files --homedir /Volumes/usb_flash_stick/key_homedir -r XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ./file_a

This also bring the possibility of only storing the public key locally and having the secret key safe on the USB. See how to move keys snippet.

\- [ gpg ]

list tar contents -- 13.06.2021 %

Before putting a tar file somewhere hard to access like S3 Glacier I note what is in it. I create a manifest file. Simply list the file names within:

$ tar tvf example.tar

With more automation worked in I came up with this:

  • list all the tar files using fd (rust find replacment)
  • list content of each one
  • pipe that into a file for safe keeping
$ for x in $(fd -e tar) ; do (tar tvf "$x" && echo "\n") ; done > /tmp/example_manifest
\- [ tar ]

split files -- 13.06.2021 %

To prevent upload errors to S3 Glacier I keep my files ~500mb. So larger ones must be split.

$ split -b 500mb example.txt example.txt.part

perl script example

\- [ split ]

org-roam capture templates -- 06.04.2021 %

Recently I’ve started using org-roam, so far so good. Utilizing capture buffers I create notes for work and my reefing aquarium hobby. Adding the roam tags manually became a pain so now I’ve figured out a way to prefill them with capture templates.

(setq org-roam-capture-templates
        '(("r" "reef" plain (function org-roam-capture--get-point)
           :file-name "%<%Y%m%d%H%M%S>-${slug}"
           :head "#+title: ${title}\n#+roam_tags: reef"
           :unnarrowed t)
          ("w" "work" plain (function org-roam-capture--get-point)
           :file-name "%<%Y%m%d%H%M%S>-${slug}"
           :head "#+title: ${title}\n#+roam_tags: work"
           :unnarrowed t)
          ("d" "default" plain (function org-roam-capture--get-point)
           :file-name "%<%Y%m%d%H%M%S>-${slug}"
           :head "#+title: ${title}\n"
           :unnarrowed t)))


\- [ org, emacs ]

restart nginx -- 07.02.2021 %

Normally I use

$ sudo systemctl restart nginx

but recently I had to take more drastic measures.

sudo pkill -f nginx & wait $!
sudo systemctl start nginx

source – stackoverflow

\- [ nginx ]

run changed tests -- 01.02.2021 %

npm run test – $(git diff master –name-only | rg ’test.ts’) –coverage=false

\- [ npm, git ]

strip audio from video file -- 09.01.2021 %

Easy way to remove audio from a video file using ffmpeg

ffmpeg -i $input_file -c copy -an $output_file

source: superuser

\- [ ffmpeg ]

gzipping an existing tar -- 14.10.2020 %

Part of my work process is taking lots of screenshot, ~5 per day. Then I back them up in AWS S3 Glacier once a month, using freeze app. Like to start with creating a regular tar file in /tmp.

$ tar cvf /tmp/pic_dump_14_10_20.tar ~/Desktop/**/*.png

Then append few more images. r in this case sanding for append..

$ tar rfv /tmp/pic_dump_14_10_20.tar ~/Pictures/resized/*

Now that the tar is complete I double check it by listing the files.

$ tar tf /tmp/pic_dump_14_10_20.tar

Lastly I need to compress the tar and I was confused if I could use tar command itself to compress a tar into a tar.gz but turns you use gunzip.

$ gzip /tmp/pic_dump_14_10_20.tar

source: (4)

\- [ tar, gzip ]

tmux plus screen -- 17.08.2020 %

Recently I was sshed into my home pi server trying to sftp some big files from a remote server. Some of the transfers are huge, 30gb+. On our internet that will take a while. Not wanting to leave the shh terminal session open that whole time I used screen on the pi. Idea was to create a screen session start the transfer detach and comeback few hours later. Detaching was a bit tricky. <Ctrl><a> <d> is the default detach command for both tmux running on my mac and screen running on the pi. So when I tried to detach from the screen session tmux would detach instead. 😡

After messing with configs and some searching turns out if you press the tmux prefix key twice it sends it once to the child shell. So eventually I was able to detach from the screen session with:

<Ctrl><a> <Ctrl><a> <d>!!


\- [ screen, tmux ]