Skip to content

Instantly share code, notes, and snippets.

@tangentstorm
tangentstorm / likstromsnat.hs
Last active October 9, 2015 02:08
a little electronics problem
{-
| a dumb little circuit simulator in haskell
| by tangentstorm, 2012/08/22
|
| This basically just calculates values using Ohm's law.
| it (probably?) only works for simple circuits where there
| is a single path from the power source to each node, and
| from each node back to the power source.
|
| many thanks to quicksilver and Axman6 on #haskell for advice
@tangentstorm
tangentstorm / gist:3814556
Created October 1, 2012 21:30
python generator example
"""
This program generates the following table:
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F
30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F
40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F
50 51 52 53 54 55 56 57 58 59 5A 5B 5C 5D 5E 5F
60 61 62 63 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F
@tangentstorm
tangentstorm / gist:3814598
Created October 1, 2012 21:37
when generators share their state
"""
This program generates the following table:
01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
It shows what happens when two generators share the same state.
Contrast with: https://gist.github.com/3814556
"""
@tangentstorm
tangentstorm / gist:4045219
Created November 9, 2012 11:22
imap regexp example for timg
>>> import re
>>> data = ['2 (X-GM-THRID 1391221299548167514 X-GM-MSGID 1391221299548167514 UID 6)']
>>> re.search('X-GM-THRID (?P<X_GM_THRID>\d+) X-GM-MSGID (?P<X_GM_MSGID>\d+)', data[0]).groupdict()
{'X_GM_THRID': '1391221299548167514', 'X_GM_MSGID': '1391221299548167514'}
@tangentstorm
tangentstorm / refs.pas
Created November 15, 2012 15:28
freepascal reference testing experiment
{ freepascal reference experiment
--------------------------------------------------------
Kaco_ / Phavel suggested the following problem
in #fpc on 11/15/2012:
layout2:tgui_layout;
layou1:=tgui_layout.init (..);
layout2:=layout1;
@tangentstorm
tangentstorm / caseclass.pas
Created November 22, 2012 05:08
structured unions with RECORD ... CASE in free pascal
{$mode objfpc}
unit caseclass;
interface uses classes;
type
kinds = ( kINT, kSYM, kSTR, kREF, kNUL, kOBJ );
RNode = record case kind : kinds of // valid pascal code
kINT : ( int : integer );
@tangentstorm
tangentstorm / gist:4224192
Created December 6, 2012 12:41
make clean cycle
michal@proton:~/ver/fpc/compiler$ make clean cycle
/bin/sh: Syntax error: "(" unexpected
/bin/rm -f ppcross ppc ppc1.exe ppc2.exe ppc3.exe ./msg2inc.exe pp1.wpo pp2.wpo
/bin/rm -f ppc386.exe ppc68k.exe ppcx64.exe ppcppc.exe ppcsparc.exe ppcppc64.exe ppcarm.exe ppcmips.exe ppcmipsel.exe ppcjvm.exe ppc.exe ppcwpo1.exe ppcwpo2.exe
/bin/rm -rf units
/bin/rm -f *.o *.ppu *.rst *.s *.a *.so *.ppl
/bin/rm -rf *.sl
/bin/rm -f fpcmade.* Package.fpc ppas.sh script.res link.res
/bin/rm -f *_ppas.bat
make tempclean ppc3.exe
$ cat system.pas
unit system;
interface
procedure test;
implementation
procedure test;
var t: longint;
begin
begin t:=1; end;
@tangentstorm
tangentstorm / compiled code running in retro
Created December 10, 2012 02:15
pl/0 to retro compiler
Retro 11.5
ok ( ---------------------------------- )
ok ( runtime library )
ok ( ---------------------------------- )
ok : odd? mod 2 1 = ;
ok ( ---------------------------------- )
ok ( generated code )
ok ( ---------------------------------- )
ok variables| i |
@tangentstorm
tangentstorm / gist:4250692
Created December 10, 2012 13:56
floating point exception in retro.c
michal@proton:~/vrx$ ./retro --with recurse.rx
Retro 11.5
ok ( ---------------------------------- )
ok ( runtime library )
ok ( ---------------------------------- )
ok : odd? mod 2 1 = ;
ok ( ---------------------------------- )
ok ( generated code )
ok ( ---------------------------------- )