Skip to content

Instantly share code, notes, and snippets.

View therealzanfar's full-sized avatar

Matthew therealzanfar

  • Phoenix, USA
View GitHub Profile
@therealzanfar
therealzanfar / roshambo.py
Last active June 14, 2024 03:45
Python Beginner Project Examples
"""Generic, Extensible Roshambo Game."""
import random
from enum import Enum
from typing import NamedTuple
class OptionDef(NamedTuple):
"""Details about a throw option."""
@therealzanfar
therealzanfar / code_review.md
Created May 31, 2024 22:51
Python Code Review

Python Code Review

Work in Progress

Introduction

A common request in /r/learnpython is for a review of existing code. While I have no intention of discouraging that practice, 90% of submissions include the same, basic issues. This is a list of those most common issues along with an attempt to elaborate on the issue and possible solutions.

@therealzanfar
therealzanfar / pyenv_commands.md
Last active October 31, 2023 22:53
pyenv Commands
  • pyenv update
  • pyenv versions Installed versions
  • pyenv install --list Availalable versions
  • pyenv install <versions>
  • pyenv global [system] <versions> Set shim priority
  • pyenv uninstall <versions>
@therealzanfar
therealzanfar / delete_trakt_history.user.js
Last active December 3, 2022 15:55
VERY DANGEROUS Greasemonkey script to delete your Trakt view history in bulk.
// ==UserScript==
// @name Trakt History Remover
// @namespace https://gist.github.com/therealzanfar
// @author Matthew W.
// @description Delete Trakt view history in bulk
// @version 1
// @match *://trakt.tv/users/*/history
// @match *://trakt.tv/users/*/history/*
// @run-at document-start
// @grant unsafeWindow
@therealzanfar
therealzanfar / logging_snippets.py
Last active October 31, 2023 20:21
VSCode Snippets for Python Logging
"logging setup": {
"prefix": "logsetup",
"body": [
"import logging",
"from rich.logging import RichHandler",
"",
"def setup_logging(verbosity: int = 0, force: bool = False) -> None:",
"\t\"\"\"",
"\tSet up a root logger with console output.",
"",
from collections import deque
from typing import TypeVar, Iterable, Iterator
T = TypeVar("T")
def window(i: Iterable[T], size: int = 2) -> Iterator[tuple[T, ...]]:
"""Yield a sliding window of items from an iterator."""
i: Iterable[T] = iter(i)
@therealzanfar
therealzanfar / coordinate.py
Last active January 2, 2024 01:13
Useful Python utility functions
class Coord2:
"""
A 2-dimensional Coordinate.
"""
@therealzanfar
therealzanfar / $mkenv.sh.md
Last active May 13, 2023 13:37
Legacy shell script to (re)create a Python virtual environment PLEASE READ NOTE

This gist remains for historical reaons, however, I can no longer recommend using it.

The pracitce of using requirements.txt and simple pip dependencies is outdated and deprecated. All new projects should use a tool that supports the pyproject.toml integrated format and keeps locked versions for specified and child dependencies. My current choice is Poetry.