This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# simple JSON item accessor | |
# | |
import json | |
def json_accessor(fn): | |
def _inner(src, keypath, *args): | |
if not isinstance(keypath, (tuple, list)): | |
keypath = [keypath] | |
src_dict = json.loads(src) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 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__) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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. | |
""" |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# argparse_demo.py | |
# | |
# Paul McGuire - April, 2019 | |
# | |
# Presented as a lightning talk at PyTexas 2019 | |
# | |
# Gist url: https://gist.github.com/ptmcg | |
# | |
import sys |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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)) |
NewerOlder