Skip to content

Instantly share code, notes, and snippets.

View JacobCallahan's full-sized avatar
🧐
🥓

Jake Callahan JacobCallahan

🧐
🥓
View GitHub Profile
@JacobCallahan
JacobCallahan / rand_name.py
Last active March 14, 2024 13:20
random people selector
import math
import pathlib
import random
import sys
import time
# Define the list of names
names = ['tasos', 'brian', 'mayuri', 'sudhir', 'sam', 'stephen', 'justin', 'cole', 'griffin', 'jake', 'david', 'danny']
# Create a list of weights that decreases logarithmically as you move through the list
@JacobCallahan
JacobCallahan / shared_resource.py
Created August 8, 2023 12:25
proof of concept for a SharedResource context manager with error recovery
"""Allow multiple processes to communicate status on a single shared resource."""
import json
import time
from pathlib import Path
from uuid import uuid4
from broker.helpers import FileLock
class SharedResource:
def __init__(self, resource_name, action, *action_args, **action_kwargs):
self.resource_file = Path(f"/tmp/{resource_name}.shared")
@JacobCallahan
JacobCallahan / linear.py
Created June 29, 2023 19:23
old linear regression class
import attr
@attr.s()
class LinearRegression():
data_points = attr.ib()
def __attrs_post_init__(self):
self._learn_data()
def _learn_data(self, data_points=None):
@JacobCallahan
JacobCallahan / spm_helper.py
Created May 10, 2023 20:17
a stupid class that makes variable access in structural pattern matching less painful
class SPMHelper:
def __init__(self, **vars):
if not vars:
vars = {k: v for k,v in globals().items() if not k.startswith("_")}
self.__dict__.update(vars)
# usage - pulls in all global-level variables
vars = SPMHelper()
vars.some_variable
@JacobCallahan
JacobCallahan / prod_log_scraper.py
Created February 13, 2023 20:16
Point at a foreman production.log file and see the most frequently used foreman/katello api endpoints
"""Some utilities for scraping Satellite production logs"""
import argparse
from pathlib import Path
def log_to_dicts(log_path):
"""Convert a Satellite log file to a list of dict log entries"""
dict_list = []
log_entry = {}
current_group = ""
@JacobCallahan
JacobCallahan / log_deploy_times.py
Last active July 25, 2022 14:33
Quick script to scrape robottelo worker logs for time spent deploying
import argparse
import json
from datetime import datetime, timedelta
from pathlib import Path
class Tracker:
def __init__(self):
self._td_total = timedelta()
self._count = 0
@JacobCallahan
JacobCallahan / export_entities.py
Created June 15, 2021 14:36
This is a script that exports all "entities" in a Satellite system to json and yaml files
from requests.exceptions import HTTPError
from nailgun import entities
from nailgun.entity_mixins import EntitySearchMixin
from nailgun.config import ServerConfig
import json
import yaml
ServerConfig(url="<satellite url>", auth=("admin", "<passowrd>"), verify=False).save()
def search_entity(ent, **kwargs):
@JacobCallahan
JacobCallahan / parallel_logger.py
Last active May 27, 2021 19:38
A parallel logger that allows for an optional verbose mode and still calls the actual logger
import json
import yaml
import logging as real_logger
class ParallelLogger:
def __init__(self, output_file=None, verbose=False):
self.data = []
self._output_set = False
self.set_file(output_file)
self.verbose = verbose
@JacobCallahan
JacobCallahan / some_script.py
Created May 13, 2021 19:55
you know the thing...
import sys
import time
import random
# ['test_cli.py', 'sub-command', '--option1', '17', '--test-flag']
# fix --test-case 0971v2s983a123-sad3t13rg-re36570-4563 --auto-merge
# close --test-case
# yolo --420
@JacobCallahan
JacobCallahan / mass_hosts.py
Created November 24, 2020 14:57
add content hosts to satelite
import asyncio
from socket import timeout
import aiohttp
import json
import uuid
import click
from functools import wraps
def coro(f):