Skip to content

Instantly share code, notes, and snippets.

View ElijahLynn's full-sized avatar
😎
All Your DevOps Belong To Us

Elijah Lynn ElijahLynn

😎
All Your DevOps Belong To Us
View GitHub Profile
@ElijahLynn
ElijahLynn / gist:9443e3b34b462fa6a9f730542663fe90
Last active April 12, 2025 00:01
cli wrapper for docker
I want to create a boiler plate project to create CLI commands that wrap around docker. Then have all the scripting in a Docker image and the CLI program passes the args and any ENV vars for secrets (api access) to the docker run.
I am not easily finding anything like this, but this is a start:
https://andrewlock.net/packaging-cli-programs-into-docker-images-to-avoid-dependency-hell/
@ElijahLynn
ElijahLynn / gist:f3e3f5e5db0249cd7c787fe5f11f5a16
Last active April 9, 2025 22:18
How to set the zone for the gcloud cli tool
# sets the default zone for your gcloud CLI. It means it will apply to all your future gcloud commands coming from that same terminal.
gcloud config set compute/zone <zone>
# default value for this specific project only.
gcloud compute project-info add-metadata --metadata google-compute-default-zone=<zone>
# https://www.reddit.com/r/googlecloud/comments/brshdg/how_to_set_correctly_default_zoneregion_via_gcloud/
@ElijahLynn
ElijahLynn / known_hosts_remove_line.fish
Created April 8, 2025 18:27
fish functions known_hosts_remove_line
functions known_hosts_remove_line
# Defined via `source`
function known_hosts_remove_line
# get total number of lines in the known_hosts file
set total_lines (wc -l < ~/.ssh/known_hosts | tr -d ' ')
if test $argv[1] -gt $total_lines
echo "Line number $argv[1] exceeds total lines ($total_lines) in ~/.ssh/known_hosts"
return 1
end
sed -i '' "$argv[1]d" ~/.ssh/known_hosts
@ElijahLynn
ElijahLynn / gist:19bcc9bac35a343c9f3f07adba3ed4da
Created March 12, 2025 05:43
bash strict mode, with a good concise comment
# enable bash strict mode: exit on error (-e), undefined variables (-u), & pipe failures (-o pipefail)
set -euo pipefail
@ElijahLynn
ElijahLynn / gist:07ba9b3c178fdcf55b3849c5ac11c52f
Last active March 7, 2025 23:56
How to use Mac fingerprint auth for sudo password prompt
For a consistent fingerprint auth experience on Mac, for both GUI and CLI, I learned that I can add the below and everytime I would have gotten a password prompt, I now instead get a fingerprint popup modal. Saves a ton of time if you have a longer password.
/etc/pam.d/sudo Add this line to the TOP, bottom won't work.
```
auth sufficient pam_tid.so
````
@ElijahLynn
ElijahLynn / promtool-grafana-cloud-access-policy-token-auth.md
Last active March 4, 2025 17:40
How to auth to Grafana Cloud Prometheus using an Access Policy Token with promtool

The docs are here but don't specify this level of detail, I found this through trial/error: https://prometheus.io/docs/prometheus/latest/configuration/configuration/#http_config

Also see, prometheus/prometheus#12924.

  1. Set your access policy up and create a token for it at https://grafana.com/orgs/{{ORG_NAME}}/access-policies
  2. Get your QUERY_ENDPOINT + INSTANCE_ID from https://grafana.com/orgs/{{ORG_NAME}}/members, then click your stack on the left, https://grafana.com/orgs/hedera/stacks/{{STACK_ID}}, then click Prometheus and scroll down to get your Instance ID (https://grafana.com/orgs/hedera/hosted-metrics/{{USERNAME/INSTANCE_ID}}
  3. Then create a file with the creds, e.g. .promtool-http-config.yml with the below format:
    authorization:
@ElijahLynn
ElijahLynn / bash-strict-mode.sh
Created February 7, 2025 00:37
bash strict mode oneliner with a good comment explaining the options
# enable bash strict mode: exit on error (-e), undefined variables (-u), & pipe failures (-o pipefail)
set -euo pipefail
@ElijahLynn
ElijahLynn / gcp-gsutil-hmac-credentials.md
Last active February 10, 2025 22:27
GCP: How to use HMAC credentials with gsutil

It isn't as easy as setting some ENV vars...

If you have an interactive TTY (local dev testing)
Generate a boto config, will prompt for access key ID and secret access token This will add gs_secret_access_key and gs_access_key_id and save to ~/.boto.

gsutil config -a

If you don't have an interactive TTY (CI/automation)

@ElijahLynn
ElijahLynn / gcp-project-metadata-ssh-key-finder-parallel.sh
Created July 19, 2024 20:55
Script to search the metadata of all GCP projects for an SSH public key
#!/bin/bash
# Define color codes
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m' # No Color
# Check if an argument is provided
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <public-ssh-key>"
@ElijahLynn
ElijahLynn / monitor-number-tcp-connection-states.sh
Last active January 20, 2024 22:49
Monitor the number of all TCP connection states
watch -n 1 "netstat -an | awk '/^tcp/ { ++S[\$NF] } END { for(a in S) print a, S[a] }'"
# Every 1.0s: netstat -an | awk '/^tcp/ { ++S[$NF] } END { for(a in S) print a, S[a] }'
# LISTEN 7
# FIN_WAIT_2 1
# CLOSE_WAIT 1
# CLOSED 33
# TIME_WAIT 1
# ESTABLISHED 63