cliday

  • About

2022-08-19

August 19, 2022

  1. mani: CLI tool to help you manage repositories
  2. asciinema: Terminal session recorder

Article of the week: A Brief History of Containers

For this trip, step into my DeLorean time machine, and let’s journey to 1979, when the concept of containers first emerged.

Tip of the week: An introduction to HEREDOCs:

# basic output to stdout
cat << EOF
The current directory is $PWD.
EOF

# basic output to a file
cat << EOF > /path/to/file
The variable $foo will be interpreted.
EOF

# don't interpret variables
cat << 'EOF' > /path/to/file
The variable $bar will not be interpreted.
EOF

# pipe the heredoc through a command
cat << 'EOF' | sed 's/foo/bar/g' > /path/to/file
All instances of "foo" will be replaced.
EOF

# write the heredoc to a file using sudo
cat << 'EOF' | sudo tee /path/to/file
This file will be owned by 'root'.
EOF

# use a heredoc, but indented (the HEREDOC must use a tab character, not spaces!)
if true; then
    cat <<- EOF
    1. One
    2. Two
    3. Three
    EOF
fi
Continue reading

2022-08-12

August 12, 2022

  1. httpie: Modern, user-friendly command-line HTTP client
  2. artem: Convert images from multiple formats to ASCII art

Article of the week: Base64 encoding

Using Base64 encoding may seem esoteric, but there are many common scenarios where you will encounter Base64 in systems administration. Knowing how to recognize, encode, and decode Base64 is valuable due to its prevalence as an encoding approach.

Tip of the week: The classic sorting and counting:

# we use 11 elements because bash indexing starts at 0, but zsh indexing starts at 1
% declare -a data=(alpha beta gamma delta epsilon zeta eta theta iota kappa lamdba)

# generate some random data:
% for _ in {1..1000}; do i=$(( RANDOM % 10 + 1 )); echo "${data[$i]}" >> /tmp/data; done

# count the number of instances of each line:
% sort /tmp/data | uniq -c
     96 alpha
     96 beta
    105 delta
     96 epsilon
     88 eta
    106 gamma
    111 iota
    103 kappa
    103 theta
     96 zeta

# re-sort by the number of instances found:
% sort /tmp/data | uniq -c | sort -nr
    111 iota
    106 gamma
    105 delta
    103 theta
    103 kappa
     96 zeta
     96 epsilon
     96 beta
     96 alpha
     88 eta
Continue reading

2022-08-05

August 5, 2022

  1. tre: Tree command, improved.
  2. glances: A top/htop alternative for GNU/Linux, BSD, Mac OS and Windows operating systems.

Article of the week: An introduction to the GNU Core Utilities

These tools are indispensable because, without them, it is impossible to accomplish any useful work on a Unix or Linux computer.

Tip of the week: Using global aliases with Zsh:

# Normally an alias can only be used as a prefix...
alias k='kubectl'
k --context gke-dev get pods --namespace my_super_long_namespace

# But Zsh has the concept of global aliases...
alias -g myns='--namespace my_super_long_namespace'
k --context gke-dev get pods myns

# These aliases can also point to functions...
get_myns() { kubectl --context gke-dev get ns -o name | fzf | cut -d/ -f2; }
alias -g gmyns='--namespace "$(get_myns)"'
k --context gke-dev get pods gmyns
Continue reading

2022-07-29

July 29, 2022

  1. diff2html-cli: Pretty diff to html javascript cli
  2. gum: A tool for glamorous shell scripts

Article of the week: A Little Story About the ‘yes’ Unix Command

The trivial program yes turns out not to be so trivial after all. It uses output buffering and memory alignment to improve performance.

Tip of the week: Using number ranges for loops and profit:

% seq 10        # print "1" through "10" on newlines
% echo {1..10}  # print "1" through "10" on a single line
% seq 3 3 21    # print "3" through "21", every third number

# generate a random number of a specific length
% for _ in {1..5}; do echo -n $((RANDOM % 10)); done

# create numbered directories in intervals of four from "4" through "32"
% for i in $(seq 4 4 32); do mkdir "folder-${i}"; done
Continue reading

2022-07-22

July 22, 2022

  1. tmuxp: tmux session manager
  2. readme-md-generator: CLI that generates beautiful README.md files

Article of the week: What happens when you press a key in your terminal?

But all of this was designed in the 70s or 80s or something and then needed to stay the same forever for backwards compatibility, so that’s what we get :)

Tip of the week: Split a string into an array with Zsh:

# by newline
% foo="one
two
three"
% bar=("${(@f)foo}")
% echo ${bar[1]}
one
# by character
% foo="one:two:three"
% bar=("${(@s/:/)foo}")
% echo ${bar[2]}
two
Continue reading
Prev Next

Powered by Jekyll with Type Theme