Skip to content

Instantly share code, notes, and snippets.

View ptmcg's full-sized avatar

Paul McGuire ptmcg

View GitHub Profile
@ptmcg
ptmcg / py_rac.py
Last active November 5, 2020 06:32
A python racter-like
#
# py_rac.py
#
# Copyright 2020, Paul McGuire
#
names = ("Voltaire|Samuel Johnson|Valery|Dante|"
"Nietzsche|Kant|Lao Tzu|Macchiavelli|Einstein|"
"Russell|Leonardo|Plato|Aristotle|Socrates|Diderot|"
"Descartes|Thomas Aquinas|Hawking|Emerson|Faulkner|"
@ptmcg
ptmcg / rcu.py
Last active November 19, 2020 05:39
RCU class for read-copy-update synchronization to a shared resource
#
# rcu.py
#
# Paul McGuire - November, 2020
#
from contextlib import contextmanager
import copy
import threading
#
# 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
@ptmcg
ptmcg / bmp.py
Last active August 29, 2021 23:19
"""
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:
@ptmcg
ptmcg / mixed_type_hello.py
Last active February 13, 2022 18:44
Hello, World rendered in a variety of Unicode characters
def ๐š‘๐“ฎ๐–‘๐’๐‘œ():
try:
๐”ฅe๐—…๐•๐š˜๏ธด = "Hello"
๐•จ๐”ฌr๐“ตแตˆ๏นŽ = "World"
แต–๐–—๐ข๐˜ฏ๐“ฝ(f"{๐—ต๏ฝ…๐“ต๐”ฉยบ_}, {๐–œโ‚’๐’“lโ…†๏ธด}!")
except ๐“ฃ๐•ชแต–๏ฝ…๐–ค๐—ฟแตฃ๐–”๐š› as โ…‡๐—‘c:
๐’‘rโ„นโ‚™โ‚œ("failed: {}".๐•—๐—ผสณแตยช๏ฝ”(แต‰๐ฑ๐“ฌ))
# snippet from unittest/util.py
@ptmcg
ptmcg / computer_thinking_spinners.py
Last active March 1, 2022 20:16
Rich spinners for "the computer is thinking"
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 / pyparsing_diagram.html
Last active May 28, 2022 03:07
PyScript runs pyparsing code to generate railroad diagram
<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 / pyscript_pyparsing_arith_eval.html
Last active May 19, 2022 21:36
PyScript demo of a pyparsing arithmetic parser/evaluator
<html>
<head>
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
</head>
<body>
<table cellpadding=30 border=2>
<tr>
<td>
@ptmcg
ptmcg / pyscript_littletable_iris.html
Last active May 19, 2022 03:28
Demonstration of CSV import using littletable in pyscript
<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 / plusminus_dice_roller_demo.html
Created June 1, 2022 23:07
Pyscript+plusminus Dice Roller
<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>