January 16, 2008

Eye of the Tiger

Filed under: Tech — Chris @ 1:31 am

Does anybody know which new API in Mac OS X 10.4 is the reason I can’t use iLike the Amazon MP3 Downloader on my Power Mac G4? Any can anybody tell me why it sucks?

Believe it or not, I actually can’t upgrade to 10.4, because it only comes on DVD-ROM and my, ahem, 6 year old G4 doesn’t have a DVD-ROM drive. (You can get CDs if you buy a copy of 10.4 and send Apple a check for ten or fifteen bucks, but… eh, no.) I will not be buying a new computer this year.

November 26, 2007

xkcd: Success

Filed under: Not Tech, Tech, Waste of Time — Chris @ 2:31 pm

This is pretty much exactly how it went down when I upgraded to Gutsy.


Consider this a standing endorsement of xkcd.

November 25, 2007

Gnome Sessions

Filed under: Linux, Tech — Chris @ 8:56 pm

I tentatively clicked “Remember current running applications” in Gnome Session Preferences (aka gnome-session-properties) and lived to regret it. What this does is it restarts any currently running application when you login. This is useful for, e.g., your online backup daemon, but kind of annoying for, e.g., five Emacs windows,, some random Nautilus directory window, etc.

Now, first I tried checking and unchecking “Automatically remember running applications when logging out”, as the window layout makes it seem as if these two settings are related. They are not. Then, I was tempted to fix this by futzing with the “Startup Programs” or “Current Session” lists. This is Not Right.

The Right Thing is to close all your programs (or just the offending ones) and then click again on “Remember current running applications”. That is to say: the only way to change the “remembered” snapshot is to take another snapshot*.

Note: Session Preferences has a Help button, but the Gnome manual page on it doesn’t mention “Remember currently running programs” or “Automatically remember running applications when logging out”. This is annoying.

* Presumably there is a text file tucked away somewhere that controls this (maybe ~/.gnome2/session?), but I haven’t the patience to find out.

Style Guidelines for People

Filed under: LaTeX — Chris @ 8:03 pm

In the midst of some unrelated Googling, I came across Luca de Alfaro’s style guidelines for student co-authors. This is good stuff. I particularly like “one sentence per line” b/w “fill-sentence macro”. It’s an elegant solution to a frequently annoying deficiency of diff, which is unfortunately the baseline for anyone collaborating via CVS or SVN. I tweaked his macro to get nice indentation in AucTeX:

(defun fill-sentence ()
    (or (eq (point) (point-max)) (forward-char))
    (forward-sentence -1)
    (let ((beg (point)))
      (if (equal "LaTeX" (substring mode-name (string-match "LaTeX" mode-name)))
          (LaTeX-fill-region-as-paragraph beg (point))
        (fill-region-as-paragraph beg (point))))))
