Snippets
Snippets or little things I cannot seem to remember but continue to need to get things done.
Import Powershell Module from a Specific Location
pwsh
cd my-module
import-module -name ./Module/
Curl with SNI Support and Client/mTLS
curl -k https://myhost.mydomain.com --cert public.pem --key private.pem --header "Host: myhost.mydomain.com" --resolve myhost.mydomain.com:443:20.231.112.51
Fix the Weird Terraform v0.12 Issue Where it Won’t Load AWS Creds
This annoys the shit out of me and I always forget this command. :)
export AWS_SDK_LOAD_CONFIG=1
Use grep, awk, and xargs to Do Some Sketchy Stuff in a Cluster or with Terraform
Disclaimers: YMMV/IANAL/Don’t try this at home I’m a professional :)
kubectl get po | grep Terminating | awk '{print $1}' | xargs kubectl delete po --force --grace-period=0 kubectl get po --all-namespaces | grep Terminating | awk '{print $2 " " $1}' | xargs printf 'kubectl delete po %s -n %s --force --grace-period=0\n' kubectl get crd | grep kyverno | awk '{print $1}' | xargs kubectl delete crd terraform state list | grep fastly | awk '{print "\x27"$1"\x27"}' | xargs terraform state rm #single quotes around the string
Clear the Console + Scrollback in the VS Code Console
I need to use the VSCode Console more instead of switching back/forth between the IDE and iTerm.
CMD + K or CTRL + K
Add an Origin for Github
git remote add origin https://github.com/rayterrill/t.git git branch -M main git push -u origin main
Get Running AWS Instances with Filtering
aws ec2 describe-instances --filters "Name=tag:kubernetes.io/cluster/my-cluster,Values=owned" "Name=instance-state-name,Values=running" --region us-east-1 | jq '.Reservations | length'
Setting Up GPG with a Yubikey
- Insert the compatible yubikey into the computer
- Reset the pins if desired (recommended)
gpg --card-edit
- Enter admin mode:
admin
- Change the passwords:
passwd
- Change the key size to 4096 (prob defaults to 2048)
gpg --card-edit
- Enter admin mode:
admin
- Change key attributes:
key-attr
- Choose RSA
- Set the keysize to 4096
- Generate GPG key
gpg --card-edit
- Enter admin mode:
admin
- Generate key:
generate
- Follow the prompts, and make sure your full name and email match what you have set in Github
- Export the key to put into github
- Get the key id from the output from command 4, and use it here:
gpg --armor --export KEY_ID_FROM_STEP_4
- Put the outputted PGP Public Key Block in Github
- Get the key id from the output from command 4, and use it here:
- Configure Git to always sign:
[credential] helper = osxkeychain [user] email = YOUR_EMAIL_ADDRESS_WHICH_MATCHES_GITHUB name = YOUR_FULLNAME_WHICH_MATCHES_GITHUB signingkey = KEY_ID_FROM_STEP_4 [commit] gpgsign = true
Setting GPG with a Yubikey up on a New Computer
- Make sure gpg and pinentry-mac are installed
- export your public key
gpg --output username.gpg --export YOUR_EMAIL_ADDRESS
- copy the key over to the new computer
- import the key on your computer
gpg --import username.gpg
- Configure pinentry and gpg (.gnupg/gpg-agent.conf - make sure you point to the correct path for pinentry on your machine):
pinentry-program /opt/homebrew/bin/pinentry-mac
- Restart gpg-agent:
gpgconf --kill gpg-agent