Skip to content

Instantly share code, notes, and snippets.

View gulan's full-sized avatar

Glen Wilder gulan

  • Santa Clara, CA
View GitHub Profile
#!/usr/bin/env python
"""
More TLA+ inspired coding. Using an explict step() that takes the
current state to the next state makes loop invarients easier to think
about.
"""
def str2int(s):
#!/usr/bin/env python
"""
Exercises with abstract state machines.
My remote goal is to learn how to specify systems using TLA+. I begin
by writing some simple programs is the style of those kinds of
specifications.
Any basic operator maps a before-state to an after-state. The operator

Knowledge Representation

Say that red is a relation and b is an individual.

Is b red?

red(b).

What is red?

"""
Arrange a program as a dictionary where the keys are program labels
and the bodies are python code. The idea is to let python do
computation, but let me define flow-control and means of program
composition.
This is a simple program, so I stick to simple Python.
"""
from collections import namedtuple
-- from https://en.wikipedia.org/wiki/List_of_elements
-- sqlite3 periodic.db <periodic.sql
drop table if exists element;
create table element (
number int primary key,
symbol text not null,
name text not null,
period int not null,
weight number not null);
#!/usr/bin/env python
import fcntl
import os
import random
import sqlite3
import sys
import termios
"""
@gulan
gulan / card.sql
Created September 11, 2015 03:42
-- The old HSK1 words. For sqlite3.
BEGIN TRANSACTION;
CREATE TABLE hsk (
hsk_id integer primary key,
chinese text not null,
pinyin text not null,
english text not null);
#!/usr/bin/env python
import sys
"""
This program demonstrates how to recognize and deal with backtracking
while processing sequential files or sequences.
A file is a sequence of runs. A run is any number of 'a', 'b' or 'x',
ending with '\n'. The file ends with a special value eof.
#!/usr/bin/env python
"""
Convert an 'elide' file to a flashy card file.
A subject.elide file has entries of the form:
answer
question
question
module OffsetOp where
import Data.List
-- The function condense takes a list of pairs. The second value of
-- each pair denotes either a delete or skip action. The delete action
-- says that the next item in the list is to be discarded, and will
-- not appear in the result list. Skip actions do nothing.
-- 1-skip 2-del 3-skip -> 1-skip 2-del