Skip to content

Instantly share code, notes, and snippets.

View shollingsworth's full-sized avatar

Steven Hollingsworth shollingsworth

View GitHub Profile
@shollingsworth
shollingsworth / python_argparse_subcommand_example.py
Created May 11, 2022 03:22
abstracted argparse subcommand example
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Argparse Subcommand Template."""
import argparse
from pathlib import Path
MAP = {
"dev": {
"arg1": "foo",
},
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
@shollingsworth
shollingsworth / aws_unattached_volume_cost_estimate.py
Last active April 29, 2022 22:42
Gives a very ROUGH estimate for AWS costs of unattached volumes since creation.This is only an estimate, and meant to shine a light on possible savings.In my paricular case, I used AWS sso to generate a list of profiles for allaccounts in our organization and iterated over those accounts to findunattached EBS volumes.You can modify the script to…
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Gives a very ROUGH estimate for costs of unattached volumes since creation.
This is only an estimate, and meant to shine a light on possible savings.
In my paricular case, I used AWS sso to generate a list of profiles for all
accounts in our organization and iterated over those accounts to find
unattached EBS volumes.
@shollingsworth
shollingsworth / gen_sso_profile.py
Created April 18, 2022 03:23
generate all available AWS sso account / permission set profiles based on sso_start_url
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Auto generate SSO profiles based on your membership."""
import argparse
from configparser import ConfigParser
import hashlib
import json
from pathlib import Path
import re
import subprocess
@shollingsworth
shollingsworth / openfiles.py
Created April 16, 2022 18:38
python3 List all processes, sort by number of open files
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""List all processes, sort by number of open files."""
from collections import Counter
import psutil
def main():
"""Run main function."""
@shollingsworth
shollingsworth / curl_post_json_file.sh
Created April 14, 2022 21:23
curl POST a json file to a http endpoint
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
curl -X POST \
-H 'Content-Type:application/json' \
-H "Accept:application/json" \
-d '@temp.json' \
http://localhost:5000/
@shollingsworth
shollingsworth / github_gpg_token_import.sh
Created April 14, 2022 15:23
import gpg public web-flow signature into your keychain i.e. key 4AEE18F83AFDEB23 You'll see these signatures in your git log history
#!/usr/bin/env bash
# import gpg public web-flow signature into your keychain 4AEE18F83AFDEB23
curl https://github.com/web-flow.gpg | gpg --import
@shollingsworth
shollingsworth / json2dataclass.py
Last active April 18, 2022 15:12
Convert JSON to python dataclass through stdin or file argument.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Convert JSON to python dataclass."""
import argparse
import json
import select
from string import Template
import sys
from typing import Any, Tuple
@shollingsworth
shollingsworth / dump_ldap_nested_group_membership.py
Created April 9, 2022 00:29
dump nested microsoft group memberships using ldap3 python library and write to files
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Enumerate LDAP nested Group Membership, from list of group names in json file"""
import json
import logging
import os
from pathlib import Path
import ssl
from typing import List
@shollingsworth
shollingsworth / add_missing_path_if_does_not_exist.sh
Created April 8, 2022 14:23
export a missing path if it doesn't exist. This prevents the path from being added over and over if you have a shell integration that auto sources some files
# add studio javac to path
if [[ ${PATH} != *"${ANDROID_SDK_ROOT}/bin"* ]]; then
export PATH="${ANDROID_SDK_ROOT}/jre/bin:${PATH}"
fi