grayscale visual one-time pads

2007-03-16 Thread Kragen Sitaker
A few years ago I reinvented Naor and Shamir's visual one-time pad system, although I didn't get all the way to their k-of-n secret sharing scheme. The interesting thing about this scheme is that it allows you to decrypt the image by placing the key on top of the ciphertext and looking at it --- n

Bloom filters and a simple spell checker in Python

2006-08-12 Thread Kragen Sitaker
I thought I'd try implementing a Bloom filter in Python, just for fun, since Python does have a nice abstraction for large bit vectors: the long int, or bignum. Turns out it's grossly inefficient to use a single long int for a Bloom filter because there's no way to set or clear bits in it. I wrot

irc bot for interacting with a triple store

2006-07-13 Thread Kragen Sitaker
This bot has a lot of bugs, but here it is: #!/usr/bin/python from __future__ import nested_scopes ### backward compatibility stuff if not globals().has_key('file'): file = open if not globals().has_key('True'): True = 1; False = 0 import sys sys.path.insert(0, '/home/kragen/lib/python') from t

improved JavaScript/DHTML RPN calculator/formula editor

2006-03-15 Thread Kragen Sitaker
Now it graphs. http://pobox.com/ragen/sw/js-calc.html Javascript/DHTML Reverse Polish Calculator #output div, input { padding: 1px; width: 60% } #output div { border: 1px solid lightslategrey; margin: 1px 0 } .instructions { float: right; width: 35%; color: darkslategrey; backgr

dimming LEDs without flicker

2006-03-09 Thread Kragen Sitaker
// Fading cellular automaton. Inspired by George Dyson's work showing // elementary-rule-110 executions on the IAS machine. Intended to run // on Limor Fried's minipov2 computer, in which the PORTB of an // ATtiny2313 is connected to 8 LEDs in a row, but will probably run // on any AVR microcontr

scheduling things by approval voting

2006-02-25 Thread Kragen Sitaker
I wanted to arrange a get-together among some of my busy friends, so I wrote this little program to help. If this were http://example.com/foo.cgi, you could send people links such as http://example.com/foo.cgi?who=brian, and then they can check the boxes to indicate what days they're available. D

Magnetic poetry in DHTML

2005-12-10 Thread Kragen Sitaker
Was pondering drag-and-drop, so I thought I'd put together a magnetic poetry kit in DHTML --- the simplest possible use of drag-and-drop. I took some time selecting words --- by hand, from the most common words in the British National Corpus, and from actual poetry --- and removing words I thought

YA directory tree browser (curses, Python)

2005-12-03 Thread Kragen Sitaker
#!/usr/bin/python """Yet another curses-based directory tree browser, in Python. I thought I could use something like this for filename entry, kind of like the old 4DOS 'select' command --- cd $(cursoutline.py). So you navigate and hit Enter, and it exits and spits out the file you're on. """ #

Condorcet winners in DHTML

