Instantly share code, notes, and snippets.

# Stephan Boyer stepchowfun

Created March 26, 2019 16:54
View when.rs
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
 fn when< I: 'static + Send, F: 'static + Send + Future, R: 'static + Send, K: 'static + Send + Fn(&[I]) -> Option, >( futures: Vec, k: K, ) -> Box + Send> { fn when_rec<
Created March 11, 2019 01:43
The factorial function implemented in the lambda calculus
View factorial.js
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
 // In the lambda calculus, an expression must be one of the following: // 1) function(x) { return expression; } // 2) expression(expression) // 3) x // Pairs const pair = function(x) { return function(y) { return function(f) {
Last active December 12, 2017 02:54
View gigantic-proof-goal
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
 1 subgoal w, x, y, z : category oMap : w -> x fMap : forall x0 y : w, arrow w x0 y -> arrow x (oMap x0) (oMap y) fIdent : forall x0 : w, fMap x0 x0 (id w) = id x fComp : forall (x0 y z : w) (f : arrow w x0 y) (g : arrow w y z), compose x (fMap y z g) (fMap x0 y f) = fMap x0 z (compose w g f) oMap0 : x -> y fMap0 : forall x0 y0 : x, arrow x x0 y0 -> arrow y (oMap0 x0) (oMap0 y0) fIdent0 : forall x0 : x, fMap0 x0 x0 (id x) = id y
Last active May 18, 2018 04:23
Decompose a string into elements!
View elementizer.hs
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
 -- Usage: -- \$ ./elementizer esther -- Es Th Er import Data.Char (isLetter, toLower) import Data.Function.Memoize (memoFix) import Data.List (intercalate, isPrefixOf) import System.Environment (getArgs) elements = [ "H" , "He" , "Li" , "Be" , "B" , "C" , "N" , "O" , "F"
Created June 22, 2016 21:39
See https://github.com/boyers/hashpass for details.
View hashpass.py
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
 #!/usr/bin/python -O import base64, getpass, hashlib domain = raw_input('Domain: ').strip().lower() key = getpass.getpass('Key: ') bits = domain + '/' + key for i in range(2 ** 16): bits = hashlib.sha256(bits).digest() password = base64.b64encode(bits)[:16]
Last active February 1, 2017 21:38
Worst-case linear-time selection algorithm in Python. Note that in practice there are faster ways to find the k-th largest element in a list, even if this implementation is asymptotically faster.
View kselect.py
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
 #!/usr/bin/python -O # partition A[p:r] in place about x, and return the final position of the pivot def partition(A, p, r, x): # find the index of the pivot i = -1 for j in range(p, r): if A[j] == x: i = j break
Last active December 29, 2018 06:44
Generates domain names according to a Markov chain trained on the English dictionary and checks their availability.
View domain_finder.py
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
 #!/usr/bin/python -O from collections import defaultdict from random import random, choice from string import ascii_lowercase from subprocess import Popen, PIPE from time import time, sleep # get a list of words with only ASCII characters words = [w.strip().lower() for w in open("/usr/share/dict/words").readlines()] words = [w for w in words if all([c in ascii_lowercase for c in w])]
Last active December 28, 2015 21:40