htmlstr() in Python

2002-01-14 Thread Kragen Sitaker
extends all the way across to the right, so we just * highlight the table */ .py_list table {background-color: #ffeecc} Here's an implementation of htmlstr(), basically for builtin types. # Kragen Sitaker, 2001-12-05 # Produce HTML renderings of Python objects. # For stylesheets: the followi

benchmarking memcpy vs. strcpy

2002-01-14 Thread Kragen Sitaker
I was making the claim somewhere that NUL-termination made string copying slower. It occurred to me that I ought to test that before making the assertion; indeed, this program shows that at the one-kilobyte level on my laptop, it's slower by about a factor of 6. #include #include #include #in

portlisten: passing socket file descriptors through sockets

2002-01-16 Thread Kragen Sitaker
In Unix, many of the bigger violations of the principle of least privilege stem from the rule that only root can bind to TCP or UDP ports below 1024. Many network daemons run as root just so they can do this. This pair of programs illustrates how you can have a small, simple program bind to the

MetaPy Python package

2002-01-16 Thread Kragen Sitaker
This is a little larger than the normal posts on this list. Some of this code shows promise of being useful, but it still needs quite a bit of spit and polish in my eyes. I'm only posting it here because other items in the hacks queue use it. begin 644 MetaPy-6.tar.gz M'XL(".-)$3P"`TUE=&%0>2TV+

idiosyncratic markup processor

2002-01-17 Thread Kragen Sitaker
I seem to have a thing for writing "simple" markup languages that get translated to HTML, because HTML is both too slow to type and too hard to read for my taste. I started doing this in 1994 with a bunch of m4 macros called "htm4". This hideous mess of kludges is the fourth one, and I like its

picturepages --- showing off your photos on the Web

2002-01-18 Thread Kragen Sitaker
contents, and lets viewers look at the subset of your images containing a particular thing. This software is not public domain, but copyright Kragen Sitaker 2001; it is licensed under the GNU GPL version 2. begin 644 picturepages-1.tar.gz M'XL(`-UPN3L``^1;37/;2)+U=2KV1U3HTE($34MVVQZW3Y1$6=

$PATH modification

2002-01-19 Thread Kragen Sitaker
work. (-i /usr/bin:/bin would work; -i /usr/bin:/bin -d /bin would fail.) So I had the choice of (a) having subtly buggy behavior; (b) rejecting reasonable input; or (c) writing the code so that it would cope with reasonable input. I chose (c). """ #'#"# Unconfuse poor

record-movie, play-movie

2002-01-20 Thread Kragen Sitaker
I've often wanted something that can record byte streams with timing intact and play them back with the timing intact. So someone FoRKed a site you could telnet to (towel.blinkenlights.nl, I think) to get played an ASCII-art movie of Star Wars, and after watching a bit of it, I knew I wanted a co

download meter

2002-01-21 Thread Kragen Sitaker
A long time ago, I posted an ASCII-art download meter in Perl to kragen-hacks. It drew a little progress bar in equals signs and estimated what time the file would finish downloading. Here's a version with Python and Tkinter. It's useful even when iconified, at least if you're using a window ma

google toolbar, Python version

2002-01-22 Thread Kragen Sitaker
when there are exceptions; oh well. Otherwise, it seems unchanged. #!/usr/bin/env python import os, urllib, re, sys from Tkinter import Radiobutton, Toplevel, Button, Tk, mainloop # Handy little button bar for looking things up. # Original version was in Tcl. # Kragen Sitaker, 2001-10-24; public

a better reload() for Python

2002-01-24 Thread Kragen Sitaker
This should be available at http://pobox.com/~kragen/sw/newreload-2.tar.gz """newreload: a better reload() for Python reload() has some bugs --- well, let's say documented behavior I don't like: 1. modules the reloaded module imports don't get reloaded. This means you have to know something

tricklemail: letting mail trickle out

2002-01-25 Thread Kragen Sitaker
Note that this program uses stuff from MetaPy, which I posted here previously, and which is also available from http://pobox.com/~kragen/sw/MetaPy-6.tar.gz. #!/usr/bin/python # I have some lists that have the following characteristics: # - not time-sensitive: it's generally OK if stuff gets sent

memory-mapped Numerical Python arrays

2002-01-26 Thread Kragen Sitaker
Python has this package called Numeric (or Numerical Python, or Numpy), which provides APLish (or PV-WAVE IDL-ish, or PDLish) multidimensional homogeneous arrays of numeric data, of the sort one often encounters in scientific computing. It provides aggregate operations on these, such as elementwi

word squares

2002-01-27 Thread Kragen Sitaker
Solution of "word squares" was a popular amusement among word freaks in the 1800s. A word square is a square grid of letters that reads the same horizontally and vertically; for example, B e a e a r a r c Here's a program to produce word squares, given an initial seed word or two. It runs und

lower-case parens

2002-01-28 Thread Kragen Sitaker
In some discussion on ll1-discuss, Olin Shivers talked about how nice it was to have lower-case parens. Here's my xmodmap file that lets users of X have lower-case parens by swapping them with square brackets. After using my keyboard this way for about a month, I'm mostly used to it, although I

hash consing in Python 2.x

2002-01-29 Thread Kragen Sitaker
"""Hash consing is a technique for implementing immutable conses (or whatever compound data structure) where you store all the living conses in a weak hash table, indexed by their children. The cons routine looks in this table whenever it is called; if it finds it is being asked to make another c

interposition on import in Python

2002-01-30 Thread Kragen Sitaker
# something you might want to do: trace imports. For example, if # you're writing a module that does something special with some kinds # of objects from urllib, but is useful without urllib being loaded, # you might not want to import urllib if your caller didn't already # import it. But if it i

mail, event notification, and such things

2002-01-31 Thread Kragen Sitaker
Sometimes, especially when I'm using my cell phone as a modem, I want to get online, download my new mail, upload whatever mail I have ready to send, and get offline as soon as possible. Here's the system I use for this at the moment. I run this shell script to control everything; pon and poff a

"oerlap": interactive analysis of tuple-element frequencies

2002-02-01 Thread Kragen Sitaker
I wanted to call this "colapse", because it seemed like the perfect term, but that seems to be a widely-used word. Google finds 5560 hits, both misspellings and other things. "oerlap" isn't quite as apt a term, but it isn't used for anything else, except as a rare misspelling of "overlap".

building prefix trees to match sets of strings

2002-02-02 Thread Kragen Sitaker
I occasionally run across the problem of matching one of a number of fixed strings in text. A very efficient way to do this is to build a deterministic finite automaton which will halt with success upon recognizing any of the strings, or halt with failure upon recognizing a string that is not a p

pam_http: PAM module using HTTP Basic authentication

2002-02-03 Thread Kragen Sitaker
ty and put something like the following in the appropriate files in your pam.d directory: auth required pam_http.so url=https://ourserver.example.com/ Copyright Kragen Sitaker, 2001. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the G

pymagemap --- Python version of imagemap.cgi

2002-02-04 Thread Kragen Sitaker
This program had a couple of those forehead-slapping moments. In early November, I'd moved my web pages from www.dnaco.net to www.canonical.org, but www.dnaco.net was still getting hits --- one of my pages referred explicitly to its imagemap.cgi program, because it had a server-side imagemap in i

making passwords

2002-02-05 Thread Kragen Sitaker
It has been asserted that passwords are obsolete, because they are either too long to memorize or too easy to crack by exhaustive search. This program generates strongly random passwords using data from /dev/random that are both short enough to memorize and type accurately and impractical to attac

Common Lisp HyperSpec index lookup

2002-02-06 Thread Kragen Sitaker
Learning Common Lisp, and especially reading Paul Graham's just-published-on-the-Web _On Lisp_, I often wish for a quick online help program that will tell me what a particular Lisp idiom means. Kent Pitman made this awesomely cool thing called the Common Lisp HyperSpec, which weighs in at 18 megs

object-oriented bash scripts

2002-02-07 Thread Kragen Sitaker
Idea from Martin Hinsch's woosh: http://wosx30.eco-station.uni-wuerzburg.de/~martin/woosh/ Implementation by Kragen Sitaker, not having read the woosh code; I thought a prototype-based system would be more suited to the shell. shoo makes your filesystem and shell into a prototype-based o

object-oriented bash scripts (second try)

2002-02-08 Thread Kragen Sitaker
depends on where you install it and what implementation of bc you have.] The idea is from Martin Hinsch's woosh: http://wosx30.eco-station.uni-wuerzburg.de/~martin/woosh/ Implementation by Kragen Sitaker, not having read the woosh code; I thought a prototype-based system would be more suited

add-a-grams

2002-02-09 Thread Kragen Sitaker
>From something on lambda.weblogs.com. #!/usr/bin/python """Compute the longest "add-a-gram" from a word list. The problem is from http://www.itasoftware.com/careers/programmers.php Add-A-Gram An "add-a-gram" is a sequence of words formed by starting with a 3-letter word, adding a lett

APM time

2002-02-10 Thread Kragen Sitaker
eed to have a kernel compiled with /proc and APM support. I run it in a small xterm without any arguments. """ import re, select, os, time, sys __author__ = "Kragen Sitaker <[EMAIL PROTECTED]>" __date__ = "2001-10-24" __version__ = "2" # version 1 was

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

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

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.

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

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

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

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]>

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

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]>

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

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

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

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

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

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

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

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

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

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

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

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

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://

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

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

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

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

'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

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

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

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``^

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

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

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

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

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

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') ==

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-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') !=

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__[&

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 $_; } -- <

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

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

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[>

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

'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

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()

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

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

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

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

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

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('

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

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

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):

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

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

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

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 '

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

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

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

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.

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

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

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 =

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

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

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

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

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

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

  1   2   >