This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Retrieve github archieve data from: | |
https://www.githubarchive.org/ | |
""" | |
import datetime | |
from concurrent.futures import ThreadPoolExecutor | |
from tqdm import tqdm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
METADATA_URL = 'http://169.254.169.254/latest/meta-data/' | |
class AmiMetaDataManager: | |
""" | |
Provides a simple wrapper around the AWS ec2 instance metadata interface | |
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
from functools import wraps | |
import redis | |
REDIS_HOST = 'localhost' | |
REDIS_PORT = 6379 | |
REDIS_CONNECTION_POOL = redis.ConnectionPool(host=REDIS_HOST, port=REDIS_PORT) | |
CACHE_EXPIRE_SECONDS = 5000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
VALID_PYTHON_EXTENSIONS = ('.py', ) | |
def get_userdefined_class(directory: str, target_baseclass: object) -> list: | |
""" | |
Load Classes that sub-classed the given 'target_baseclass' for modules in the given directory | |
:param directory: directory containing user-defined classes subclassing 'target_baseclass' | |
:param target_baseclass: the ABC class that the user class subclasses | |
:return: (class) [UserDefinedClass, ...] | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def _get_package_defined_classes(package, target_baseclass) -> dict: | |
""" | |
Voodoo function to discover classes in given 'package' that subclass the given 'target_baseclass' | |
:param package: Python Package Object | |
:param target_baseclass: Python Class Object | |
:return: | |
{ | |
CLASS_NAME: CLASS_OBJECT, | |
... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
This is a script to compare the content of two directories. | |
It was used to determine how complete a series of cp commands were done after the cp process was already started | |
""" | |
import os | |
def directory_size(path): | |
total = 0 | |
for entry in os.scandir(path): | |
if entry.is_file(): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import csv | |
from multiprocessing import cpu_count, Pool | |
def process_csv(args): | |
filepath, encoding = args | |
unique_ids = set() | |
with open(filepath, 'r', encoding=encoding) as in_f: | |
reader = csv.reader(in_f) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# the `update-function-configuration` overwrites the existing set envars. | |
# In order to *ADD* variables we need to read the existing envars and add to that. | |
# This command uses `jq` to read and transform the json result to an envar then update the lambda configuration | |
# create the updated envar set | |
export YOUR_FUNCTION_NAME={populate this} | |
export UPDATED_ENVIRONMNET_VARIABLES=$(aws lambda get-function-configuration --function-name ${YOUR_FUNCTION_NAME} | \ | |
jq --compact-output ".Environment + {\"Variables\": (.Environment.Variables + {\"NEW_ENVAR_NAME\": \"NEW_ENVAR_VALUE\"})}") | |
# check |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Get/Set lambda environment variables | |
""" | |
import os | |
import pprint | |
from pathlib import Path | |
from typing import Tuple, List | |
from enum import Enum | |
import boto3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from colorsys import rgb_to_hls, hls_to_rgb | |
class ScaledFloatColorManager: | |
""" | |
Intended to provide a scaled legend between to colors in the HSL space | |
""" | |
def __init__(self, name, minimum_value, maximum_value, hex_color_min="66b219", hex_color_max="cc0000", display_band_count=6): | |
self.name = name |