Skip to content

Instantly share code, notes, and snippets.

View ptmcg's full-sized avatar

Paul McGuire ptmcg

View GitHub Profile
@ptmcg
ptmcg / corinthians_I.py
Last active April 2, 2021 08:19
Recreate popular verses on love from I Corinthians
#
# corinthians_I.py
#
# Class definitions to use when recreating I Corinthians 13:4-8 from
# the Python prompt.
#
# Copyright 2020, Paul McGuire
#
import sys
sys.excepthook = lambda *args: print(args[0].__name__)
@ptmcg
ptmcg / graph_algebra.py
Last active February 11, 2020 10:29
Graph algebra parser/evaluator
#
# graph_algebra.py
#
# A rough implementation of a graph algebra.
#
# References:
# https://statagroup.com/articles/an-algebra-for-graph-structures
# https://www.youtube.com/watch?v=EdQGLewU-8k
#
# Copyright 2020, Paul McGuire
@ptmcg
ptmcg / orbit_with_multi_dispatch.py
Last active November 16, 2019 17:57
classmethod to validate mix-and-match kwargs
"""
https://chat.stackoverflow.com/transcript/message/47865711#47865711
Well it's mainly "utility functions", ie I need to define a (keplerian) orbit. Which is normally done by giving
semi-major axis, eccentricity, inclination, argument periapsis and longitude ascending node. However there are lots
of "variations": ie for parabolic orbits the semi major axis is replaced by semi latus rectum. Or you can just use
state variables at a point (position + velocity in 3 dimensions). Or you could replace the semi major axis +
eccentricity by peri + apo apsis.
"""
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ptmcg
ptmcg / argparse_demo.py
Last active November 9, 2023 22:06
Demo of creating custom argument types for argparse (percent and Enum)
#
# argparse_demo.py
#
# Paul McGuire - April, 2019
#
# Presented as a lightning talk at PyTexas 2019
#
# Gist url: https://gist.github.com/ptmcg
#
import sys
@ptmcg
ptmcg / shuffled.py
Last active October 26, 2019 15:53
shuffled - one-line lambda to shuffle any sequence, not just shuffling lists in place
# shuffled.py - faster than random.shuffle, and will accept any sequence, not just indexables (like lists)
shuffled = lambda seq, rnd=random.random: sorted(seq, key=lambda _: rnd())
print(shuffled(range(20))