Skip to content

Instantly share code, notes, and snippets.

@mnp
mnp / gist:c137004a5a5fbd90ffbe0dd007b43be9
Created June 21, 2023 12:47
Karl Popper, Paradox of Tolerance
https://en.wikipedia.org/wiki/Paradox_of_tolerance
@mnp
mnp / gist:1f9f15955a6d83dee92fd098ccd901d9
Created June 29, 2022 17:32
Dead Trigger Puzzle from 2013
Solution to an old puzzle. The puzzle text:
02201010121021210121111011020201012110221021
21020201012102221020211111110210101211010102
10010120211210202101211102210212010121012111
00210201010121101010210010120220010121102011
02021102101201010120211210121111110101202112
01012020210101201212012100121101212012110121
20121201211
(intern ":fact")
(intern ":expt")
(defun sp/fact (n) ; n!
(if (> n 1)
(* n (sp/fact (- n 1)))
1))
(defun sp/term(op &rest rest)
(cond ((eq op :fact) (cons 'sp/fact rest)) ; a!
@mnp
mnp / no-div-fizzbuzz.py
Created October 29, 2021 17:39
No-div fizzbuzz
i=0
j=3
k=5
while i<40:
if j==0 and k==0:
print(f'{i} fizzbuzz')
j=2
k=4
elif j==0:
print(f'{i} fizz')
@mnp
mnp / twin-twin.py
Last active August 12, 2021 13:50
Find cases where twin primes lead to more twin primes
#!/usr/bin/env python3
# see https://old.reddit.com/r/mathematics/comments/p2wv1a/twin_primes_square_distances/
def find_prime_pairs(n):
sieve = [True] * n
if n > 0:
sieve[0] = False
if n > 1:
sieve[1] = False
for number in range(2, int(n ** 0.5) + 1):
@mnp
mnp / calc-data-units.el
Created October 11, 2020 00:39
Data units for Emacs Calc
;;
;; I'm not sure why these aren't part of `math-standard-units`.
;; Source: https://en.wikipedia.org/wiki/Mebibyte
;;
(setq math-additional-units '(
;; Base units. Note "b" is Barns in math-standard-units, while convention "B" is Bytes, so
;; there's no conflict.
(bits nil "bits")
(B "8 * bits" "Bytes")
@mnp
mnp / url-play.el
Created May 26, 2020 15:16
emacs url experiments
;; ---- Asynchronous -----
(defun retrieve-handler (status)
(message "callback %s with %s chars" status (buffer-size))
(setq got status))
(condition-case x (url-retrieve "http://ahsdjfas" #'retrieve-handler) (t (message "handle %s" x)))
"handle (error ahsdjfas/80 nodename nor servname provided, or not known)"
(condition-case x (url-retrieve "http:ahsdjfas" #'retrieve-handler) (t (message "handle %s" x)))
@mnp
mnp / gist:39031ecce03b948a5617a815461fd431
Last active October 11, 2018 12:40
chesco volunteer opportunities
www.wcupa.edu/volunteer
http://chestercountyfoodbank.volunteerhub.com Chester County Food Bank
http://safeharborofgwc.org Safe Harbor homeless shelter
https://bvspca.org Brandywine Valley SPCA
http://hfhcc.org/ Habitat for Humanity They're mostly working near Downingtown
https://www.indivisiblechesco.org Indivisible Chester County (This one's political).
https://www.all4pawsrescue.com/volunteer All Four Paws
http://www.lamanchaanimalrescue.org La Mancha rescue
http://chescolibraries.org/volunteer-fair
@mnp
mnp / fibs.el
Last active April 5, 2018 19:55
Elisp Fibs
;; g'bye stack
(let ()
(defun f (n)
(if (< n 2) 1
(+ (f (- n 1)) (f (- n 2)))))
(loop for i from 0 upto 20
collect (f i))
)
@mnp
mnp / gist:ff0b957d2ff13e03dcd19849e956727e
Created April 28, 2017 20:28
PERF dump for Consul issue driving high cpu
# Samples: 21K of event 'cpu-clock'
# Event count (approx.): 5466750000
#
# Children Self Command Shared Object Symbol
# ........ ........ ....... ................. ...................................................................................................................................................................
#
96.75% 0.00% consul consul [.] runtime.goexit
|
---runtime.goexit
|