Skip to content

Instantly share code, notes, and snippets.

View wcDogg's full-sized avatar

wcDogg wcDogg

  • Philadelphia, PA
View GitHub Profile
@wcDogg
wcDogg / google-map-embed.md
Last active September 9, 2023 17:59
Google Map Embed - Position, Zoom, Color

Embed a Google Map on a Google Site

This article applies to Google Workspace and Google My Maps, though the concepts should work with any Google Map.

While Google Sites has a quick embed for My Maps, it lacks position, zoom, and color control. Instead, we start with the Google-generated embed code, modify it, and add it to the site as a regular embed.

Get the Position and Zoom

  1. My Maps > Map > Preview. Opens in new tab.
@wcDogg
wcDogg / python-obfuscate-string.md
Last active January 21, 2023 06:15
A function to replace some or all of a string's characters with asterisks.

Python: Obfuscate String

A function to replace some or all of a string's characters with *** asterisks.

def obfu_string(string: str, show_first: bool = True, show_last: bool = True) -> str:
  '''Obfuscates a string by replacing characters with *asterisks.
  '''

  str_list_in: list = []
@wcDogg
wcDogg / python-install-multiple-versions-on-linux.md
Last active January 21, 2023 06:19
How to install, manage, and use multiple versions of Python on Linux.

Install Multiple Versions of Python on Linux

Tools like Nox run tests against multiple versions of Python. Here's how to use pyenv to manage multiple versions of Python and make those versions available during testing.

Existing Python?

I've used distros where no Python is installed and where multiple versions are installed. If it's reasonable, go for a blank slate by uninstalling existing Python.

@wcDogg
wcDogg / python-install-multiple-versions-on-windows.md
Last active January 21, 2023 06:19
How to install, manage, and use multiple versions of Python in Windows.

Install Multiple Versions of Python on Windows

Tools like Nox run tests against multiple versions of Python. Here's how to use pyenv-win to manage multiple versions of Python and make those versions available during testing.

Existing Python?

There's a good chance you already have Python installed. Check:

  • Start > Settings > Apps > Apps & Features
@wcDogg
wcDogg / python-list-files-in-directory.md
Last active January 21, 2023 06:28
An OS-agnostic way to list files in a directory using Python.

Python: List Files in a Directory

from os import listdir
from pathlib import Path

dir_start: Path = "D:\Media\Movies"

for f in listdir(dir_start):
 print(f)
@wcDogg
wcDogg / python-appdirs.md
Last active August 30, 2023 16:26
How to locate OS-appropriate directories for storing app data on a user's computer in Python.

Python: Locate OS Paths for Common App Directories

appdirs helps you locate OS-appropriate directories for storing app data on a user's computer - user, site, caxhe, log. I use appdirs to write log files.

python -m pip install appdirs

appdirs Paths

Python: Catch Warnings with Try Except

Today I needed to handle a Pillow warning. Many posts demonstrate how to treat all warnings as exceptions so they can be caught with try and exept. I quickly discovered that catching all warnings can be problematic. Here's how to catch specific warnings:

import warnings
warnings.filterwarnings("error", category=Image.DecompressionBombWarning)

def process_images():
 try:

Python: Simple Logging

# module.py
import logging
logging.basicConfig(level="DEBUG", format='%(asctime)s : %(levelname)s : %(name)s : %(message)s', datefmt='%Y-%m-%d %H:%M:%S')
log = logging.getLogger(__name__)
@wcDogg
wcDogg / bash-prompt-create-password.md
Last active September 7, 2022 04:18
Bash: Create Password Prompt

Bash: Create Password Prompt

  • Prompt user to create and confirm a new password.
  • Cannot be blank.
  • Hide user's entry.
while :     
do
 read -rs -p "${QUEST} Admin PW: " NETWORK_PW && echo
@wcDogg
wcDogg / FizzBuzz-Python.md
Last active January 21, 2023 06:59
FizzBuzz in Python

FizzBuzz in Python

Like 3M other people inspired by Tom Scott's FizzBuzz: One Simple Interview Question video, here is my 20 minute stab at FizzBuzz. I imagine a programmer would nail this in under 10 :P

I did it this way because I was curious about the different patterns variable inputs would create. The results remind me of The Rythm of Primes :)

class FizzBuzz:
  '''Classic children's game in Python.
  '''