Skip to content

Instantly share code, notes, and snippets.

@pjaudiomv
pjaudiomv / parse-tfstate.py
Created April 24, 2024 18:58
Terragrunt to Terraform migration. Useful for migrating lots of statefiles down to a single statefile
#!/usr/bin/env python3
import argparse
import json
import subprocess
from collections import defaultdict
# IE.
# parse-state -o terragrunt.tfstate -n terraform.tfstate -m ec2_bastion
def parse_args():
@pjaudiomv
pjaudiomv / custom-field-keys.py
Last active December 27, 2023 00:36
BMLT Servers with Custom Field Keys
import urllib3
import json
standard_keys = ['id_bigint', 'worldid_mixed', 'service_body_bigint', 'weekday_tinyint', 'venue_type', 'start_time', 'duration_time', 'time_zone', 'formats', 'lang_enum', 'longitude', 'latitude', 'meeting_name', 'location_text', 'location_info', 'location_street', 'location_city_subsection', 'location_neighborhood', 'location_municipality', 'location_sub_province', 'location_province', 'location_postal_code_1', 'location_nation', 'comments', 'train_lines', 'bus_lines', 'phone_meeting_number', 'virtual_meeting_link', 'virtual_meeting_additional_info', 'root_server_uri', 'format_shared_id_list']
req = urllib3.PoolManager().request("GET", 'https://aggregator.bmltenabled.org/main_server/api/v1/rootservers')
root_servers = json.loads(req.data.decode())
root_servers = sorted(root_servers, key=lambda k: k['name'])
for root in root_servers:
root_info = json.loads(root['serverInfo'])
available_keys = root_info['available_keys'].split(',')
@pjaudiomv
pjaudiomv / aws-assumerole.sh
Last active March 12, 2024 02:45
Get EC2 Assume Role STS Creds and set them locally - useful for testing ec2 role or when you have ssh access to an ec2 but no aws credential accesss
#!/usr/bin/env bash
# Fetches AWS credentials from a EC2 IAM role and configures them locally.
# Script expects input parameter to be a named Host in your SSH config, then sets AWS creds name using that Host name.
#
# Configuration
# Check for SSH_CONFIG_FILE env var then default to users home dir
SSH_CONFIG_FILE="${SSH_CONFIG_FILE:-$HOME/.ssh/config}"
# ANSI color codes for pretty output
YELLOW='\033[1;93m'
@pjaudiomv
pjaudiomv / get-all-images.sh
Last active April 9, 2024 16:14
Get All Images in a Cluster
#!/usr/bin/env bash
normalize_image_name() {
local name="$1"
local registry
if [[ "$name" == *\/* ]]; then
registry=${name%%/*}
if ! [[ "$registry" == *.* || "$registry" == localhost:[0-9]* ]]; then
name="docker.io/${name}"
fi
@pjaudiomv
pjaudiomv / get_all_images.py
Created November 3, 2023 17:28
Get All Images in a Cluster
import yaml
import re
from kubernetes import client, config
def parse_name(name):
if len(name.split("/")) > 1:
registry = name.split("/")[0]
if not (
re.search("\.", registry) or re.search("localhost:[0-9]+", registry)
@pjaudiomv
pjaudiomv / http.php
Created October 27, 2023 01:54
http
<?php
private function httpGet(string $url): string
{
if (defined('WP_CONTENT_DIR')) {
return $this->wordpressGet($url);
} else {
return $this->guzzleGet($url);
}
}
@pjaudiomv
pjaudiomv / langDays.php
Last active October 18, 2023 01:27
Language Names with Days of Week
<?php
function getLangInfo()
{
$langs = ['da', 'de', 'en', 'es', 'fa', 'fr', 'it', 'pl', 'pt', 'ru', 'sv'];
$ret = [];
foreach ($langs as $lang) {
$daysOfWeek = [];
$lang_name = \Locale::getDisplayLanguage($lang, $lang);
@pjaudiomv
pjaudiomv / kx.sh
Created September 21, 2023 17:51
Kubeconfig Context Switcher
#!/usr/bin/env bash
usage () {
echo "Usage: kx [OPERATION]"
echo " -h Help. Displays this message."
echo " -l list contexts"
echo " -c get current context"
echo " -s set context"
echo " -d delete context"
}
@pjaudiomv
pjaudiomv / gt_1_tz_countries.json
Created May 31, 2023 15:52
gt_1_tz_countries.json
{
"Antarctica": {
"long_name": "Antarctica",
"short_name": "Antarctica"
},
"AU": {
"long_name": "Australia",
"short_name": "AU"
},
"BR": {
@pjaudiomv
pjaudiomv / zshrc
Last active May 19, 2023 19:51
zshrc
export GPG_TTY=$(tty)
alias ll='ls -al'
alias h='history'
alias hg='history | grep $1'
alias c='clear'
alias ns='arp -a | grep :'
alias gs='git status'
alias tf='terraform fmt -recursive'
alias account='{ aws sts get-caller-identity & aws iam list-account-aliases; } | jq -s ".|add"'