Skip to content

Instantly share code, notes, and snippets.

View cidrblock's full-sized avatar

Bradley A. Thornton cidrblock

View GitHub Profile
@cidrblock
cidrblock / extract.py
Last active May 5, 2023 16:58
Extract pylint rules implimented in ruff
import requests
from bs4 import BeautifulSoup
url = "https://github.com/charliermarsh/ruff/issues/970"
response = requests.get(url)
html_content = response.content
soup = BeautifulSoup(html_content, "html.parser")
li_tags = soup.find_all("li")
@cidrblock
cidrblock / playhouse.py
Created August 25, 2022 16:45
Triangle solver
"""Convert to feet/inches."""
import math
def div32(number: float) -> int:
"""Return the closest 32nd of an inch.
:param number: number to be divided
:return: closest number divided by 32
import jinja2
def to_template(string):
return f"{{{{ {string} }}}}"
env = jinja2.Environment()
# -*- coding: utf-8 -*-
# Copyright 2020 Red Hat
# GNU General Public License v3.0+
# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
"""
flatten a complex object to dot bracket notation
"""
from __future__ import absolute_import, division, print_function
# -*- coding: utf-8 -*-
# Copyright 2020 Red Hat
# GNU General Public License v3.0+
# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
"""
flatten a complex object to dot bracket notation
"""
from __future__ import absolute_import, division, print_function
# roles/template_test/filter_plugins/eth_builder.py
# -*- coding: utf-8 -*-
# Copyright 2020 Red Hat
# GNU General Public License v3.0+
# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
"""
sample use of dataclass in filter plugin
@cidrblock
cidrblock / run.yaml
Created June 2, 2022 20:46
Sample pypyr CI pipeline
# Sample pypyr file for running CI jobs locally
# example usage:
# - run with default parameters (python3.10 and ansible 2.13)
# $ pypyr run
# - run with default paramters, but stop at the first error
# $ pypyr run continue_on_error=False
# - run with py3.8 and ansible 2.12
# $ pypyr run python_version=3.8 ansible_version=stable-2.12
# - run with py3.10 and milestone, but only unit and sanity
# $ pypyr run python_version=3.10 ansible_version=stable-2.12 --groups unit sanity
# cspell:ignore dpkg, getent, lineinfile, nxapi, nxos, rglob, ruamel, sysvinit
"""A test files updater."""
import logging
import ruamel.yaml
from pathlib import Path
from typing import OrderedDict
from ansiblelint.yaml_utils import FormattedYAML
@cidrblock
cidrblock / parser_defintion.yml
Created April 13, 2022 10:14
Parse output using native parser
x1 ➜ collection_development ansible-navigator run parse.yml -m stdout --ee false
PLAY [localhost] ***************************************************************
TASK [Define some data] ********************************************************
ok: [localhost]
TASK [Pass text and template_path] *********************************************
ok: [localhost]
@cidrblock
cidrblock / site.yml
Created April 12, 2022 20:17
Validate IPv4 address in lists of interfaces
- hosts: localhost
gather_facts: false
tasks:
- name: Define some data
ansible.builtin.set_fact:
data:
wan:
- name: LAN3
ipv4-address: 100.100.100.1
subnet-mask: 255.255.255.248