Skip to content

Instantly share code, notes, and snippets.

Avatar

Paul McGuire ptmcg

View GitHub Profile
View peps.json
[
{"id": "1", "title": "PEP Purpose and Guidelines", "authors": "Warsaw, Hylton, Goodger, Coghlan", "discussions_to": null, "status": "Active", "type": "Process", "topic": "", "created": "13-Jun-2000", "python_version": null, "post_history": "21-Mar-2001, 29-Jul-2002, 03-May-2003, 05-May-2012, 07-Apr-2013", "resolution": null, "requires": null, "replaces": null, "superseded_by": null, "url": "https://peps.python.org/pep-0001/", "abstract": ""},
{"id": "2", "title": "Procedure for Adding New Modules", "authors": "Cannon, Faassen", "discussions_to": null, "status": "Active", "type": "Process", "topic": "", "created": "07-Jul-2001", "python_version": null, "post_history": "07-Jul-2001, 09-Mar-2002", "resolution": null, "requires": null, "replaces": null, "superseded_by": null, "url": "https://peps.python.org/pep-0002/", "abstract": "\nIntroduction\nThe Python Standard Library contributes significantly to Python's\nsuccess. The language comes with \"batteries included\", so it is easy\nfor people to become produ
View splitby.py
import typing
from functools import lru_cache
T = typing.TypeVar("T")
PredicateFunction = typing.Callable[[T], bool]
SourceIterable = typing.Iterable[T]
ObjectList = typing.List[T]
def splitby(
@ptmcg
ptmcg / plusminus_dice_roller_demo.html
Created Jun 1, 2022
Pyscript+plusminus Dice Roller
View plusminus_dice_roller_demo.html
<html>
<head>
<title>Plusminus Dice Roller</title>
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
<py-env>
- plusminus
</py-env>
</head>
@ptmcg
ptmcg / pyscript_littletable_iris.html
Last active May 19, 2022
Demonstration of CSV import using littletable in pyscript
View pyscript_littletable_iris.html
<html>
<head>
<script defer src="https://pyscript.net/alpha/pyscript.min.js"></script>
<py-env>
- littletable
</py-env>
</head>
<body>
<h2>Iris data</h2>
@ptmcg
ptmcg / pyscript_pyparsing_arith_eval.html
Last active May 19, 2022
PyScript demo of a pyparsing arithmetic parser/evaluator
View pyscript_pyparsing_arith_eval.html
<html>
<head>
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
</head>
<body>
<table cellpadding=30 border=2>
<tr>
<td>
@ptmcg
ptmcg / pyparsing_diagram.html
Last active May 28, 2022
PyScript runs pyparsing code to generate railroad diagram
View pyparsing_diagram.html
<html>
<head>
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
<py-env>
- pyparsing==3.0.9
- railroad-diagrams
- jinja2
</py-env>
<py-script>
@ptmcg
ptmcg / computer_thinking_spinners.py
Last active Mar 1, 2022
Rich spinners for "the computer is thinking"
View computer_thinking_spinners.py
import rich.progress
import rich.spinner
import time
import random
class RandomChars(rich.progress.ProgressColumn):
"""Simulation of computer 'thinking' by displaying random characters
Args:
chars (str): characters from which to choose for display. Defaults to 0-9A-F.
@ptmcg
ptmcg / mixed_type_hello.py
Last active Feb 13, 2022
Hello, World rendered in a variety of Unicode characters
View mixed_type_hello.py
def 𝚑𝓮𝖑𝒍𝑜():
try:
𝔥e𝗅𝕝𝚘︴ = "Hello"
𝕨𝔬r𝓵ᵈ﹎ = "World"
ᵖ𝖗𝐢𝘯𝓽(f"{𝗵e𝓵𝔩º_}, {𝖜ₒ𝒓lⅆ︴}!")
except 𝓣𝕪ᵖe𝖤𝗿ᵣ𝖔𝚛 as ⅇ𝗑c:
𝒑rℹₙₜ("failed: {}".𝕗𝗼ʳᵐªt(ᵉ𝐱𝓬))
# snippet from unittest/util.py
View bmp.py
"""
bmp.py - module for constructing simple BMP graphics files
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
View strict_generator.py
#
# THE PROBLEM
#
# create a generator and list out its items
a = (n**2 for n in range(10))
print(list(a))
# listing it out again creates an empty list because the generator has been consumed;
# generators in this state will continue to raise StopIteration, but caller will take