Skip to content

Instantly share code, notes, and snippets.

View lynn's full-sized avatar
🐞

Lynn lynn

🐞
View GitHub Profile
@lynn
lynn / tweetsprint.des
Created January 29, 2017 14:59
tweetsprint
NAME:🏃
TAGS:sprint
MONS:orc,urug,mara
ITEM:orb of zot,random rune
ORIENT:encompass
MAP
bbbbbbbbb|1b
beld=3=2=11=|||{
bbbbbbbbb|1b
ENDMAP
@lynn
lynn / Turing.hs
Last active April 15, 2017 20:41 — forked from nandor/Turing.hs
Haskell Turing Machine
import Data.Map(Map, fromList, lookup, union)
import Control.Monad(msum)
fromMay d = (!!0) . foldr (:) [d]
mapIns :: (Ord k) => k -> a -> Map k a -> Map k a
mapIns k a = union (fromList [(k, a)])
-- | A TM to add 1 to a binary natural.
incr :: (Int, [Int], [(Int, Int, Char, Char, Int)])
@lynn
lynn / twitter-gradient.py
Created May 30, 2017 19:34
Update your Twitter profile color in a day-night gradient cycle
from datetime import datetime, timedelta
from PIL import Image
import twitter
def clock_fraction():
'Return time since midnight rescaled to [0, 1); e.g. 0.5 is noon.'
now = datetime.now()
midnight = now.replace(hour=0, minute=0, second=0, microsecond=0)
return (now - midnight) / timedelta(days=1)
@lynn
lynn / prime5.v
Created June 1, 2017 16:37
Proof that 5 is prime
Require Arith.
Require Le.
Inductive Divides k : nat -> Prop :=
| Divides_base : Divides k 0
| Divides_step : forall n, Divides k n -> Divides k (k+n).
Definition Prime (p : nat) : Prop :=
forall k, Divides k p -> (k = 1 \/ k = p).
@lynn
lynn / yuyugrep.sh
Created August 22, 2017 15:09
Grep my Yuyushiki subtitles
function yuyugrep {
yuzucol="\x1b[38;5;213m"
yukacol="\x1b[38;5;93m"
yuicol="\x1b[38;5;221m"
chihocol="\x1b[38;5;180m"
fumicol="\x1b[38;5;35m"
keicol="\x1b[38;5;130m"
momcol="\x1b[38;5;38m"
ncol="\x1b[0m"
grep --ignore-case --color=always $* \
@lynn
lynn / miscellany.v
Created October 7, 2017 15:19
Old Coq proofs from my hard drive
(* CanHalveEven.v *)
Inductive Even : nat -> Prop :=
| Even_base : Even 0
| Even_step : forall n, Even n -> Even (S (S n)).
Check Even_ind.
Theorem can_halve_even :
forall n, Even n -> (exists k, k + k = n).
@lynn
lynn / followers-graph.py
Last active October 18, 2017 00:11
Generate Twitter followers graph from webarchive crawl data
#!/usr/bin/env python3
# Example:
#
# % python3 followers-graph.py 0xlynn chordbug
# 2017/04/21 224
# 2017/04/22 238
# 2017/04/27 288
# 2017/05/07 328
# 2017/05/08 329
@lynn
lynn / bf.ni
Last active November 30, 2017 12:53
brainfuck interpreter in Inform 7
"Brainfuck Interpreter" by "Lynn"
[ Such language in a high-class establishment like this! ]
Chapter 1 - Implementation
[ These inputs are queried before execution starts: ]
The code is a text that varies.
The program input is a text that varies.
[ These global values describe the state of our machine: ]
@lynn
lynn / quadrics.nb
Created December 7, 2017 18:19
Mathematica quadric normalizer
K := 5 x^2 + 4 x y + 2 y^2 + 2 x - 4 y + 3 (* Input quadric *)
X := Variables[K]; n := Length[X]
(* Mathematica's Coefficient[3x+2xy,x] gets us 3+2y. We just want the free term, 3. *)
FreeTerm[p_] := p /. Map[# -> 0 &, X] (* p with all variables substituted by 0 *)
Co[m_] := FreeTerm[Coefficient[K, m]] (* So Co[x^2] is 5, Co[y] is -4... *)
A := Table[Co[X[[i]] * X[[j]]] / If[i==j, 1, 2], {i, 1, n}, {j, 1, n}]
B := Table[Co[X[[i]]], {i, 1, n}]
@lynn
lynn / random-rhymes.py
Last active January 7, 2018 21:09
Turn English text into nonsense that sounds like the input
from collections import defaultdict
import fileinput
import random
import re
common = """the of and to a in for is on that by this with
i you it not or be are from at as your all have an was we
will can us i'm it you're i've my of""".split()
pronounce = {}