Ask (Google) and ye shall receive

I’ve (re)discovered AutoHotKey and used it to solve a tremendously annoying Windows “feature” — you can’t move maximized windows.  I downloaded Easy Window Dragging — KDE Style and hacked it to un-maximize a window before it moves it.

I also thought, Hey, you could implement a virtual window manager in AutoHotKey with not too much difficulty.  Some Googling leads me to an actual virtual window manager (VirtuaWin) and it’s free and so far (all of 10 minutes in) I’m quite happy with it.  I wish I’d found it four years ago.

It’s all way better than the LiteStep configuration I wasted, oh, two days on.  *shudder*  Suffice to say, run away.

I hate it when … invalid models

I hate it when my internal model of a program doesn’t quite match its actual behavior.

So I’m tailing a file: “tail -f file”.  Tail recognizes when a file’s been truncated and starts rereading it.  BUT, even if you say “-n +0” it still starts rereading from the new end, not from the beginning.  So if you have

# Terminal 1
date > file
tail -f -n +0 file

# Terminal 2
date > file
date > file
date > file

You’ll never see anything new from tail, because the length of the file never actually changes.

More subtly, say you have

# Terminal 1
date > file
date >> file
tail -f -n +0 file

# Terminal 2
date > file

Here the tail will see that you truncated the file, but it won’t show you the new line, because the file length changed from 58 to 29, not from 58 to 0 to 29.

All that’s fine and maybe even “obvious” when laid out like that.  But you can get the same behavior like this:

# Program 1, pseudo-Perl
open LOGFILE, “>file”;
while (my $request = get_request()) {
    print LOGFILE “the requestn”;
    process( $request );
}

# Terminal 1
tail -f -n +0 file

When you restart Program 1, you won’t see the first request in the log file, because just as above, the file length went from (say) 100 to 50, not 100 to 0 to 50.

But if you cat the file, there it is.

Anyway, I hate it when that happens.

(The answer, by the way, is to unlink the file before you start writing to it again, and tell tail “–follow=name”.)

An interesting practical tutorial on states of alertness.

If you should find yourself faced with a life-threatening attack by a criminal, as a typical normal person, you will be faced by three enormous difficulties. They are:

1. Recognizing the presence of the predator in time;

2. Realizing, internalizing, and accepting that THAT MAN, RIGHT THERE, is about to kill you for reasons you do not understand; if you don’t stop him; and

3. Overcoming your reluctance to do lethal violence against a fellow human being.

Read the rest here.

Continue reading An interesting practical tutorial on states of alertness.

A few things I’ve learned about time synchronization in VirtualBox

These comments may be specific to running a Debian Linux guest on a Mac OS X host.
  • Time synchronization is briefly documented in the manual in chapter 9, Advanced Topics.
  • Time synchronization is performed by an in-guest daemon called VBoxService
  • You can tune VBoxService (on the guest) by running VBoxManage on the host.  As near as I can tell, you must restart VBoxService for any changes to take effect.  (In Debian, /etc/init.d/vboxadd-service restart.  To kill it, replace “restart” with “stop”.  To start it after you’ve killed it, replace “restart” with “start”.)
  • You can watch what VBoxService does by killing the daemon (see above) and running it from the command line in verbose mode, in the foreground (as root), “VBoxService -v -f“.
  • By default, VBoxService wakes up every 10 seconds and adjusts the time.  If the time is off by less than 20 minutes, it adjusts the time by (very roughly) 0.005 seconds.  (Put another way, if your clock is slow by a whole second, it may take half an hour to catch up.)  If the time is off by more than 20 minutes, VBoxService just sets the time.
  • If you want VBoxService to just set the time when it’s off by more than 1 second (1000 ms), instead of adjusting it gradually every 10 seconds, you can say
    • VBoxManage guestproperty set <vm-name> "/VirtualBox/GuestAdd/VBoxService/--timesync-set-threshold" 1000
  • The “--” in the documentation and in the command above is not a typo.
  • Remember to restart VBoxService for your changes to take effect.