Skip to content

Instantly share code, notes, and snippets.

@PM2Ring
PM2Ring / acot_triangle.svg
Created December 4, 2017 11:29
Show that arccot(2)+arccot(3)=arccot(1)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@PM2Ring
PM2Ring / cbg-printer0.rle
Created November 22, 2017 12:11
Game of Life "cbg" printer in RLE format
x = 632, y = 391, rule = B3/S23
265b2o$265bo$257b2o3b2obo$256bo3bo3bo$240b2o13bo$240b2o13bo3bo2bo$231b
2o3bo6b2o10bo5bo$231bobo3bo5b3o10bo3bo4b2o12b2o$232b5o6b2o12b2o6bo13b
2o$233b3o4b2o9bobo9bobo$240b2o10b2o9b2o$252bo24bo$259b2o17bo$258bobo
17bo$260bo2$276b2o3b2o51b2o$279bo54bo$248bo27bo5bo40b2o7bobo$248b2o5b
2o20b2ob2o41bobo6b2o$247bobo5b2o21bobo30bo12b3o$279bo28b4o3b2o8b3o$
279bo20b2o5b4o3b2o8b3o$300b2o5bo2bo3b2obob2o2bobo8b2o12b2o$307b4o4bobo
b2o2b2o9bo13b2o$308b4o3bob2o13bobo$240b2o69bo20b2o$241b2o$240bo34bobo$
275b2o70b3o$276bo3b3o39b2o2b2o19b3o$266b2o11bo3bo37bo3b2o19bo3bo$266b
2o10bo5bo37b2obo77b2o$233bo44b2obob2o60b2o3b2o51bo$233b2o159b2o5bobo$
@PM2Ring
PM2Ring / circular_shift.py
Created October 31, 2017 17:20
Detect if a list is a circular permutation of a given list
#!/usr/bin/env python3
''' Detect if a list is a circular permutation of a given list
Written by PM 2Ring 2017.11.01
'''
from random import seed, randrange
seed(42)
@PM2Ring
PM2Ring / circles.py
Created October 26, 2017 15:19
Apollonian gasket in GTK2+
#! /usr/bin/env python
''' Draw an Apollonian gasket. Non symmetrical version.
Recursively solves Descartes Theorem to find the circles tangent
to 3 circles that are tangent to each other.
Written by PM 2Ring 2008.09.14
'''
import sys, colorsys
@PM2Ring
PM2Ring / combosums.py
Last active October 15, 2017 03:07
Find combinations of integers from 3 lists that sum to the items in a target list
#!/usr/bin/env python3
''' Find combinations of integers from 3 lists that sum to the items in a target list
https://gist.github.com/PM2Ring/f051ab09f9074ab5a378fa30f4141352
Written by PM 2Ring 2017.10.15
'''
from itertools import product
@PM2Ring
PM2Ring / xor_bytes_speed_tests.py
Last active October 8, 2017 18:11
Test speeds of performing XOR on two bytes strings of equal length
#! /usr/bin/env python3
''' Test speeds of performing XOR on two bytes strings of equal length
Typical results on a 32bit 2GHz machine running Python 3.6.0 on Linux
Size: 2 Loops: 65536
Verify True
xor_bytes_I : [0.36799076000170317, 0.3949565820003045, 0.40133740400051465]
xor_bytes_BLC : [0.41839819899905706, 0.4583157610031776, 0.4664555540002766]
@PM2Ring
PM2Ring / aes_ecb.py
Last active January 16, 2018 13:51
Call the AES_set_encrypt_key, AES_set_decrypt_key, and AES_ecb_encrypt functions from the OpenSSL library using ctypes
#!/usr/bin/env python3
''' AES ECB
Call the AES_set_encrypt_key, AES_set_decrypt_key, and
AES_ecb_encrypt functions from the OpenSSL library
Uses info from /usr/include/openssl/aes.h
Also see https://boringssl.googlesource.com/boringssl/+/2490/include/openssl/aes.h
@PM2Ring
PM2Ring / sha1_demo.py
Created October 4, 2017 16:36
An implementation of SHA-1 in pure Python 3
#!/usr/bin/env python3
''' sha1_demo
An implementation of SHA-1 in pure Python 3
Built from the pseudocode at
https://en.wikipedia.org/wiki/SHA-1#SHA-1_pseudocode
Written by PM 2Ring 2017.10.01
@PM2Ring
PM2Ring / bloom_filter_test.py
Created October 2, 2017 17:13
Bloom filter demo
#!/usr/bin/env python3
''' Testing a Bloom filter implementation
See https://en.wikipedia.org/wiki/Bloom_filter
Written by PM 2Ring 2017.09.29
'''
from random import seed, randrange
@PM2Ring
PM2Ring / tk_iso_ellipse0.py
Created October 2, 2017 12:27
Fitting an ellipse into an isoceles triangle
#! /usr/bin/env python3
''' iso_ellipse. An ellipse that touches an isoceles triangle at the
midpoint of its base and at a given distance on the sides.
The apex of the triangle is at the origin, with the triangle's axis
on the +X axis. The slopes of the equal sides are m and -m,
the "height" is V, so the other 2 vertices are at (V, mV) and (V, -mV).
We want an ellipse that's tangential to the triangle at (X, Y) and (X, -Y)