Skip to content

Instantly share code, notes, and snippets.

@lsparrish
lsparrish / bitzap.py
Last active November 4, 2015 06:13
simple bitoin-like program
#==========Bitzap: a tiny bitcoin-like program.==========#
# The goal is secure published transactions. Not yet completed.
# Install Notes:
# Uses dbdict, a recipe from: http://code.activestate.com/recipes/576642-persistent-dict-with-multiple-standard-file-format/
# On Ubuntu the Crypto library can be installed with "sudo apt-get install python-crypto"
# Details:
# Addresses are first 32 chars of a hash of the public key.
# Transaction IDs are first 32 chars of the buyer's signature.
# Receipts are lists of debits and credits that have been applied to each address.
# Buyer is sender, seller is receiver.
chain: struct'
: { ( -n ) 0 ;
: field ( nn"-n ) over ` : .data ` + ` ; + ;
: } ( n"- ) ` : .data ` here ` swap ` allot ` constant ` ; ;
: clone ( a-a ) here swap 3 + @ allot ;
;chain
with struct'
{
2 field .bar
1 field .baz
chain triggers'
{{
variable dict
: m dup 0 =if nip 0 ;then 2dup 1+ @ =if nip 2 + 0 ;then ;
: n here dict @ , dict ! , ;
: ? dict repeat @ m 0; again ;
---reveal---
: __? @ ? 0; .word ; parsing
: > compiler off 9 , key dup emit n 8 , , ; compile-only
: < here compiler on ;
chain: stacks'
{{
variable this
: stack ( -n ) this @ ;
---reveal---
: :| ( n- ) this ! ;
: |: ( "- ) create here dup :| , 100 allot ;
: \ ( n- ) stack ++ stack @ ! ;
: / ( -n ) stack @ stack -- @ ;
}}
( dict contains link to the most recent char word created. )
( m? is the interrupt detector for the lookup function. )
( l? is the lookup function. returns an xt or 0. )
( : starts a char definition. )
( ; calls a char definition. )
variable dict
: m? dup 0 =if nip -1 ( leave 0 on stack after interrupt ) ;then
2dup 1+ @ =if nip 2 + -1 ( leave xt on stack after interrupt );then ;
: l? dict repeat @ m? if; again ;
@lsparrish
lsparrish / test.c
Created September 15, 2010 00:40
playing around with c
#include <stdio.h>
char* listen();
int process();
int strcmp();
int output();
int main() {
char *str;
while (strcmp(str,"bye\n") != 0){
@lsparrish
lsparrish / gist:576359
Created September 12, 2010 19:30 — forked from crcx/gist:576343
chain: stringBuffer'
{{
tib variable: buffer
@buffer variable: pointer
: terminate ( - ) 0 @pointer ! ;
: bs? ( c-cf ) dup 8 = ;
: remove ( c- ) drop pointer -- @pointer @buffer <if @buffer !pointer then terminate ;
: add ( c- ) @pointer ! pointer ++ terminate ;
---reveal---
: addToBuffer ( c- ) bs? if remove else add then ;
@lsparrish
lsparrish / gist:576309
Created September 12, 2010 18:34 — forked from crcx/gist:576204
chain: stringBuffer'
{{
tib variable: buffer
@buffer variable: pointer
: terminate ( - ) 0 @pointer ! ;
---reveal---
: addToBuffer ( c- ) @pointer ! pointer ++ terminate ;
: getFromBuffer ( -c ) pointer -- @pointer @ terminate ;
: endOfBuffer ( -a ) repeat @pointer dup @ 0; 2drop pointer ++ again ;
: sizeOfBuffer ( -n ) @pointer @buffer - ;
@lsparrish
lsparrish / gist:575873
Created September 12, 2010 05:26 — forked from foucist/gist:575421
functional
with quotes'
( compare two strings from the beginning and return how many )
( similar characters there are before the strings diverge. )
: ^match ( $$-n )
0 -rot repeat @+ [ swap @+ ] dip =if rot 1+ -rot else 2drop ;then again ;
( test each word in the dictionary for similarity. if similar up )
( to the current point, add to the suggestions queue. )
create list here , 100 allot
with strings'
with quotes'
{
create str0 512 allot
create str1 512 allot
: NewCompare
[ toLower dup getLength 1+ str0 swap copy ] dip
toLower dup getLength 1+ str1 swap copy
str0 str1 default: compare ;