(global-set-key "\ej" 'fill-sentence)

[UPDATE 1/20/08] Fixed an off-by-one error when the cursor is on the first character of the sentence by adding (forward-char).
[UPDATE 9/19/08] Fixed an error when the cursor is at the end of the buffer by changing (forward-char) to (or (eq (point) (point-max)) (forward-char))

LaTeX Letters

Filed under: LaTeX, Tech — Chris @ 4:42 pm

I was trying to write a letter in LaTeX the other day:





\opening{To Whom It May Concern:}

Hello, there.



This led to the following two errors, which shed little light on the situation:

! LaTeX Error: There's no line here to end.

See the LaTeX manual or LaTeX Companion for explanation.
Type H  for immediate help.

l.10 \opening{To Whom It May Concern:}

and (on a different example)

! Incomplete \iffalse; all text was ignored after line 66.

l.16 \end{letter}

Runaway text?
\@mlabel{}{\unhbox \voidb@x \ignorespaces \global \let

The problem, as it was gently explained to me, is I had omitted the second mandatory argument of \begin{letter}, which is the address of the recipient. The following is correct:




\begin{letter}{Foo Corp.}

\opening{To Whom It May Concern:}

Hello, there.



[UPDATE] I just realized that the reason I got so confused about this is that I was working off a previous business letter that was formatted like:

Foo Corp. \\
... \\
ATTN: Warranty Dept.}

I’m not sure if I intended it to be the case (probably not), but LaTeX picked up the braces around the address as the argument to letter. When I used this as the template for a personal letter and deleted the address, all hell broke loose.

November 15, 2007

Fake project directories in tarballs

Filed under: Tech — Chris @ 2:39 pm

To make a tarball where all the files are in a subdirectory FOO (as per best practices), where FOO doesn’t really exist on your disk (e.g., FOO may be PROJECT-vX.Y.Z and the files are in directory PROJECT), just do

tar cvf NAME.tar --transform=s,^,FOO/,g FILES

Note that the argument to transform in this case is just a sed command with commas instead of slashes.

November 10, 2007

Eye Candy

Filed under: Linux, Tech — Chris @ 11:24 pm

The difference between “Desktop Plane” and “Desktop Wall” in the Ubuntu “Visual Effects” options (aka CompizConfig Settings) is that the latter allows windows to overlap a viewport* and the former does not. (Along with this comes a lot of incidental options and visual fillips, like the ability to drag a window entirely from one viewport to another.) Although this does not sound like a big productivity booster, I’m going to give the Wall a chance.

I’m not going to give the “Desktop Cube” a chance, because it won’t let me place viewports above and below, as well as left and right, seemingly out of some wrong-headed sense of pseudo-three-dimensional literalism (although your “cube” can have an arbitrary number of faces, they must be arranged linearly from left to right: Euclidian topologies only).

* For some reason the “Desktop Plane,” “Desktop Wall,” and “Desktop Cube” options all use viewports and not workspaces**, so they don’t work well with the Gnome Workspace Switcher.

** For some other reason, Gnome has two distinct ways of implementing virtual desktops (viewports and workspaces) even though theres no discernible advantage to one over the other (except for compatibility with this application or that).

[UPDATE] Visual Effects lead to intermittent system freezes. Fun! Going back to boring old workspaces.

November 6, 2007

Updating for Daylight Savings Time on Ubuntu

Filed under: Linux, Tech — Chris @ 9:28 pm

My system clock has been all wiggy since Daylight Savings Time ended (or started?) (it’s ended) on Sunday. Believe it or not, it was actually flipping back and forth between correct and one hour ahead for no apparent reason. I did two things which together seem to have fixed things.

First, via Fast Track Sites, I found that my system timezone information was out of date. The test for this is:

% sudo zdump -v /etc/localtime | grep 2007
/etc/localtime Sun Mar 11 07:59:59 2007 UTC = Sun Mar 11 01:59:59 2007 CST isdst=0 gmtoff=-21600
/etc/localtime Sun Mar 11 08:00:00 2007 UTC = Sun Mar 11 03:00:00 2007 CDT isdst=1 gmtoff=-18000
/etc/localtime Sun Nov 4 06:59:59 2007 UTC = Sun Nov 4 01:59:59 2007 CDT isdst=1 gmtoff=-18000
/etc/localtime Sun Nov 4 07:00:00 2007 UTC = Sun Nov 4 01:00:00 2007 CST isdst=0 gmtoff=-21600

If the output doesn’t exactly match the above, you have a problem. Download the latest tzdata2007X.tgz file (where X is a lowercase letter) from the National Cancer Institute (seriously). For gorey details, see the Fast Track Sites post cited above. (I don’t think you really have to do the ln step, which sets your timezone to EST5EDT instead of, e.g., America/New_York. I skipped it.)

Now your system ought to know the right start/end dates for Daylight Savings Time. But your clock is probably still out of whack.

Now, via Ubuntu Forums and Stephen Sykes, use ntpdate to reset the clock. The trick(s) here are: (a) you have to shut down ntpd first, (b) setting the clock back an hour will convince sudo that you’re trying to do something nefarious (“timestamp too far in the future”), and (c) I had to give ntpdate the -u option to get past some unseen firewall.

% sudo /etc/init.d/ntp-server stop
 * Stopping NTP server ntpd                                 [ OK ]
% sudo ntpdate-debian -u
 6 Nov 17:00:00 ntpdate[13693]: step time server offset -3598.042737 sec
% sudo /etc/init.d/ restart
sudo: timestamp too far in the future: Nov  6 17:59:56 2007

Oops. Using the “Adjust Date & Time” applet, manually set the clock one hour forward. Now, run sudo -k. Now, set the clock back to the correct time (again using “Adjust Date & Time”). Starting over:

% sudo ntpdate-debian -u
 6 Nov 17:00:00 ntpdate[13693]: step time server offset -3598.042737 sec
% sudo /etc/init.d/ restart
 * Saving the system clock
% sudo /etc/init.d/ntp start
 * Starting NTP server ntpd                                [ OK ]

All done. Enjoy.

[UPDATE 3/12/2008] It looks like this might be a semi-annual ritual: my system pulled the same schizo act when DST started this week. On Gutsy, ntp-server has become ntp. It’s easier springing forward than falling back, because sudo just times out when you set the clock forward.

[UPDATE 3/9/2009] A fall back and a spring forward with no problems. Whoopee.

July 25, 2007

A Dubious Assertion

Filed under: Tech — Chris @ 2:44 am

Being a conscientious software engineer, I try to be good about putting assert statements in my code. And being a verification guy, I find myself tempted to express fairly deep correctness properties in my assertions. And this fills me with such satisfaction, that I am such a wise and clever programmer, that I should do such things.

But then I’m trying to optimize some code so that it runs in something like an acceptable amount of time and for some reason I just can’t shake this routine out of its stupor… What’s going on here?

Don’t add assertions that change the asymptotic complexity of your algorithm. That’s just dumb. (Of course you can always compile your code with assertions turned off, but even in testing the difference between O(n) and O(1) can pinch.)

And now look at how much more wise and clever and self-satisfied I can be.

July 9, 2007

Changing your PATH in Emacs’ compilation mode

Filed under: Emacs, Tech — Chris @ 4:21 pm

[UPDATE: This is not really wrong, but not really right either. See below.]

I was a bit surprised at this problem, but I suppose most people use standard make or gcc to build… I want to build my project with a version of OMake that I have compiled and installed in my home directory. I have ~/tools/bin in my PATH, but for some reason M-x compile still gives me

/bin/bash: omake: command not found

The trick is that Emacs invokes the compile command in a non-interactive, non-login shell, which means that neither your .bash_profile nor your .bashrc (or any variations thereof) are going to get read.* The workaround is to set BASH_ENV to point to a script file that sets your PATHbash reads the file pointed-to by BASH_ENV in non-interactive mode. Here’s my solution:

# In ~/.bash_profile:  
. ~/.bashrc

# In ~/.bashrc:  
export BASH_ENV=~/.bash_env  

# In ~/.bash_env:  
export PATH=/home/chris/tools/bin:$PATH

There’s probably a good reason why this is a bad idea, but it works.

* A quick refresher course: .bash_profile is for login shells; .bashrc is for interactive, non-login shells; BASH_ENV is for non-interactive, non-login shells (which, confusingly, will probably be a sub-process of an interactive and/or login shell, which is why the above example works).

[UPDATE] The compilation shell being non-interactive and non-login is a red herring. While this is certainly the case, a non-interactive, non-login shell will inherit the environment of it’s parent process. So, for instance, if your PATH is properly set in your shell and you invoke Emacs from the command line, things should be fine.

What was really causing my problem is that I was invoking Emacs from the Gnome Panel. The environment that Emacs inherits in this case is Gnome’s, not Bash’s. How do you change the PATH in the Gnome environment? Um… Eh… gnome-session-properties? .gnomerc?

The solution I’ve settled on is to create a ~/.xsession file as follows,

  #! /usr/bin/bash

  if [ -f ~/.bash_env ]; then
    . ~/.bash_env

  exec gnome-session

where .bash_env is as above.

NOTE: If you leave off the last line, your X session will end before it begins. The .xsession script is the X process: when it ends, the X process ends. Execing gnome-session replaces the script process with the Gnome session process.

[UPDATE 2] Of course, another option is to just use setenv in your .emacs file. TMTOWTDI, in Emacs and Perl alike.

« Newer PostsOlder Posts »

Blog at