Skip to content

Instantly share code, notes, and snippets.

View Hermann-SW's full-sized avatar

Hermann Stamm-Wilbrandt Hermann-SW

View GitHub Profile
@Hermann-SW
Hermann-SW / wol.js
Created July 14, 2023 10:13
minimal nodejs code to power on wakeonlan enabled PC with given mac address
// eslinted; send wakeonlan magic packet for mac address defined in m
//
const m = Buffer.from([0x9c, 0x6b, 0x00, 0x15, 0xbd, 0xc2]);
const p = Buffer.concat([Buffer.alloc(6,0xff),m,m,m,m,m,m,m,m,m,m,m,m,m,m,m,m]);
const sock = require('dgram').createSocket('udp4').on('listening', function() {
sock.setBroadcast(true);
sock.send(p, 0, p.length, 9, '255.255.255.255', function() {
sock.close();
});
@Hermann-SW
Hermann-SW / latest_new_primes
Created June 19, 2023 07:50
shows difference for "list of largest 5000 primes"
#!/bin/bash
wget -O /tmp/all.txt https://t5k.org/primes/lists/all.txt 2> /dev/null
if [ ! -f t5k.org_primes_lists_all.txt ]
then
echo "initial download of largest primes list"
cp /tmp/all.txt t5k.org_primes_lists_all.txt
fi
if [ ! -f t5k.org_primes_lists_all.txt.old ]
@Hermann-SW
Hermann-SW / sqrtm1.smallest_known_1million_digit_prime.cc
Created June 19, 2023 00:10
Only here to investigate "munmap_chunk(): invalid pointer"
This file has been truncated, but you can view the full file.
// x,y -> sqrtm1 [-> x,y]
//
// https://t5k.org/primes/lists/all.txt
// 2147 10^999999+308267*10^292000+1 1000000 CH10 2021
//
// f=sqrtm1.smallest_known_1million_digit_prime
//
// either
// g++ $f.cc -lgmp -lgmpxx -O3 -o $f
// or
@Hermann-SW
Hermann-SW / cypari2_.py
Last active June 14, 2023 09:59
Python script for testing making use of cypari2 if available
from sympy import gcd, I
try:
import cypari2
pari = cypari2.Pari()
gen_to_python = cypari2.convert.gen_to_python
except ImportError:
cypari2 = None
@Hermann-SW
Hermann-SW / phi_e_pi.py
Created June 3, 2023 13:39
Determinine percentages of "is_prime(f_x(p))" with "f_x(p) = round_to_odd(p * x)"
# pylint:disable=C0103, C0114, C0116, W0611
from math import sqrt, floor, pi, e
from sympy import nextprime, isprime
def digits(n):
return len(str(n))
phi = (sqrt(5) + 1) / 2
@Hermann-SW
Hermann-SW / sq2.gp
Last active June 2, 2023 19:48
1st Pari/GP experience, determine sum of squares for prime p = 1 (mod 4), implement "assert()"
\\ sq2(p) determines sum of squares for prime p = 1 (mod 4), implement "assert()"
\\
\\ based on
\\ - https://pari.math.u-bordeaux.fr/Events/PARI2019b/talks/init.pdf
\\ - https://pari.math.u-bordeaux.fr/Events/PARI2019b/talks/prog.pdf
\\ - https://pari.math.u-bordeaux.fr/pub/pari/manuals/2.15.1/tutorial.pdf
\\ - https://skalatan.de/en/archive/pariguide/doc/Programming_under_GP.html
\\ - https://home.gwu.edu/~maxal/gpscripts/binomod.gp
\\
assert(b, v, s) = { if(!(b), error(Str(v) Str(s))); }
@Hermann-SW
Hermann-SW / cython_demo
Created May 29, 2023 18:36
Short demo of using Cython, setting language_level, compare runtimes, ...
#!/bin/bash
pip install setuptools Cython gmpy2
rm -rf /tmp/tst && mkdir /tmp/tst && cd /tmp/tst
wget -q https://gist.githubusercontent.com/Hermann-SW/061d33b47325bd15a4033b33d3f7c4c9/raw/9900616d98b6acdd50c436d9ae914a1c5d81f2b2/sq2_cg.py
mv sq2_cg.py sq2_cg.pyx
cat << EOF > setup.py
from setuptools import setup
stateDiagram
    [*] --> Still
    Still --> [*]

    Still --> Moving
    Moving --> Still
    Moving --> Crash
    Crash --> [*]
@Hermann-SW
Hermann-SW / 36401.py
Created May 17, 2023 23:47
verification of sum of squares for 36401-digit palindromic prime
"""
sq2_sympy.py from here (plus time print() in "sq2()"):
https://github.com/sympy/sympy/issues/15358#issuecomment-1551635777
2.5GHz i7-11850H
1998.6601960659027s a = sqrt(-1) (mod p)
2011.4160270690918s x, y = gcd(p, a + I).as_real_imag()
"""
from math import log10
@Hermann-SW
Hermann-SW / sq2_cg.py
Last active May 12, 2023 09:06
determine sum of squares for 2467-digit prime, simplified for pycg callgraph analysis (manually transformed to Graphviz)
# pylint: disable=C0103
# invalid-name
"""
determine sum of squares for 2467-digit prime
- minimized for pycg analysis
- original: https://github.com/Hermann-SW/RSA_numbers_factored/blob/main/python/sq2.py
- manually converted to Graphviz with splines=ortho
- shortened GraphvizFiddle Share link: https://stamm-wilbrandt.de/sq2_cg.py.gvf.html
"""
from time import time