Example Page

Bash

+--------------------+----------------------+-----------------+-----------------+
|   Expression       |       parameter      |     parameter   |    parameter    |
|   in script:       |   Set and Not Null   |   Set But Null  |      Unset      |
+--------------------+----------------------+-----------------+-----------------+
| ${parameter:-word} | substitute parameter | substitute word | substitute word |
| ${parameter-word}  | substitute parameter | substitute null | substitute word |
| ${parameter:=word} | substitute parameter | assign word     | assign word     |
| ${parameter=word}  | substitute parameter | substitute null | assign word     |
| ${parameter:?word} | substitute parameter | error, exit     | error, exit     |
| ${parameter?word}  | substitute parameter | substitute null | error, exit     |
| ${parameter:+word} | substitute word      | substitute null | substitute null |
| ${parameter+word}  | substitute word      | substitute word | substitute null |
+--------------------+----------------------+-----------------+-----------------+

Docker

Common commands:

docker-compose up
docker-compose up -d
docker-compose up -d my-api
docker-compose down
docker-compose logs
docker-compose logs -f --tail 100 my-api

 

Docker/AWS

Login to AWS ECR through a Docker container:

docker run --rm -it -v ~/.aws:/root/.aws amazon/aws-cli:latest ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws/<company> 

Push an image to AWS ECR:

docker build -t image_ref .
docker tag <image_ref> public.ecr.aws/<ecr_name>/<repo_name>:latest
docker push public.ecr.aws/<ecr_name>/<repo_name>:latest

Docker/Azure​

Run Azure CLI through Docker container:

docker run --rm -v "${HOME}/.azure:/root/.azure" mcr.microsoft.com/azure-cli

Python

python -m venv venv
pip install -r requirements.txt

# list comprehension
[(x, y) for x in [1,2,3] for y in [3,1,4] if x != y]

PowerShell

# Rename all files with creation date:
Get-ChildItem -Recurse *.txt | Rename-Item -newname {$_.CreationTime.toString("yyyyMMddHHmmss") + ".txt"}

Git

# Get lines of code by contributor

git ls-files | xargs -n1 git blame --line-porcelain | sed -n 's/^author //p' | sort -f | uniq -ic | sort -nr

# Change commit date

(
GIT_COMMITTER_DATE="2023-11-15T13:46:00-07:00"
GIT_COMMITTER_NAME="Some Author"
GIT_COMMITTER_EMAIL="author.email@example.com"
git commit --amend \
-m "Some message" \
--date "$GIT_COMMITTER_DATE" \
--author="$GIT_COMMITTER_NAME<$GIT_COMMITTER_EMAIL>" \
--allow-empty 
)

# Push branches from one remote to another

git push origin 'refs/remotes/origin-old/*:refs/heads/*'