Monday, November 17, 2008

Emacs 22.3 on Windows

I've been using Emacs 21.3 happily for years. Since 2003 apparently, because I looked at the release dates today when I discovered a new version 22 had been released this year for the first time in a long time. Here's what I found.
  • Happily, the gnuclientw function has been integrated, as emacsclientw, and all that's needed in .emacs is (start server)
  • They recommend setting an environment var for some reason: set ALTERNATE_EDITOR to runemacs.exe
  • Now I can associate files with emacsclientw.exe to open them in my current emacs session. However, add the '-n' argument so it doesn't maintain a link to explorer, and ask you to hit a keystroke to release the editing buffer. A puzzling default behavior.
I also had to get rid of 'lazy-lock' and 'resize-minibuffer-mode' from my .emacs, but that was it. I turned off the toolbar, too, of course. Easy, painless upgrade.

I was surprised when it was slow to shut down the first time, but it has been much faster each time since. After a long time open, it is still noticably slow to shut down.

Thursday, November 6, 2008

Compact flash disk image with dd and cygwin

I found a way to make an exact duplicate of a compact flash card using cygwin. I suspect this method only works with identical flash cards - i.e. both the same capacity, and possibly both from the same manufacturer.
Anyhow, based on Reimaging CompactFlash cards tutorial, I looked in Computer Management, Disk Manager, and discovered my compact flash card was 'disk 2'
Then, using 'a' for disk 0, and 'c' for disk 2, at the cygwin command prompt:
dd if=/dev/sdc of=b2.img
It reports this, for a 32Mb flash card:
62592+0 records in
62592+0 records out
32047104 bytes (32 MB) copied, 10.725 s, 3.0 MB/s
Then, 'eject' the flash card in explorer, and insert the new one (to be erased and copied over). In cygwin again, note 'if' and 'of' swap:
dd of=/dev/sdc if=b2.img
62592+0 records in
62592+0 records out
32047104 bytes (32 MB) copied, 43.448 s, 738 kB/s

And it works! It's even bootable.
I'm still puzzled by a cygwin list suggestion, which has weird syntax for mounting the drive first. I tried it, and I got 'permission denied' when trying to write the image to the card, too. I think you want to treat it as a device, not a drive.

Update: I am able to copy the disk image onto a larger CF card, and all the data is preserved, but the CF is not bootable. An exact duplicate read from a 32Mb card and copied to a 32Mb card is bootable.

To fix that, I downloaded the latest syslinux, looked in the win32 subdirectory, and then ran this command (in cygwin), since my CF is the F: drive:
syslinux.exe -m -a f:
I also discovered that simply copying all the files, and then run the syslinux command above to make the CF bootable, works just fine too.

One more thing. The older version of syslinux allows 'append=' in syslinux.cfg, but the newer version doesn't like the '=' sign. Once I changed all occurences to 'append', it booted correctly. The older syslinux likes that format, too.

Wednesday, November 5, 2008

Bash script, filenames with spaces

Sometimes these things can be really annoying. Anyhow, good hint here:
Handling filenames with spaces in a bash for or while loop.
Helps loop over filenames which include spaces. Like most normal people do, nowadays.
I also got caught trying to extract substrings. We had the date embedded in the name of some backup files. The substring operator looks like this:
Get a substring, starting as position 19, 8 chars long.
I wanted from the end, so you make the position negative. But you have to use parens, otherwise it looks like the default-val operator
${file:(-19):8} and not ${file:-19:8}
Then I found that the year started with a zero, so it was getting treated as octal, and 08 is not a valid octal number. So I ended up with this to extract the 2 digit year into a integer var:
# 10# in front says 'use base 10', because the 08 was being interpreted as octal.
let file_year="10#${file:(-19):2}"
# get days by asking 'date' to convert the date string for us.
let file_days="10#$(date --date=${file:(-19):8} +%j)"
Just for your edification, here's how the end of that backup filename was generated:
suffix=$(date +%y-%m-%d_%H%M%S)

# add unique suffix (mbk = mirror backup)
All perfectly clear?

Tuesday, November 4, 2008

Election day, go libertarians.

I voted. I hope Mike Munger, the libertarian candidate for governor in NC, gets his 2%, so he can automatically be on the ballot next time. I think that's the condition....