Skip to content

Instantly share code, notes, and snippets.

View JacobCallahan's full-sized avatar
🧐
🥓

Jake Callahan JacobCallahan

🧐
🥓
View GitHub Profile
"""Purpose of the script goes here.
Example usage for the script goes here.
python this_script.py <args>
"""
import os
import sys
import urllib2
import wget
@JacobCallahan
JacobCallahan / setup.sh
Created December 20, 2017 19:49
create stuff and do the things
#!/usr/bin/bash
# Create and populate a repository.
set -euo pipefail
# hammer auth login -u admin -p changeme
hammer -u admin -p changeme product create --name repotest --organization-id 1
hammer -u admin -p changeme repository create \
--content-type 'yum' \
--url 'https://repos.fedorapeople.org/pulp/pulp/fixtures/rpm-signed/' \
--download-policy 'on_demand' \
@JacobCallahan
JacobCallahan / async_bugzilla.py
Created March 14, 2018 13:55
asynchronously gather bugzilla information
import os
import asyncio
import sys
try:
import bugzilla
except ImportError:
print('Install dependencies with `pip install -r -requirements.txt`.')
sys.exit(-1)
@JacobCallahan
JacobCallahan / simple_config.py
Last active April 30, 2019 13:51
Stupidly simple config class. Read from yaml or json configs as well as environment variables
"""Simple Config - Config.... Simplified!"""
import json
import os
import yaml
from pathlib import Path
from logzero import logger
class SimpleConfig:
@JacobCallahan
JacobCallahan / Silent_Bugzilla_CLI
Last active September 26, 2019 15:32
How to update bugs, without sending an email, in the CLI
For this, we will be using the python-bugzilla module
pip install python-bugzilla
This provides 'bugzilla' command, which is the interface we'll be using.
bugzilla has a "modify" sub command which allows us to update a bug via the CLI.
The most important piece of this is to pass the following argument, which surpresses email updates.
--field=minor_update=1
@JacobCallahan
JacobCallahan / classtest.py
Created October 17, 2019 19:24
Written during a quick class on python classes
import random
class MyBase:
"""This is a base class"""
def __init__(self, **kwargs):
"""Assign each key, value pair to our class instance"""
for arg, val in kwargs.items():
self.__dict__[arg] = val
@JacobCallahan
JacobCallahan / generators.py
Created October 24, 2019 19:30
Generators and Iterators
# generators and iterators
import random
def my_gen(in_str="This is a sentence."):
"""A generator that returns on character in a string per iteration"""
for char in in_str:
yield char # return one character and wait
def big_list():
"""Create a list of number from 0 to 100 million"""
@JacobCallahan
JacobCallahan / decorators1.py
Created November 22, 2019 15:29
Decorator Class 1
"""
Decorators provide a way to intercept a decorated function, method, or class.
Ultimately, the decorator accepts the function as its only argument
Decorators can then either return the original function, or another one
"""
def change_name(func):
"""This decorator just changes the name of any decorated function"""
func.__name__ = "changed"
@JacobCallahan
JacobCallahan / fixtures.py
Created January 23, 2020 20:50
Fixture demo
"""Pytest fixtures
Fixtures give you a convenient way to perform setup actions outside of a test.
By limiting or expanding the scope of a fixture, you can cut down on costly setup tasks.
"""
import pytest
import random
import unittest2 # please never
NUM = "0123456789"
@JacobCallahan
JacobCallahan / async_runner.py
Created January 28, 2020 19:51
prototype general async requests thing
import aiohttp
import asyncio
import async_timeout
import click
from logzero import logger
from pathlib import path
class AsyncRunner:
"""A general class to perform async requests and process data"""