layout | lastchange | url |
---|---|---|
post |
25-09-16 v022 + diagrams-graphwiz.py :README.md |
The objective of this repo is to provide examples of practical use of production-quality Python language.
There are plenty of other sites and repos offering code to play games or demonstrate a coding trick.
Not here.
Here we aim to provide code that exhibit the security and technical features needed in a (hostile) production environment where debugging needs to occur quickly.
These contain various utilities I wrote which have the most practical usefulness.
Each contains helpful features implemented as identified:
PROTIP: List the last_change of all python (.py) files in this repo by running:
chmod +x dundars-list.py
./dundars-list.py
-
dundars-list.py lists programs by date, along with the last_change and status text in each python program.
-
diagrams-graphwiz.py generates diagram files from text, using graphwiz tool library.
-
python-samples.py is a conglomeration of many features.
-
gpu-sample.py recognizes what GPU is available (CUDA or Apple MPS) and runs sample PyTorch microbenchmarks of timings and memory used. Enhancements:
-
About Google's Tensorflow: ipynb based on the VIDEO: Awaiting the 2025 4th edition to October 2022 O'Reilly book: Hands-on Machine Learning with Scikit-Learn, Keras and TensorFlow (3rd edition) by Aurélien Geron (YouTube, interview, X)
-
print-inkjet.py keeps print heads clear by sending a pdf containing colored text and images. Features and enhancements:
- Quotes scraped from the internet to print.
- Quotes scraped from the internet to print.
-
ls_al.py lists files in a directory like the Linux command ls -al.
-
mondrian-gen.py to generate a png art in the style of Mondrian. References macOS Keychain to keep OpenAI API key.
-
saytime.py to use the macos say CLI command to voice the time or other text.
-
sorting.py to run different sorting algorithms to compare performance as n rises, on a matplotlib visualization.
-
sqlite-sample.py to create and maintain a SQLite database.
In the weather folder:
-
openweather.py to obtain from API calls and format weather data (as fuzzy tokens). Features
- Lookup Longitude/Latitude by zip code
- wttr-weather.py issues curl commands for weather data (https://github.com/chubin/wttr.in)
- Display on a monitor information about the location of people you communicate with
- Use BeautifulSoup to scrape predictions from google.com (which references Weather.com).
- Compare actuals vs. predictions of each prediction service.
- Compare accuracy of different predictors (weather.com vs. wattr.in vs. Openweather. etc.)
-
youtube-download.py downloads videos based on its URL from a list of URLs in a CSV file.
In the recommender folder:
- it-media.py is a popular way to show off skill at database manipulation, analytics, and machine learning. Related enhancements:
-
Bulk load into database movie info (such as "m1-100k")
-
Reconcile data about the same movie from various sources.
-
Sorting by several factors: genre, content rating, year, actors, directors, academy awards
-
Link to rottentomatoes.com and other reviews
-
Link availability of movie on various streaming platforms (Netflix, Prime, etc.)
-
Enable entry of user ratings and use that data to influence recommendations.
-
Link release dates to calendar
-
Catalog DVD collection by scanning UPC labels.
-
Play a particular video in a media app after scanning the UPC on the video box.
-
surprise.py provides a GUI created (using tkinter) to select movies and TV shows as an example of machine learning matrix eigenvector SVD (Singular Value Decomposition) & PCA (Principal Component Analysis) feature extraction algorithms from data science.
-
Recommend movies based on what friends watched.
-
-
argparse-samples.py to specify command line arguments into this program.
-
bookmarks_export.py to export bookmarks from Chrome to a HTML file.
-
calculator-tk.py is a calculator created using the Tk GUI library.
-
dijkstras.py to compare calculations of shortest path on a graph
-
dijkstra-yt.py to calculate shortest path using heapq library
-
endecode-protobuf.py encodes/decodes a comma-separated list so each word in front of a # prefix has a char count, like Protobuf does for gRPC.
-
fido2-titan.py to use the FIDO2/WebAuthn protocol to read FIDO2-compliant OTP+FIDO+CCID keys
-
log-time-csv.py creates the path to a CSV file based on static naming standards to write a sequential time stamp to a CSV file. Has limits to an infinite loop.
-
logging.py to use the logging module to log messages to a file.
-
ml-metrics.py to use PyTorch & Scikit to generate metrics for Machine Learning.
-
num2words.py simply converts a number input to its word.
-
otel-flask.py - a simple Flask app with automatic OpenTelemetry instrumentation
-
pengram2nato.py to use the NATO phonetic alphabet spell out a sentence.
-
perf-ns.py obtains timings in nanosecond-level resolution.
-
plotting.py to create common visualizations using matplotlib.
-
pytorch-mnist.py to use PyTorch to build, train and evaluate a neural network to recognize a hand written digit MNIST
-
random-niche.py to generate a 19-digit cryptographically secure random number.
-
recursive-cache.py shows faster Fibonnici recursion calls when using functools cache.
-
rolldice.py rolls a 6-sided die used in Yahtzee, rolled repeated until "quit".
-
rot13.py is used on UseNet to encode sentences using a cypher that's 13 characters away.
-
roku-set.py opens Roku at a given IP address to the YouTube video specified.
-
roman2int.py converts Roman numerals to base 10 numbers.
-
sklearn-sample.py calculates
-
try-accept.py to show usage of try/except/else/finally exceptions
-
unittest_calculator.py to use Python's Unit Test feature.
-
variables.py to experiment with defining and viewing objects of various data types.
- bomonike/memon to generate a strong passphrase based on random words in English and German.
- bomonike/google/gcp-services has authentication and other functions to access services within the Google Cloud Platform (GCP)
- bomonike/google/myutils.py contains utility functions useful for calling by other programs.
In the countries folder:
-
country_info.csv
-
country_lang_info.xlsx
-
Comparison of countries: csv from a year of the World Happiness Report and statistics from the CIA Factbook.
- Use OpenCV to recognize hand signals (Sign Language), then take an automatic action or raise an alarm when touching your face (bad hygiene).
In the predictions folder is an example
-
Use Box charts and descriptive statistics to compare trends in currency exchange rates (of euros, Japanese yen, Chinese runbei, etc.) vs. price of gold, bitcoin, etc.
-
https://codepen.io/freeCodeCamp/pen/dNVazZ Recipe Box app in JavaScript for a Take Home Project.
NOTE: Other pograms are in the https://github.com/bomonike organization:
-
https://github.com/bomonike/memon calculate super strong word phrases and remember them via LLM gen'd songs. See https://www.youtube.com/watch?v=KAjkicwrD4I on how to memorize using PAO (Person Action Object)
-
palindromes.py - I personally don't understand the intellectual curiosity for words and phrases that spell the same forward and backward. Examples: TENET, 747, KAYAK, TACO CAT, RACECAR, NEVER ODD OR EVEN, STEP ON NO PETS, UFO TOFU
The features in each code section:
-
SECTION 01: Preparations before running this program: Bash CLI commands to load external libraries (such as uv add matplotlib ...
last_commit = "v007 + ruff checks & fixes :print-inkjet.py"
-
SECTION 02: Load modules used by this program: External libraries are imported within a try/except structure so instructions are given on fail.
-
SECTION 03: Logging: Capture pgm start date/time (as global variables)
-
SECTION 04: Define utilities to print messages:
-
SECTION 05: Globals: Define hard-coded Global variables as parm defaults:
-
SECTION 06: Show args_prompt() menu and read params specified on program command line: -v SHOW_VERBOSE
-
SECTION 06-2: Set display and exit
-
SECTION 06-3: Read parameters as command arguments:
-
SECTION 06-5: Edit parameter values from command arguments:
-
SECTION 07: Obtain variables from .env file and secrets vault (in cloud): MY_USERNAME, MY_LOCATION, MY_PRINTER, MY_REGION, etc.
-
SECTION 08: Validate values from all sources above:
- File or database specified of correct format and exists?
-
SECTION 09: Login:
-
SECTION 10: Define utilities to read and delete files and folders: (folder_, file_, csv_, pdf, png, sqldb_, docdb_, graphdb_, rag_, etc. => _check, _create, _search, _seqread, _delete, _update, _audit, _graph, etc.)
-
SECTION 11: Define utilities to list and print to printers:
- CHECK_FOR_FILE_IN_PATH if an existing .pdf file exists in path to print.
-
SECTION 12: Create custom outputs:
- Create a pdf containing colors printed (if requested by CREATE_COLOR_BLOCKS)
-
SECTION 13: Audit outputs and send alerts
-
SECTION 14: Clean up: Delete (remove) .pdf file created by this program if REMOVE_PDF_FILE_CREATED = True
-
SECTION 15: pgm_stats() to show how long the program ran and how many items were processed.
-
SECTION 16: Main calls to functions defined above:
Below are notes about coding practices, from the top down:
-
At the very top of the file:
#!/usr/bin/env python3
That enables you to run the program as a script without typing python3:
./mondrian-gen.py
instead of
python3 mondrian-gen.py
-
This specifies that emjois and non-English characters (such as Japanese, Chinese, etc.) may be in the code file:
# -*- coding: utf-8 -*-
-
SPDX (Software Package Data Exchange) license identifiers provide machine-readable tags to communicate the license governing a piece of software.
# SPDX-License-Identifier: MPL-2.0
The MPL-2.0 (Mozilla Public License version 2.0) is a moderately permissive open-source license with some copyleft provisions. Its key characteristics include:
- Allows code to be freely used, modified, and shared
- Requires modifications to MPL-licensed files to be shared under the same license
- Allows MPL-licensed code to be combined with code under different licenses
- Provides patent protection for contributors and users
- Requires preservation of copyright notices
-
Dunder (double underscore) variables in the module define metadata about the program. PEP specifies that such variables can be read by other programs without opening the source code.
__commit_date__ = "2025-05-20" __version__ = "1.0.0" __author__ = "Your Name" __license__ = "MIT" __commit_date__ = "2025-05-20" __status__ = "Production" __doc__ = "This module demonstrates the use of dunder (double underscore) variables in Python."
-
To capture the program start time at the earliest moment, the built-in time module is used:
import time std_strt_timestamp = time.monotonic()
time.monotonic() returns the time since an arbitrary point in the past, which is not affected by system clock changes.
-
External dependencies are specified in a requirements.txt file.
import requests
-
Within the requirements.txt file, the myutils module is loaded to provide all other custom Python programs in this repo:
import myutils
- Modules used The ast (Abstract Syntax Tree) module parses Python source code into a structure so code can be better analyzed or modified programmatically.
import ast
ast is used by linters, type checkers, and other such tools to analyze code without running it.
-
All functions defined in this file are prefixed with myutil_ to avoid name conflicts in other modules.
def myutil_print(msg): print(msg)
-
The function issuing a message to the console is printed along with the message:
def myutil_print(msg): print(msg)
-
Reset all my passwords automatically. This would involve my database in KeePassXC and 1Password, then programmatic control operating Authy and emails to confirm.
-
Functions to reference a physical Yubikey containing secrets and cryptographic certificates.
The STATUS of each program is noted within each file.
Before running each:
chmod +x dijkstras.py
./dijkstras.py
https://codehs.com/tutorial/david/sample-a-csp-performance-task-1 Sample A CSP Performance Task
https://codehs.com/tutorial/david/sample-b-csp-performance-task Sample B CSP Performance Task - Caesar Cipher
https://www.youtube.com/watch?v=LXsdt6RMNfY Use Python to automate my life
https://www.youtube.com/watch?v=mCk4Rabkmjc Automate Boring Office Tasks with ChatGPT and Python
https://www.youtube.com/watch?v=Ge-9AhVVOFc Automate any task using ChatGPT! (my full GPT building framework)
import subprocess result = subprocess.run(["bash", "path/to/script.sh"], capture_output=True, text=True) stdout = result.stdout stderr = result.stderr
https://github.com/Gatsby-Lee/DevOps/tree/master/programming_lang/python
https://www.youtube.com/watch?v=kGcUtckifXc Please Master These 10 Python Functions…
Have a single import per line to reduce merge conflicts. See https://github.com/asottile/reorder-python-imports?tab=readme-ov-file#why-this-style