Skip to content

Instantly share code, notes, and snippets.

@PM2Ring
PM2Ring / miller_rabin.py
Last active September 1, 2023 21:48
Deterministic Miller-Rabin primality test
""" Deterministic Miller-Rabin primality test
See https://en.m.wikipedia.org/wiki/Miller%E2%80%93Rabin_primality_test
and https://miller-rabin.appspot.com/
Written by PM 2Ring 2015.04.29
Updated 2022.04.20
"""
small_primes = [
@PM2Ring
PM2Ring / divisors_sieve.py
Created April 18, 2022 12:26
Find all divisors in a range by sieving
#!/usr/bin/env python3
''' Find all divisors in a range by sieving
Written by PM 2Ring 2017.05.03
Prime GP version
'''
from itertools import product
@PM2Ring
PM2Ring / julian_day.py
Created March 6, 2022 08:13
Julian Day Number conversion, Gregorian & Julian
""" Julian day number to date conversion
Proleptic Gregorian and Julian, with Astronomical years
i.e., 1 AD = year 1, 1 BC = year 0, 2 BC = year -1, etc
Derived from RG Tantzen (1963), ACM.
Algorithm 199: conversions between calendar date and Julian day number.
https://en.wikipedia.org/wiki/Julian_day
Julian day number 0 assigned to the day starting at noon on
January 1, 4713 BC, proleptic Julian calendar
@PM2Ring
PM2Ring / TriBounce.svg
Last active February 19, 2022 09:09
Bouncing around a triangular billiards table. SVG output.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@PM2Ring
PM2Ring / HorizonsBatch.py
Created January 21, 2022 03:45
Run Horizons batch file in Sage
""" Retrieve data from Horizons using a batch-file
Written by PM 2Ring 2021.12.27
"""
import re, requests
url = "https://ssd.jpl.nasa.gov/api/horizons_file.api"
pat = re.compile(r"(?:[^'\s]|'[^']*')+")
@interact
def go(batch=InputBox(width=40, height=24)):
if not batch: return
@PM2Ring
PM2Ring / MultiplicationDrill.html
Last active January 18, 2022 17:19
Simple multiplication drill app, in JavaScript
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Multiplication Drill</title>
</head>
<body>
<h3>Multiplication Drill</h3>
<input id="aLo" type="number" value="2"><label for="aLo">Low A</label><br>
@PM2Ring
PM2Ring / leap-seconds.py
Last active June 25, 2024 13:51
Parsing the leap-seconds.list file
# Fetch & parse leap-seconds.list
from datetime import datetime, timezone, timedelta
from hashlib import sha1
import requests
# Leap second data source
# url = 'https://www.ietf.org/timezones/data/leap-seconds.list'
url = 'https://raw.githubusercontent.com/eggert/tz/main/leap-seconds.list'
@PM2Ring
PM2Ring / ApollonianTriangle.svg
Last active May 24, 2025 19:54
Miscellaneous SVGs
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@PM2Ring
PM2Ring / SVGBezierToy.html
Created July 26, 2021 11:50
Basic Bezier curve, interactive
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>SVG Bézier</title>
<style id="mystyle">
circle {
stroke: #222;
stroke-width: 0.5;
stroke-opacity: 0.25;
@PM2Ring
PM2Ring / SunSSB.svg
Created July 18, 2021 13:56
Sun-SSB radial distance, 1945-1995
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.