Skip to content

Instantly share code, notes, and snippets.

Avatar

Alex Rutar alexrutar

View GitHub Profile
@alexrutar
alexrutar / get_ssh_key_hash.md
Last active Oct 15, 2022
Get SSH Public Key Hash
View get_ssh_key_hash.md

To get the SHA256 hash of an existing public key, simply run

ssh-keygen -lvf path/to/key.pub

If you want the MD5 hash (or another supported format), run something like

ssh-keygen -lv -E MD5 -f path/to/key.pub
View git_pretty_log.md

You can quickly visualize your current git tree structure with

git log --graph --oneline --all
@alexrutar
alexrutar / fish_pipeline.md
Last active Feb 11, 2022
Applying a command to each line of STDIN in fish
View fish_pipeline.md

It's often useful to apply a command to each line of STDIN inside a pipeline. This is easy to do in fish:

ls | while read line; echo $line; end
@alexrutar
alexrutar / wait_example.fish
Last active Feb 11, 2022
Execute functions in parallel, and wait for them to finish.
View wait_example.fish
# This is a short function demonstrating how to run a sequence of commands in parallel
# and wait for them to be completed before continuing
function test_sleep
set -l pid_list
for i in 1 4 2 5 3
# execute the command and put it in the background
fish --command "
sleep $i
echo \"Finished command $i!\"
" &
@alexrutar
alexrutar / validate_html.md
Last active Feb 11, 2022
Validate HTML using the W3C API from the command line.
View validate_html.md

We can use httpie to make requests to the W3C validator. For example, to test the file index.html, run

https "https://validator.w3.org/nu/?out=gnu" @index.html "Content-Type: text/html; charset=utf-8" --print 'b'

and any errors or warnings will be printed to STDOUT.

You can also get the error format in JSON by using the out=json syntax.

@alexrutar
alexrutar / get_large_files.md
Last active Jan 27, 2022
Get the largest files in a directory in human-readable format.
View get_large_files.md

If you have a folder my/folder, you can run

du -h my/folder | sort -h | tail -n 10

to get a list of the 10 largest subfolders.

Explanation:

  • du -h: get the size of the elements in the folder in human-readable format
  • sort -h: sort human-readable (requires an updated version of sort)
  • tail -n 10: only take the last 10 elements