This file contains 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)) |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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. | |
""" |
This file contains 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 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 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
# rk.py | |
# | |
# Copyright 2020, Paul McGuire | |
# | |
from typing import Callable, Sequence | |
from array import array | |
class RKIntegrator: | |
""" |
This file contains 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
import time, sys, base64 | |
for i, v in enumerate((getattr, time, sys, "sleep", | |
"decode", "bytes", "stdout", | |
"write", "flush", 1.0, 6, | |
base64, "upper", 1000.0, "'", | |
print, 0), start=3): | |
vars()['_'*i] = v | |
_ = ( | |
b'RGFpc3kgRGFpc3kgZ2l2ZSBtZSB5b3VyIGFuc3dlciBk' | |
b'bwpJJ20gaGFsZiBjcmF6eSBhbGwgZm9y\nIHRoZSBsb3' |
This file contains 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
# | |
# 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|" |
This file contains 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
# | |
# rcu.py | |
# | |
# Paul McGuire - November, 2020 | |
# | |
from contextlib import contextmanager | |
import copy | |
import threading | |
This file contains 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__) |
OlderNewer