Skip to content

Instantly share code, notes, and snippets.

@tangentstorm
tangentstorm / thingmail.py
Created April 2, 2013 18:22
an old, experimental email system in python ... uses the cmd unit to create a shell and curses for interaction
#!/usr/bin/python2.5
import handy
import sys, os
import mailbox
import sqlite3
from email.utils import parseaddr, parsedate_tz, mktime_tz, formatdate
import cmd
import pdb
from cursor import Cursor, ListView
from storage import PySQLiteStorage
@tangentstorm
tangentstorm / risc.pas
Created April 9, 2013 14:47
RISC virtual machine by Niklaus Wirth from his book, Compiler Construction. (This is actually oberon, not pascal, but github doesn't highlight oberon)
MODULE RISC; (* NW 22.9.07 / 28.3.11 *)
IMPORT SYSTEM, Texts, Oberon;
CONST
MemSize = 1024; (* in words *)
MOV = 0; AND = 1; IOR = 2; XOR = 3; LSL = 4; ASR = 5;
ADD = 8; SUB = 9; MUL = 10; Div = 11; CMP = 12;
@tangentstorm
tangentstorm / blockdown.as
Created April 12, 2013 05:01
ancient actionscript 2 code for blockdown (tetris clone)... this is just the main game logic. the game is playable at http://www.kongregate.com/games/tangentstorm/blockdown
// == declarations ==========================================
var level:Number = 0;
var score:Number = 0;
var cleared:Number = 0; // number of lines cleared
var justDropped:Boolean = false; // did they just force a drop? (Enter key)
var board:MovieClip;
var EMPTY:Number = -1;
#!/usr/bin/env perl6
=comment
Universal forth-style tokenizer (breaks on whitespace)
=cut
grammar Grammar {
token TOP { [ <whitespace> | <blackspace> ]+ }
token whitespace { \s+ }
token blackspace { $<token>=[\S+] }
}
grammar CorePascal;
parse : module ;
//--- parser -------------------------------------
module
: modHeader
block '.'
;
@tangentstorm
tangentstorm / output.pas
Created April 23, 2013 06:55
Ugly python + xpath code to translate the UML digaram for gamesketchlib to pascal. see http://i.imgur.com/LZtWxH7.png for the diagram.
type
IGridMember = interface
end;
IInteractive = interface
procedure click( mx, my : int );
procedure press( mx, my : int );
procedure drag( mx, my : int );
end;
IPlayable = interface
@tangentstorm
tangentstorm / grin.pas
Last active December 16, 2015 18:21
pascal's syntax described in a hypothetical metagramar
{ this is pascal code to scan the metagrammar.
unfinished and untested... probably won't even compile }
unit grinlex;
interface
type
TGrinKind = ( tkTokenSigil, tkRuleSigil, tkComment, tkNeck, tkEnd
tkChar, tkEnd, tkTo, tkOr, TkString, tkIden,
@tangentstorm
tangentstorm / peano-proof.txt
Last active December 16, 2015 20:48
a semi-formal proof about peano numbers, for illustration purposes
GIVEN
data N = Z | S N; -- call this N:0 (peano representation of natural numbers)
add Z y = y -- call this add:1
add x Z = x -- call this add:2
add x (S y) = add (S x) y -- call this add:3
PROVE
add x (S y) = S add (x y) -- for all x, y : N
BEGIN
@tangentstorm
tangentstorm / ltbios.txt
Last active December 16, 2015 20:59
ltbios example run : (p)rint the (empty) board, (g)ive a new board, (p)rint it back, and (q)uit
> p
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
@tangentstorm
tangentstorm / product.sql
Created May 16, 2013 23:43
relational division
create table a (x integer);
create table b (y integer);
insert into a values (1);
insert into a values (2);
insert into b values (1);
insert into b values (2);
insert into b values (3);
select * from a,b;