Skip to content

Instantly share code, notes, and snippets.

View gene1wood's full-sized avatar
🎩

Gene Wood gene1wood

🎩
View GitHub Profile
@gene1wood
gene1wood / mount-netbird-nfs.bash
Last active July 20, 2023 21:35
Make Netbird umount all of the NFS mounts which point to other devices on the Netbird mesh network when the Netbird service stops
#!/bin/bash
if [ -z "$1" -o "$1" = "mount" ]; then
action=mount
elif [ "$1" = "umount" ]; then
action=umount
else
echo "missing action"
exit 1
fi
@gene1wood
gene1wood / how_to_create_a_new_python_package.md
Last active June 28, 2023 21:45
My process for creating a new python package
my-package-name
├── my_module_name
│   └── __init__.py
├── LICENSE.txt
├── README.rst
├── requirements.txt
└── pyproject.toml
  • Create a Python package name which is ideally all lower case with no dashes but may contain dashes (but not underscores)
@gene1wood
gene1wood / log_aws_lambda_event_and_context.py
Last active June 27, 2023 04:33
A python AWS Lambda function which logs the contents of the event and context variables passed into the function.
from __future__ import unicode_literals
import logging
import json
logger = logging.getLogger(__name__)
logging.getLogger().setLevel(logging.INFO)
class PythonObjectEncoder(json.JSONEncoder):
"""Custom JSON Encoder that allows encoding of un-serializable objects
@gene1wood
gene1wood / get_policy_documents_for_role.py
Created July 24, 2019 14:53
Function to return all AWS IAM policy documents (inline and managed) for a given IAM role
import boto3
def get_paginated_results(product, action, key, credentials=None, args=None):
args = {} if args is None else args
credentials = {} if credentials is None else credentials
return [y for sublist in [x[key] for x in boto3.client(
product, **credentials).get_paginator(action).paginate(**args)]
for y in sublist]
@gene1wood
gene1wood / analyze_pypi_package_names.py
Last active June 12, 2023 02:24
Analysis of PyPi package names and the use of dashes underscores upper and lower case
try:
import xmlrpclib
except ImportError:
import xmlrpc.client as xmlrpclib
client = xmlrpclib.ServerProxy('https://pypi.python.org/pypi')
packages = client.list_packages()
total = len(packages)
dashes = len([x for x in packages if '-' in x])
@gene1wood
gene1wood / Livermore Valley Craft Beer Festival - Brewery Instructions.md
Last active May 9, 2023 23:31
Livermore Valley Craft Beer Festival - Brewery Instructions

Livermore Valley Craft Beer Festival - Brewery Instructions

@gene1wood
gene1wood / parse_arn.py
Last active April 25, 2023 17:58
Parse an AWS ARN (Amazon Resource Name) into it's constituent elements
def parse_arn(arn):
# http://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html
elements = arn.split(':')
result = {'arn': elements[0],
'partition': elements[1],
'service': elements[2],
'region': elements[3],
'account': elements[4]
}
if len(elements) == 7:
@gene1wood
gene1wood / config_file_and_command_line_arguments.py
Last active April 14, 2023 18:55
An example of how to use a config file which is overridden by command line arguments in Python.
#!/usr/bin/env python
import ConfigParser
import argparse
import logging
import os
def type_loglevel(level):
try:
result = getattr(logging, level.upper())
@gene1wood
gene1wood / git_commit_before_pulling_fix.md
Last active March 1, 2023 01:10
What to do when you git commit before pulling and then find out when you push that your commit is not based off of the right HEAD

First STOP, don't do a git pull

If you git push, find the problem, then do a git pull, you're in no man's land

If you've been able to resist the urge to git pull, then merely do a

git pull --rebase which will fix this

http://stackoverflow.com/a/4675513/168874