Skip to content

Instantly share code, notes, and snippets.

Stephan Boyer stepchowfun

Block or report user

Report or block stepchowfun

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@stepchowfun
stepchowfun / bullet.c
Created Apr 24, 2012
Source code for the self-balancing unicycle described at: http://www.stephanboyer.com/post/17
View bullet.c
#define F_CPU 20000000
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <stdio.h>
#include <math.h>
/*
-----------------------
Self-Balancing Unicycle
@stepchowfun
stepchowfun / finite_automaton.h
Created Oct 18, 2012
This header declares structures and interfaces for manipulating finite automata, both deterministic and nondeterministic.
View finite_automaton.h
/*
This header declares structures and interfaces for manipulating finite automata,
both deterministic and nondeterministic.
The code is written in a portable subset of C++11. The only C++11 features used
are std::unordered_map and std::unordered_set, which easily can be replaced with
the (less-efficient) C++03 equivalents: std::map and std::set.
*/
#ifndef FINITE_AUTOMATON_H
@stepchowfun
stepchowfun / merger.py
Last active Aug 10, 2019
My three-way merge algorithm, originally designed for 6.033 DP2.
View merger.py
#!/usr/bin/python -O
################################################################################
################################################################################
#
# State-Based Text Merging Algorithm
# For 6.033 Design Project 2
# TA: Katherine Fang
# 9 May 2012
#
View grid.min.css
.container{width:100%;max-width:1210px;padding-left:20px;padding-right:20px;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;margin-left:auto;margin-right:auto}.row{*zoom:1}.row:before,.row:after{display:table;content:""}.row:after{clear:both}@media(max-width:767px){.row:after{clear:none}}.span1{float:left;*zoom:1}.span1:before,.span1:after{display:table;content:""}.span1:after{clear:both}@media(max-width:767px){.span1{margin-top:inherit;margin-bottom:inherit;float:none}.span1:first-child{margin-top:0}.span1:last-child{margin-bottom:0}.span1:after{clear:none}}.span2{float:left;*zoom:1}.span2:before,.span2:after{display:table;content:""}.span2:after{clear:both}@media(max-width:767px){.span2{margin-top:inherit;margin-bottom:inherit;float:none}.span2:first-child{margin-top:0}.span2:last-child{margin-bottom:0}.span2:after{clear:none}}.span3{float:left;*zoom:1}.span3:before,.span3:after{display:table;content:""}.span3:after{clear:both}@media(max-width:767px){.span3{margin-top:inherit;
@stepchowfun
stepchowfun / domain_finder.py
Last active Dec 29, 2018
Generates domain names according to a Markov chain trained on the English dictionary and checks their availability.
View domain_finder.py
#!/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])]
@stepchowfun
stepchowfun / kselect.py
Last active Feb 1, 2017
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
#!/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
View hashpass.py
#!/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]
@stepchowfun
stepchowfun / elementizer.hs
Last active May 18, 2018
Decompose a string into elements!
View elementizer.hs
-- 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"
View gigantic-proof-goal
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
@stepchowfun
stepchowfun / factorial.js
Created Mar 11, 2019
The factorial function implemented in the lambda calculus
View factorial.js
// 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) {
You can’t perform that action at this time.