2005-11-26 Thread Kragen Sitaker
I was thinking last night about how an election can fail to have a Condorcet winner, and I wondered what fraction of all possible elections had that property. Rather than spending half an hour looking up the answer on Google and reading it (finding e.g. http://arxiv.org/abs/math.ST/0511140 for thr

toy triple store sniki-like thing in DHTML with JavaScript

2005-11-19 Thread Kragen Sitaker
assert_equal(freevars([['a', 'b', 'C']]), ['C']) assert_equal(freevars([['A', 'B', 'C']]), ['A', 'B', 'C']) assert_equal(freevars([['A', 'A', 'A']]),

Browsing the OED by user-entered guidewords

2005-11-15 Thread Kragen Sitaker
x27;, 'require that you type in the guidewords you see on ', 'up to six pages before you get to the correct page: ', T.form(method='POST', action='page/1')[ T.input(name='q'

object-calculus pretty-printer and a little of a standard library

2005-10-15 Thread Kragen Sitaker
#!/usr/bin/python """Pretty-print object-calculus expressions with various bits of shorthand. In particular, elide 'self' names on method definitions that don't need them; use () instead of {}.'()' in ObjectDerivation expressions enclosed in a MethodCall(x, '()'); and elide 'arg1', 'arg2', etc., i

first hack at mvfs in Python (without cut and paste)

2005-06-25 Thread Kragen Sitaker
#!/usr/bin/python # Finite multi-mappings, like the stuff I wrote about "mvfs: # multivalued functions" in 2003, using + and * for (commutative, # associative) union and (non-commutative, associative) composition, # and supporting transitive closure. # This code only supports finite mvfs, and unl

FollowTail file-follow for Twisted Python (like tail -F)

2005-06-18 Thread Kragen Sitaker
#!/usr/bin/python # POE has a "FollowTail" wheel that works like tail -F --- if log # rotation renames the file, creates a new one under the original # name, and starts appending to it, it switches to watching the new # file. # This "followtail" module provides a way to do the same thing in # Twi

lazy evaluation in Python in a way that supports distributed operation

2005-06-11 Thread Kragen Sitaker
#!/usr/bin/python # Inspired by Mark S. Miller's whenUpdated and reactToUpdate protocol # described in # http://www.erights.org/javadoc/org/erights/e/elib/slot/EverReporter.html # and # http://www.erights.org/javadoc/org/erights/e/elib/slot/EverReactor.html # with the following differences: no gen

five-dimensional hypercube for Beatrice's birthday

2005-06-04 Thread Kragen Sitaker
# I wrote this on Beatrice's birthday, but didn't get around to posting # it until now. #!/usr/bin/python # 5-dimensional hypercube with 32 vertices for Bea's 32nd birthday # Written in Python with list-comprehensions and "sum"; works in # Python 2.3, might work in 2.2 import random, math def vec

sliding file windows over an mbox (for full-text indexing)

2005-04-23 Thread Kragen Sitaker
/* buf.c: copyright relinquished by Kragen Sitaker, sole author */ /* * My first mail-message-buffering strategy turned out fiendishly * complex. So I thought maybe I'd make a better design with a couple * of layers: one that doesn't know anything about messages and From_ * lines

Simple HTML chat demo with Twisted (Ajax push prototype)

2005-04-16 Thread Kragen Sitaker
#!/usr/bin/python # I wanted to play with Ajax Push with Twisted Python, so I thought # I'd start with the old standby: a chat app. The first step is to # see what happens when you hold a connection open for an arbitrarily # long time with Twisted Web: how do you tell when the connection # closes

JavaScript/DHTML RPN calculator/formula editor

2005-04-08 Thread Kragen Sitaker
http://pobox.com/~kragen/sw/js-calc.html Javascript/DHTML Reverse Polish Calculator #output div, input { padding: 1px; width: 60% } #output div { border: 1px solid lightslategrey; margin: 1px 0 } .instructions { float: right; width: 35%; color: darkslategrey; background-color: wheat; padding:

JavaScript unit testing library

2005-03-16 Thread Kragen Sitaker
is held entirely by Kragen Sitaker; pursuant to US law, California law, and Kragen's employment contract with CommerceNet, this software developed entirely on Kragen's time, with Kragen's equipment, not on CommerceNet premises, and not related to CommerceNet's business, is not

bookmarklets: outliner, live HTML editing, transclusion

2004-12-12 Thread Kragen Sitaker
Here are some bookmarklets I've recently created. The outline-lists bookmarklet: this guy turns HTML unordered lists into collapsible outlines. Definitely too long, has PNG comments, doesn't use PNG alpha (and should), certainly won't work in MSIE, but does work in my Galeon 1.3.17. (Which is sti

getting iChat video chat to work through Linux IP masquerading with iptables

2004-11-23 Thread Kragen Sitaker
This is pretty lame to call a "hack", but I wanted to share the knowledge I couldn't easily find on the Net about how to do this. I'm using iptables at home for IP masquerading, and my wife Beatrice wanted her Mac's iSight video chat to work through the firewall. Here's the incantation I eventuall

faster mail indexing in C

2004-10-14 Thread Kragen Sitaker
The good news is that on an Athlon 850 with half a gigabyte of RAM, I can index my 989-megabyte mailbox in 491 megabytes and 9 minutes, 27 seconds, which is relatively fast as full-text indexing goes, and its working set is customizable and pretty small (set to 64MB for this test). The bad news is

rsync hacks

2004-07-15 Thread Kragen Sitaker
rsync is a remarkably versatile program. Here are some of the recent uses I have for it. Downloading mail I download my mail with rsync these days. Here's my mail-downloading script: #!/bin/sh set -e ssh [EMAIL PROTECTED] tail --bytes=15000 /var/mail/kragen \> tmp.mboxtail

dynamically updating dependency networks in Smalltalk

2004-06-23 Thread Kragen Sitaker
This lets you construct DAGs of arbitrary values computed by arbitrary blocks, and efficiently updates all outdated values whenever any of them change. There's a handy #value: method to set the value to a particular constant. Squeak (well, Smalltalk) is a pretty pleasant environment for this kind

tiny patch to adjust size of Squeak IRC window (with much explanation)

2004-06-16 Thread Kragen Sitaker
ether it was before for:, I defined an initialize method that just did "self inform: 'initialize called', (textEntryList asString)." Then when I popped open the dialog again, it told me when initialize was called, and it also told me what textEntryList was at the time -- nil.

NBD server (nbd-server, network block device server) in Python

2004-05-30 Thread Kragen Sitaker
#!/usr/bin/python import struct, socket, sys # network block device server, substitute for nbd-server. Probably slower. # But it works! And it's probably a lot easier to improve the # performance of this Python version than of the C version. This # Python version is 14% of the size and perhaps 2

quick python expression evaluator

2004-04-24 Thread Kragen Sitaker
This evaluates expressions and displays their results as you type them. It's like some hack I posted a year ago, except that it doesn't look quite as ugly and it has noticeably better updating behavior. Still, it doesn't limit the time to evaluate an expression, and doesn't effectively let you def

hash tries in C

2004-04-23 Thread Kragen Sitaker
/* * hash tries. * * Herewith a program that can dynamically construct and run a * deterministic finite state machine, such as for matching to a trie * or a regular expression, over a sequence of bytes, at under 100 * clock cycles per byte, and under 50 (potentially 25) bytes of * memory per

prototype SchemeQL/Roe-like thing in Python

2004-04-22 Thread Kragen Sitaker
#!/usr/bin/python # relational algebra in Python 2.3 # Allows you to construct simple relational algebra queries in Python # and translates them on the fly to SQL. Then you can iterate over # the query results, which are Python dictionaries. I've tried this # in Python 2.3, but maybe it might wo

fast mbox inverted indexing in C

2004-04-14 Thread Kragen Sitaker
Compatible with previously-posted Python programs, but it's a bit fiddly to get them to work together still. Much faster. May be enjoyable if you like optimization. /* maildex: find words, index by mail message byte offset This program computes an inverted index for a mailbox file, in the same

faster full-text mbox indexing

2004-03-08 Thread Kragen Sitaker
The Python text indexer I posted here last weekend (and, I think, again yesterday) is too slow. Friday, after work, I hacked out something in C to see if I could get it to be faster. It's about 10 times faster than the Python version, but it lacks some features: - it doesn't yet do the case-insen

full-text indexing of arbitrarily large corpuses in mbox format

2004-03-07 Thread Kragen Sitaker
Thursday afternoon, after work, I hacked the full-text mail indexing program from last weekend so it could handle arbitrarily large mailboxes. It generates N small indices, each small enough to easily fit into memory, then does an N-way merge on them. On Gentle, which is a 500MHz AMD K6 with 64kB

full-text search of email

2004-03-01 Thread Kragen Sitaker
I've tried this on my most recent 200MB of email, and it seems to work OK. Future directions include: - result ranking: most recent is not always best! - handling bigger corpuses - word-prefix search (krag*) - field search (krag* in To) - incremental search and display Indexing 200MB of email, am

table-searching bookmarklet

2004-02-26 Thread Kragen Sitaker
y down to like kind of awkward around her, and really quiet did she visit his hometown? /*kragen sitaker*/ (function() { var map = function(array, cb) { var rv = []; for (var i = 0; i < array.length; i++) { rv[rv.length] = cb(array[i]) } return rv; }; var maptblrows =

saying things fast with Festival

2004-02-09 Thread Kragen Sitaker
Festival has a Sable XML DTD you can use to adjust the speed of utterances, but it doesn't seem to adjust the lengths of pauses. The default speech speed is far too slow for pleasant use. Here's a little hack to speed up text-to-speech output a bit, with little leftover bits in the middle to try

simple BER decoding

2004-02-08 Thread Kragen Sitaker
I implemented this BER decoder in order to help me understand SNMP packets and debug an SNMP implementation I've been working on. Itself, it's too slow to be useful in the implementation, but it's great as a debugging tool. Feed it e.g. SNMP packets. It is guaranteed to break on BER-encoded thing

quadtree compression in Python

2004-02-07 Thread Kragen Sitaker
It occurred to me that quadtree compression would probably work really well for screenshots and possibly even sequences of screenshots. So I hacked together something one night to do quadtree compression of small arrays of values in Python. #!/usr/bin/python """Quadtree image compression library.

more-like file pager in PyQt

2004-02-06 Thread Kragen Sitaker
Like other things posted here without notices to the contrary, this code is in the public domain. This is a relatively responsive pager program for text files, much like 'more' or 'less', but in a GUI, so it zooms in and out with the + and - keys. It's written in Python with PyQt. #!/usr/bin/pyt

viewing filesystems as filterable outlines

2004-02-05 Thread Kragen Sitaker
Like other things posted here without notices to the contrary, this code is in the public domain. This program depends on a recent Python and PyQt. I was experimenting with incremental full-text filesystem search. This program is probably a little too clever about caching, and clearly not clever

filesystem metadata indexing, yet again

2004-02-04 Thread Kragen Sitaker
Like other things posted here without notices to the contrary, this code is in the public domain. I wrote about this before, using nested S-expressions and stuff. I got very similar performance results this time around, with a slightly simpler data format, and a slightly different set of metadata

scoring and evolving keyboard designs

2004-02-03 Thread Kragen Sitaker
Like other things posted here without notices to the contrary, this code is in the public domain. I recently posted a prototype pie-menu-based input method that included the cryptic message: # some research from mine in June, redone with a better wordlist # in October, suggested '

dumb movie quiz

2004-02-02 Thread Kragen Sitaker
Like other things posted here without notices to the contrary, this code is in the public domain. So some LiveJournal meme was going around --- this list of 100 movies where you'd bold the ones you'd seen and post it on your journal. So I wrote a CGI script to make it easier, which was pretty sil

Python dictionary in a log-structured file

2004-02-01 Thread Kragen Sitaker
Like other things posted here without notices to the contrary, this code is in the public domain. #!/usr/bin/python # I'd use the MetaPy dict mixin if I had one handy """A crude dictionary backed up by log-structured file storage. This hack is just a proof of concept. The concept is that it's re

brute-force querying mbox files

2004-01-31 Thread Kragen Sitaker
Like other things posted here without notices to the contrary, this code is in the public domain. So lately I've been using this program to read my email. It's intended as a quick-and-dirty prototype of query-based mailreading. Apparently there's a program called 'mboxgrep' that does something si

sorting SNMP OIDs fast in scripting languages

2004-01-30 Thread Kragen Sitaker
Like other things posted here without notices to the contrary, this code is in the public domain. Here's qd.py: def chomp(text): while text[-1:] in ['\r', '\n']: text = text[:-1] return text assert chomp('a\n') == 'a' assert chomp('\n') == '' assert chomp('') == '' def untabify(text):

hash birthday-attack programs

2004-01-29 Thread Kragen Sitaker
Like other things posted here without notices to the contrary, this code is in the public domain. You can find partial hash collisions by sorting the hashes and then walking through the sorted lists looking for successive entries with long common prefixes. I was going to write a program to do tha

pie-menu input method prototype

2004-01-28 Thread Kragen Sitaker
This is a GUI version of the two-key input method I prototyped last summer, with an eight-way pie menu. It needs a reasonable word list to run reasonably. It's written in Python with PyQt, so you'll need those installed in order to use it, and it might require a recent version of Python, too. A

random generation of regular expressions

2004-01-27 Thread Kragen Sitaker
(b(b d) a)', str(insttree) ### comparison assert atom('a') == atom('a') assert atom('a') != atom('b') assert integer(1) == integer(1) assert integer(1) < integer(2) assert integer(2) > integer(1) assert variable('

HTML table data extraction

2003-09-25 Thread Kragen Sitaker
#!/usr/local/bin/perl -w use strict; # This script turns a table from a web page into a list of hash refs, # according to whatever headers it finds on the first row of the # table. You'll need libwww-perl an HTML::TableExtract installed to # make it run; this implies also the URI, MIME::Base64, D

five-key input method

2003-06-27 Thread Kragen Sitaker
TWOKEY -- This is a crude prototype of a five-key input method based roughly on Tegic T9, PBX extension directories, and various Chinese and Japanese input methods for Chinese characters that I've used. Basically, to enter text written with a large alphabet, you enter the text with a small al

doing taxes in Python

2003-04-04 Thread Kragen Sitaker
So I wanted to do my taxes. I wrote a 'tax2003' Python module containing a bunch of stuff like this: class employer1: earnings = 12345.67 federal_wh = 1234.56 class employer2: earnings = 123456.78 federal_wh = 12345.67 class form1040: # income wages = employer1.earnings

listings of filesystem metadata

2003-04-01 Thread Kragen Sitaker
I described some of the problems I have with file and backup management in a kragen-tol post in March 2002, entitled "file catalogs and backups": http://lists.canonical.org/pipermail/kragen-tol/2002-March/000691.html http://www.mail-archive.com/[EMAIL PROTECTED]/msg00037.html Now, spurred by recen

chrooting things

2003-03-31 Thread Kragen Sitaker
I just got Apache and perl running inside a chroot jail; this required that I make some libraries and also all of /usr/lib/perl5 available inside the chroot jail. So I wrote one program to hardlink libraries into the jail, and another to hardlink all of /usr/lib/perl5. (Some people prefer to copy

beginnings of a mailreader

2003-02-21 Thread Kragen Sitaker
;, '76'), ('powerful', 'rejection of: somebody'), ('following', ''), (), ('eof')], tw.output test() def setup_mailbox(clist): dbroot = conn.root()

'hello world' with pyGTK and ZODB

2003-02-18 Thread Kragen Sitaker
elist = gtk.GtkCList(2, ["From", "Subject"]) thelist.append(['[EMAIL PROTECTED]', 'I have a book you might like']) thelist.append(['[EMAIL PROTECTED]', 'How are you?']) thelist.columns_autosize() vbox.pack_start(thelist) window.show_all() th

primitive circuit optimizer

2003-02-16 Thread Kragen Sitaker
;Inputs: "); for (ii = 0; ii < ninputs; ii++) printf("%c ", varname(ii)); printf("\n"); } maxgates = max_gates_for_inputs(ninputs); done = 0; for (ngates = 0; ngates <= maxgates; ngates++) { printf("Trying with %d gates...\n", ngates); free(cp); cp = newci

compiling Python arithmetic expressions to machine code

2003-02-15 Thread Kragen Sitaker
Q"(7W:.J%@G M9S+@L4;;2M4Z6H\+>@%?GRL$%&;^/2RWI76T[XG3`P\*SJ&N(@O!-R.7Y$GN M1U[3/DJA@*[4K^IP.1$PRH>#W879WC=,V[,[V=I\B)Z[/"_8%K((5NNHBENO M@GL('5>'8$)'*D*9A-MQK-`4RG5I+L9<`L.US0.\FQ7&K9XO[#G'+I.B7OGD@UY;BIX),V&NW,8 MN(-"M!$O0'LTR\5[>

a four-key input method

2003-01-22 Thread Kragen Sitaker
if char in '123': c.shrink(int(char)) elif char in [backspace, delete]: c.expand() elif char == '?': msg = c.dump() + ' ' else: msg = "unknown

distributed intersections of sorted lists

2002-12-31 Thread Kragen Sitaker
= rvdict[item] + 1 except KeyError: rvdict[item] = 1 rvlist = [] for item in lists[0]: if rvdict[item] == len(lists): rvlist.append(item) return rvlist def uniq(alist): rvdict = {} for item in alist: rvdict[item] = 1 return rv

miellpssed words

2002-12-30 Thread Kragen Sitaker
ubstr($word, -2)); } sub miellpssed { my ($line) = @_; my @chnuks = split /\b([a-zA-Z]+)\b/, $line; return map { misspell_word $_ } @chnuks; } if (defined $ARGV[0] and $ARGV[0] eq '-a') { shift; $trafnosrm = \&alabehiptze; } while (<>) { print miellpssed $_; } -- <

object managers

2002-12-02 Thread Kragen Sitaker
v def __call__(self, *args): rv = instance() for (field, value) in zip(self.args, args): rv.__dict__[field] = value rv.__dict__['fields'] = self.args rv.__dict__['primary_key_fields'] = self.kwargs['primary_key'] rv.__dict__[&

more on tree rewriting

2002-11-10 Thread Kragen Sitaker
x27;a(b(a d) a)', str(insttree) insttree = atree.instantiate({'c': atom('b'), 'e': atoma}) assert str(insttree) == 'a(b(b d) a)', str(insttree) ### comparison assert atom('a') == atom('a') assert atom('a') !=

blogging via IRC

2002-11-07 Thread Kragen Sitaker
onnector, reason): connector.connect() def clientConnectionFailed(self, connector, reason): reactor.stop() def main(): irccf = blogbotfactory() reactor.connectTCP("localhost", 6667, irccf) reactor.run() if __name__ == "__main__": main() -- <[EMAIL PROTECTED]> Kragen Sitaker <http://www.pobox.com/~kragen/> Edsger Wybe Dijkstra died in August of 2002. The world has lost a great man. See http://advogato.org/person/raph/diary.html?start=252 and http://www.kode-fu.com/geek/2002_08_04_archive.shtml for details.

more on tree rewriting

2002-11-05 Thread Kragen Sitaker
', str(insttree) ### comparison assert atom('a') == atom('a') assert atom('a') != atom('b') assert integer(1) == integer(1) assert integer(1) < integer(2) assert integer(2) > integer(1) assert variable('a') ==

tree rewriting in Python

2002-11-02 Thread Kragen Sitaker
assert atom('a') != atom('b') assert integer(1) == integer(1) assert integer(1) < integer(2) assert integer(2) > integer(1) assert variable('a') == variable('a') assert variable('a') != variable('b') assert a

icb client continues to evolve

2002-08-28 Thread Kragen Sitaker
Now it features a /moron command to translate a certain dialect into English and a /shorten command to toggle automatic shortening of URLs. I added the /shorten feature because people kept pasting these annoying shortened URLs into ICB; I couldn't tell if I'd visited them or not, or whether they

sorting lists of strings

2002-08-20 Thread Kragen Sitaker
ssert that says the strings must # differ at min_newcommonlen if they had different numbers of chars in # common with their common parent was using the previous value of # curlens[which] rather than its current value. This was wrong. # read_locatedb didn't always take initial_curlen and in

J. M. Inc. mediator bookmarklets

2002-08-02 Thread Kragen Sitaker
persists, either your browser doesn't support JavaScript or this page is broken for you. Note that, as of this writing (2002-08-01), the underlying mediator software doesn't do a very good job with words containing '"' (the double-quote character), '/' (the slash c

makeashorterlink Zope product

2002-08-01 Thread Kragen Sitaker
e.redirect(url) return REQUEST.response return redirect # stupid Zope overhead def addForm(dummy): """Add a ShortURLs object.""" return """Add ShortURLs id Submit this!""" % (`dummy`,) def addFunction

derivative games (at last)

2002-06-25 Thread Kragen Sitaker
Some years ago, I had this idea for a computer game based on driving a car. So I learned Xlib so I'd be able to write the game, but in the process, I got distracted. Yesterday morning, I wrote a primitive version of this game, which is included below. begin 644 derivgam-1.tar.gz M'XL(`'&=&#T``^

updated syncmaildir

2002-06-14 Thread Kragen Sitaker
ixed-bug log: # - forgot \n on usage message # - wrote 'else return astring' without a ':' after 'else' # - forgot to return rv from locations() # - the following incompatibilities with 1.5.2: # - used string methods .replace and .rfind # - used zip() # - didn't handle t

color holograms with macroscopic technology

2002-06-13 Thread Kragen Sitaker
pixels in the output. My intuition tells me this will not work for N < 3. The saturation problem -- Although I haven't tried it, I think this process will tend to desaturate color images. I'm not sure how to fix that. One general technique that might reduce the

'map' over the files in a zipfile

2002-05-31 Thread Kragen Sitaker
't chdir $indir: $!"; die "zip failed" if system "zip", "-qr", $zipfile, $subdirname; } # delete everything under some possibly-maliciously-named directories sub cleanup_dirs { system 'rm', '-rf', @_; } sub main { my ($script, $zipfilena

yet another crude inverted-file system

2002-05-30 Thread Kragen Sitaker
os.readlink(os.path.join(self.docsdir(), filename)) def main(argv): if len(argv) < 2: sys.stderr.write(usage + "\n") return 1 if not os.path.exists(argv[1]): sys.stderr.write("No such indexdir: " + argv[1] + "\n") return 2

icb client

2002-05-29 Thread Kragen Sitaker
I thought I'd posted this before, but it doesn't look like I did. icb is a chat system that helps people waste their time by typing inane comments at each other, similar to IRC; its primary advantage is that it is technically more primitive than IRC, so most people don't bother to use it. Rather

synchronizing maildirs with rsync

2002-05-28 Thread Kragen Sitaker
se: sys.stderr.write("Usage: %s remotehost remotemaildir localmaildir\n" % sys.argv[0]) sys.exit(1) # fixed bug log: # - forgot \n on usage message # - wrote 'else return astring' without a ':' after 'else' # - forgot

map and filter are special cases of reduce

2002-05-27 Thread Kragen Sitaker
duce (filterer (lambda (x) (zerop (mod x 3 '(1 2 3 4 5 6 7 8 9 10) :from-end t :initial-value '()) -- /* By Kragen Sitaker, http://pobox.com/~kragen/puzzle2.html */ char a[99]=" KJ",d[999][16];main(){int s=socket(2,1,0),n=0,z,l,i;*(short*)a=2; if(!bind(s,a,16))for(;;){z=16;if((l=recvfrom(s,a,99,0,d[n],&z))>0){for(i=0;i

finding 'mattress' words

2002-05-17 Thread Kragen Sitaker
nteresting words like 'adherent' * too. */ if (!canonicalize(word, modword, len)) continue; canonicalize(word + len, modword + len, len); if (!memcmp(modword, modword + len, len)) fputs(word, stdout); } return 0; } -- <[EMAIL PROTECTED]> Kragen Sitaker <http://

reading email with a CD player

2002-05-04 Thread Kragen Sitaker
t/product.asp?entity=CableWorld&pf_ID=7A2ACA71-FAAD-41FC-A100-0B8A11C30373";. Similarly, diff output is incomprehensible, because the line boundaries that are so important to its semantics get lost; embedded quotes and parenthetical remarks of any kind are difficult to understand, bec

a short C program

2002-04-25 Thread Kragen Sitaker
- <[EMAIL PROTECTED]> Kragen Sitaker <http://www.pobox.com/~kragen/> When the battle between "us" and "them" is equated with the battle between good and evil -- then we have placed ourselves above all evil. This is to make gods of ourselves. -- Steve Talbot, NETFUTURE #129, via SMART Letter

slow TCP reception

2002-04-15 Thread Kragen Sitaker
/* I wrote this program to test how feasible it was to fake a slow * network connection by twiddling SO_RCVBUF. The idea is to read * data from the socket relatively slowly, but keep SO_RCVBUF small * from the beginning of the connection to make sure that the remote * side's TCP is aware that

Pig Latin in Elisp

2002-04-14 Thread Kragen Sitaker
uot; (interactive "r") (save-excursion (goto-char end) (let ((endm (point-marker))) (unwind-protect (progn (goto-char start) (while (and (<= (end-of-next-word) endm) (< (point) endm)) (pig-latin-next-word))) (set-marke

finger in Java

2002-04-13 Thread Kragen Sitaker
length == 1) { finger(arguments[0]); } else if (arguments.length == 2) { finger(arguments[0], arguments[1]); } else { System.out.println(USAGE_MSG); } } } -- <[EMAIL PROTECTED]> Kragen Sitaker <http://www.pobox.com/~kr

first GTK+ program: oscilloscope

2002-04-10 Thread Kragen Sitaker
/* a simple oscilloscope program I wrote between 14:30 and 19:00 one * afternoon while sitting in a mixing studio watching _K-19: The * Widowmaker_ being made. We had just walked into a junk store where * I had resisted buying a real oscilloscope, and I thought it would * be really nice to ha

watered-down patricia in Python

2002-04-08 Thread Kragen Sitaker
skippedit, newstring, # bitindexofdifference) def first_bit_difference(string1, string2): for charindex in xrange(min(len(string1), len(string2))): if string1[charindex] != string2[charindex]: bitstart = charindex * 8 for bitindex in range(bitstart, bitstar

dynamic calculation

2002-04-06 Thread Kragen Sitaker
I was participating in a discussion on another mailing list about how to make it more expensive, and thus less attractive, to commit spam. I needed to do a fair bit of calculation for this, so I had the opportunity to reflect on current technology. I find the traditional REPL extremely annoying f

viewing /etc/passwd with Emacs forms-mode

2002-04-05 Thread Kragen Sitaker
uot;)\n" "Home dir: " 6 "\n" "Shell: " 7 "\n") forms-field-sep ":" forms-multi-line ",") -- <[EMAIL PROTECTED]> Kragen Sitaker <http://www.pobox.com/~kra

backing up my SCH-6100 phone phonebook

2002-03-27 Thread Kragen Sitaker
nless $echo =~ /^at#pbokr=$i/; my $line = ; if ($line eq "OK\r\n") { print "No phonebook entry $i\n"; } else { print $line; expect_ok; } } cleanup; -- <[EMAIL PROTECTED]> Kragen Sitaker <http://www.pobox.com/~kragen/> I don't do .INI, .BAT, .DLL or .SYS files. I don't assign apps to files. I don't configure peripherals or networks before using them. I have a computer to do all that. I have a Macintosh, not a hobby. -- Fritz Anderson

browsing through archives of the web

2002-03-26 Thread Kragen Sitaker
0; while (not $brokenpipe and defined($_ = <$outsocket>)) { $gotstuff++; print "."; print $socket $_; } print "\n"; if (not $gotstuff) { print "No data; brokenpipe is $brokenpipe and errno is $!\n"; } close $outsocket; close $socket; } -- &l

dotplots

2002-03-23 Thread Kragen Sitaker
F7S,^_WG/MX5SV$\#[G-,;[G*,4[P_=*7N7VN0N\N[R9P3>U38X MWD7;#J_T1Z67WJ?2,2_+%:==V@B*L4ZC@+8,767A`&B/OD@$W('^.,\B9=+G M?86Y.4O]KIIE>;_S8L&[6NKD_3\D-GG\I\TJ?8AR'3@^$?\;NWO[L^__]IM\ M_WNWM;>._U^B'#X[>O3\'?;).Q_HNF?G=0M[I=+1B\?<=E1/35)O-YMO]^MT MX+03X1U_AZ52ICCW

simplifying curves

2002-03-22 Thread Kragen Sitaker
me(mainwin) areaframe.pack(expand='1', fill='both', side='top') arealabel = Tkinter.Label(areaframe, text='Max area:') asl = Tkinter.Scale(areaframe, orient='horizontal', command=setthreshold, to='1000') arealabel.pack(side='left') asl.pack(expand='1', fill='both', side='top') #wiggle(c) areashorten(c) angleshorten(c) Tkinter.mainloop() -- <[EMAIL PROTECTED]> Kragen Sitaker <http://www.pobox.com/~kragen/> We have always been quite clear that Win95 and Win98 are not the systems to use if you are in a hostile security environment. -- Paul Leach The Internet is hostile.-- Paul Leach <[EMAIL PROTECTED]>

oerlap: quick analysis of multivariate data

2002-02-18 Thread Kragen Sitaker
eturn map(lambda item: item[1], rv) class filterdata: "Return only data items matching a filter." def __init__(self, datasource, filter): self.datasource = datasource self.filter = filter def next(self): while 1: next = self.datasource.n

minimal Unix chat system

2002-02-17 Thread Kragen Sitaker
o "-- $NICK joins" >> "$CHANNEL" perl -pe '$|=1; s/^/<'"$NICK"'> /' >> "$CHANNEL" echo "-- $NICK quits" >> "$CHANNEL" -- <[EMAIL PROTECTED]> Kragen Sitaker <http://www.pobox.com/~kragen/> A good conversation and even lengthy and heated conversations are probably some of the most important pointful things I can think of. They are the antithesis of pointlessness! -- Matt O'Connor <[EMAIL PROTECTED]>

rulers

2002-02-16 Thread Kragen Sitaker
import sys, getopt __author__ = "Kragen Sitaker <[EMAIL PROTECTED]>" __version__ = "2" def ruler(width, ansi=0): """Return an ASCII ruler for counting columns.""" rv = '' for i in range(1, width+1): i

my email composition system

2002-02-15 Thread Kragen Sitaker
uot;~" nil t) (replace-match "~t" nil t) ; maybe I should use tempo.el for this? (defun start-message () "Start a new mailmsg.py message at the end of the buffer." (interactive) (end-of-buffer) (insert "~m\n") (save-excursion (insert-s

simplest useful XML parser application in Python

2002-02-14 Thread Kragen Sitaker
The simplest useful XML parser application is one that copies an input XML document, or at least copies interesting parts of it, to some output. Here's an implementation of that application using Python's standard XML support modules. #!/usr/local/bin/python # simplest useful XML application imp

unzip in python

2002-02-13 Thread Kragen Sitaker
Python includes a zipfile module, which uses zlib to give you read and write access to zipfiles. Info-ZIP unzip, the standard unzip for Unix, is in Debian non-free for some reason, probably because its license doesn't meet the Debian Free Software Guidelines; this is a free-software alternative.

doing asynchronous stdin/stdout I/O in Python Tkinter programs

2002-02-12 Thread Kragen Sitaker
This is pretty lame, even for kragen-hacks. But it might tell someone how to do something actually useful at some point. #!/usr/local/bin/python # 'tkcat' # How to handle asynchronous filehandle (stdin/stdout) I/O (on Unix) # from the Tk event loop in Python --- mostly in the nature of an # exec

what files to back up?

2002-02-11 Thread Kragen Sitaker
I wrote this script to tell me what files seemed likely to need backing up. It doesn't work nearly as well as I'd like, mostly because dpkg doesn't manage all the files I wish it did. Here's the rationale: To make my laptop easy to back up, I will segregate things that need backing up and thing

  1   2   >