Toys!

Little toys none of which are really worthy of a full-fledged "project", either because they're a single file of code or because regardless of size, once committed they're actually done and don't need much future attention.


toys: Tue Feb 26 01:20:00 2008

Tue Feb 26 01:20:00 2008

t9.py is an exploration of words with ambiguous T9 (phone text interface) encodings. The interesting bit is the scaling issue... or lack of one: it handled a 230K wordlist, producing 10k result sets, in about 30 seconds... on an EEEpc. Completely naive implementation, no optimization (and thus no wasted optimization :-) I did use string.maketrans and string.translate but that was more because I'd used them before and they're actually a pretty natural fit for this task. (I did switch from lists to sets, but that wasn't performance-related either - the wordlist I was working from had a variety of entries that weren't unique when downcased, and it didn't occur to me to just use sort -fu on it.)

Footnotes:


toys: Sun Jan 13 23:33:00 2008

Sun Jan 13 23:33:00 2008

While debugging a very strange problem (a simple shell loop that was occasionally continuing around before the body was done, leading to multiple parallel runs of something that was supposed to be serialized) I came across Debian Bug #445956 - "script dies on SIGWINCH."

The bug report simply notes that script "dies", reporting "Script done, file is typescript", which is true... but incomplete. It turns out that script has a parent and child process, and only the parent dies; the child (and whatever was being run inside script) continues to run!

In the long run, the important thing is that bsd-utils actually got fixed (the bug mentioned above is closed by 2.13-9, though that is post-etch and post-gutsy.) In the short run, it would be nice (at least for me) to have a workaround...

My first attempt was simply to use signal.signal to set SIGWINCH to SIG_IGN (in the python wrapper that actually runs script for me.) Not good enough - the bug is in code that is setting a SIGWINCH handler in script itself.

Second attempt was to call sigblock... but for portability reasons (somewhat tied to embedding python in other code, if I correctly interpreted the postings excusing its absence - I didn't look to closely because having a good reason didn't actually solve my problem :-) python's signal module can't do sigblock. Oh well, ctypes to the rescue; fixed_script.py shows an example of the workaround. Worked for me, both in my application and in standalone tests using screen to change window sizes (I use ratpoison and generally don't want windows to take up less than the entire screen, so outside of testing like this I don't generally care that I can't easily resize windows... I only noticed in this case because I reattached the screen session from two different machines, which had different (fixed) window sizes :-)

Footnotes:


toys: Sun Nov 5 17:21:00 2006

Sun Nov 5 17:21:00 2006

tratmenu - clone of ratmenu (from the man page and my usage of it) using curses instead of X11. Takes the same options so that I can use it for some ultimately text-based applications (like picking surfraw engines from a list, or picking hosts-to-ssh-into from a generated list of things I have access to.)

This is another project that stalled until I started with the "simplest thing that can work"... one by one, I

Each of these was only a couple of minutes and mostly a matter of looking up parts of the curses API or the ratmenu manpage. There are still a few things that I don't care much about but may implement for completeness:

Also, I may add an explicit "if $DISPLAY is set, run the real ratmenu instead" option, just so that I can have a common command regardless of context, though that doesn't actually work for things which might or might not need a window unless I also add an xterm_or_not wrapper.