Skip to content

Instantly share code, notes, and snippets.

View seasonedgeek's full-sized avatar
💭
Active Referee. (Semi-retired) Developer.

Tom Stewart seasonedgeek

💭
Active Referee. (Semi-retired) Developer.
View GitHub Profile
@seasonedgeek
seasonedgeek / make-egg.zsh
Created January 8, 2021 01:58
Zsh Script to manage a local Python 3 project.egg-info directory.
#!/opt/local/bin/zsh
# make-egg
usage="
$0 [pie | dump | help] -- makes editable <project>.egg-info
where options are:
pie creates <project>.egg-info directory
dump removes <project>.egg-info directory
help show this help text."
@seasonedgeek
seasonedgeek / SquashLogs.java
Last active May 31, 2020 00:24
Clean up session logs generated by iTerm.app
package com.seasonedgeek.squashlogs;
import java.io.File;
import java.util.Calendar;
import java.util.Date;
/**
* <p>
* SquashLogs is a command line process that cleans up dated log files
* generated by iTerm (app) sessions.
@seasonedgeek
seasonedgeek / upgrade_outdated_brews.py
Last active May 21, 2020 00:21
Identifies outdated packages managed by Homebrew and then automates each package's upgrade process.
"""This module seeks to help the user save time, by identifying outdated
packages managed by Homebrew and then automating each package's upgrade
processes."""
#!/usr/bin/env python3
import subprocess
def main():
"""Function creates a list of outdated packages to upgrade (if any)"""
@seasonedgeek
seasonedgeek / check_requirements.py
Created May 3, 2020 02:51
Alternative to processing a Python requirements file
#!/usr/bin/env python3
"""Checks the installation of packages, as recommended by the authors of
`Tiny Python Projects` (MEAP 6.0.0, Manning Publications 2020) to
learn by doing while enduring the covid-19 `stay safer @ home` orders.
See https://www.manning.com/books/tiny-python-projects?query=tiny.
"""
import shlex
@seasonedgeek
seasonedgeek / decompress_webp_files.sh
Last active May 3, 2020 02:43
Uses Google's WebP `dwebp` to decompress `webp` images into `png` images.
#!/usr/bin/env zsh
# decompWebp.zsh - Decompresses WebP files into PNG files.
set basedir=$1
for file in ${basedir}/**/*.webp ; do
# ext = PNG, PAM, PPM or PGM
ext=".png"
@seasonedgeek
seasonedgeek / trash_target_gems.rb
Created February 28, 2020 18:28
Programmatically uninstall one or more target gems including ALL of their dependencies.
#!/usr/bin/env ruby
# -- coding: utf-8 --
# frozen_string_literal: true
require 'json'
require 'ostruct'
require 'logger'
# This module attempts to trash (uninstall) one or more target gems,
@seasonedgeek
seasonedgeek / add_project_configs.py
Last active February 24, 2020 02:34
Writes user's custom linter and testing configuration files to project directory. (Such as: ~/Exercism/python/<exercise-directory>)
# -*- coding: utf-8 -*-
import argparse
import configparser
import sys
from pathlib import Path
"""Writes configuration files
Writes flake8, mypy, pytests, tox configuration files
@seasonedgeek
seasonedgeek / twelve_days.py
Created February 11, 2020 07:31
Exercism.io/Python: Twelve Days (Practice Mode)
# -*- coding: utf-8 -*-
from json_database import JsonDatabase
"""Adds selected lyrics from the song: 'The Twelve Days of Christmas'
to a list.
Uses JsonDatabase. See details @:
- https://pypi.org/project/json-database/
- https://github.com/OpenJarbas/json_database
@seasonedgeek
seasonedgeek / write_pkg_requirements.py
Created February 2, 2020 07:16
Write Versioned Python Packages to Requirements File for Uninstallation
import re
"""This script prepares a stream of text (captured during a Terminal session).
The text represents the named package installations of `pyttsx3` and its
113 versioned dependencies.
The captured stream of text (copy & paste) was saved to the `trash_pkgs.txt`
file. This script transforms its contents to specification and writes a
`requirements.txt` file. The requirements file is used by the command:
@seasonedgeek
seasonedgeek / multireader_issues_solutions.md
Created January 31, 2020 07:20
Solutions for {bound method; utf-8 decode} MultiReader.read & test.bz2: {UnicodeDecodeError} invalid start byte

MultiReader Issues/Solutions

While trying out the reader project code presented in Chapter 1 of The Python Journeyman, I problem solved a couple of issues. I'm certain that my issues are related to being a Java defector, and a pythonic newbie.
I'm running Python 3.8.1 on macOS 10.15.

My Issues:

  • UnicodeDecodeError: 'utf-8' codec can't decode byte ...: invalid start byte

    The invalid start byte, I assume is related to test.bz2 and the authors' bz2.open(..., mode='wt'). I used mode='wb'.

  • bound method MultiReader.read of <reader.multireader.MultiReader object at 0x10f4a8a90>