June 14, 2009

Civilization in Wine on Linux. How civilized.

I have the Civilization IV: the Complete Edition DVD sans DRM. It works pretty well under Wine. But this is what it took (Ubuntu 8.10, aka Intrepid):

I find it makes life easier to segregate my Wine apps, so first steps were:

export WINEPREFIX=/usr/local/civ
winecfg

There, I set Wine to also consider /usr/local/civ to be where my My Documents folder was, so the game would create its "My Games" folder there instead of under my real Linux home directory.

Wine 1.1.22. It failed with Wine 1.1.23, the current development release.
Used winetricks to install d3dx9 and msxml3
Needed this to get around a stupid sound bug:

mkdir -pv $HOME/.kde/socket-$HOSTNAME

Then just running

wine setup.exe

on the file at the top level of the DVD did the rest. I selected "custom install" so I could set a less long, obnoxious installation path than the default. I installed the just-released Beyond the Sword 3.19 patch.

I put Blue Marble on top of that, and ran vanilla Civ, Warlords, Beyond the Sword, and Colonization once each to create the appropriate folders under My Games, and to set the graphics and audio options to my preferences.

I edited each of the CivilizationIV.ini files in their respective directories under the installation directories to set NoIntroMovie = 1 and EnableVoice = 0. (The first is just by preference; the intro movies worked fine. The default EnableVoice = 1 resulted in a warning under Warlords, but not the others. Strange.) It didn't work to set these just in the CivilizationIV.ini files under My Games, which I would have thought was the point.

Finally, I backed up the results so I won't have to do all that again when I inevitably screw something up while playing with mods.

The startup scripts are simply like this:

#!/bin/bash
WINEPREFIX=/usr/local/civ 
/usr/bin/wine /usr/local/civ/drive_c/Program\ Files/civ4complete/Civilization4.exe $@

Everything but a few cosmetic details works. Unit health bars don't, city progress bars on the main map don't (this can be ameliorated by requesting detailed city info in the options), the cursor animation doesn't work, so it doesn't turn into a little spinning globe when you're waiting. So far as I can tell, everything else works. (And my words are backed by a Holy Roman spaceship at Alpha Centauri.)

June 12, 2009

Ruby string escaping weirdness

Well, that's odd... (ruby 1.8.7)

irb(main):021:0> '\\' + 'x'
=> "\\x"
irb(main):022:0> "x".gsub("x",'\\' + 'x')
=> "\\x"
irb(main):023:0> '\\' + '&'
=> "\\&"
irb(main):024:0> "&".gsub("&",'\\' + '&')
=> "&"

March 3, 2009

Recycling Palms as secondary LCD displays

Recently, I’ve had a crush on the computer lcd front panel displays you can find here or here. But they’re either tiny or expensive.

I remembered a project to let you use a Palm in its cradle as an LCD display. PalmOrb has been orphaned since 2005, and, as of the last version, indicates you’re on your own with USB Palms (which are the only ones I have left.) It actually worked decently with LCD4Linux. But it only left you with a tiny block of text, and it was harder than I’d like to customize the output.

So I tried simply running ptelnet, a Palm telnet app, to make a serial connection, and running a script that wrote to /dev/pilot (I had the visor module loaded), clearing the screen every minute (with VT100 escape codes) and sending status info.

It works pretty well, but the text is tiny, with no way to change the size. Anyone know of an alternative to ptelnet to just receive data from the serial connection and display it, that allows you to change fonts?

February 13, 2009

New and improved emacs launcher

I'm much happier with this combination. /usr/local/bin/editor is:

#!/bin/bash ALTERNATE_EDITOR=/usr/local/bin/editor2 emacsclient -c "$*"

/usr/local/bin/editor2 is:
#!/bin/bash
EMACS=/usr/bin/emacs
EMACSCLIENT=/usr/bin/emacsclient
SOCKET=/tmp/emacs`id -u`/server

$EMACS --daemon

count=25

while [ $[ count-- ] -gt 0 ]; do
if [ -e $SOCKET ] && [ ! (lsof $SOCKET &> /dev/null) ]; then
$EMACSCLIENT -c "$*"
break
fi
sleep .2
done

Among the advantages here over the old one:

emacs --daemon is only run if emacsclient can't find a socket, as opposed to emacsclient encountering any error

The old one slept for 1 second after launching the daemon. This was occasionally too short, but usually too long. This one checks for the socket five times a second, and gives up after five seconds. (There are imaginable race conditions that could give undesirable results, but I don't expect to ever actually encounter them.)

February 3, 2009

Daemon Emacs

A nifty feature in the current development version of Emacs (now available in a pretest release candidate) is that you can start it as a daemon, to which graphical and terminal clients alike can attach. A not so nifty lack of feature is there being no easy standard way to do the obvious: launch a client if the daemon's running; if it's not, start the daemon, and then launch the client. So everyone cobbles together their own. Here's mine, which cribs from here.

#!/bin/bash
if [ -z $DISPLAY ] ; then
OPT="-t"
else
OPT="-c"
fi

if [ -z "$*" ]; then
OPT="$OPT -e (raise-frame)"
else
OPT="$OPT $@"
fi
emacsclient $OPT 2>/dev/null || (
(emacs --daemon)
sleep 1
emacsclient $OPT)

I have that as /usr/local/bin/editor. To stop emacs nicely, and get prompted to save unfinished business, I have another script with:

/usr/local/bin/editor -e '(save-buffers-kill-emacs)'

October 13, 2008

My own virtual Ubuntu Intrepid

  1. Make sure your CPU supports virtualization (you may have to turn it on in the BIOS)

    cat /proc/cpuinfo |egrep '(svm|vmx)'

    If you get no response, it doesn't. A response means you're good to go.

  2. Download the Ubuntu Intrepid Beta alternate install CD

  3. install qemu and kvm

    sudo apt-get install qemu kvm

  4. create the disk image that will serve as the virtualized intrepid's hard drive

    qemu-img create -f qcow2 intrepid.img 6G

  5. start the vm, booting the Intrepid CD

    sudo kvm -cdrom ubuntu-8.10-beta-alternate-i386.iso -hda intrepid.img -boot d -m 256M

  6. Hit F4 to choose a command-line install; go through the installation.

  7. When the installation finishes and reboots, kill the VM. Restart it with:

    sudo kvm -hda qemu/intrepid.img -boot c -m 256M -redir tcp:2222::22 &

  8. In the VM, turn off apt-get automatically installing recommended packages

    echo 'APT::Install-Recommends "false";'|sudo tee /etc/apt/apt.conf

  9. In the VM, Edit /etc/apt/sources.list to point to the closest mirror

  10. In the VM, Bring yourself up-to-date and install openssh-server

    sudo apt-get update sudo apt-get upgrade sudo apt-get install openssh-server

  11. On your real machine, ssh into the VM.

    ssh -p 2222 username@localhost

  12. Have fun with your new virtual Intrepid.

September 22, 2008

xterm made easy

I’m a fan of the rxvt-unicode terminal emulator, but it has one problem: it sometimes spaces xft fonts badly, with conspicuous gaps between the characters, making for fewer characters per line.

Looking into alternatives, I found that the GTK library includes vte, a terminal emulator widget that a bunch of terminal emulators use. And they all look good, but had a drawback I couldn’t live with: none of the ones I tried recognized my Meta-keys, which I’ve grown used to using for command-line editing in my shell.

vte, along with the Ruby GTK bindings, makes life so easy, I just rolled my own. This is just the Ruby vte demo program that comes with the bindings with a couple of lines added to handle Meta-keys.

require "vte"

window = Gtk::Window.new("Terminal sample")
window.signal_connect("destroy"){Gtk.main_quit}

vte = Vte::Terminal.new
vte.set_font("DejaVu Sans Mono 16", Vte::TerminalAntiAlias::FORCE_ENABLE)

Gtk.key_snooper_install {|t, e| 
  vte.feed_child("\e")  if e.state.meta_mask? and e.event_type == Gdk::Event::KEY_PRESS
}

vte.signal_connect("child-exited") do |widget|
  Gtk.main_quit
end
vte.signal_connect("window-title-changed") do |widget|
  window.title = vte.window_title
end
vte.fork_command
window.add(vte)
window.show_all

Gtk.main

September 16, 2008

Fastest Ubuntu mirror for you

I recently learned about netselect-apt, a Debian package to find the fastest Debian mirror. Ubuntu Hardy includes it, but it's worse than useless -- it's still hard-coded to work with Debian. But it's easy enough to reproduce its essential functionality.

sudo apt-get install netselect
wget --no-check-certificate -O mirrors https://launchpad.net/ubuntu/+archivemirrors
sudo netselect -v -s 5 $(perl -F'"' -ane 'print "$F[1] " if (/United States/ .. /highlighted/) && /http/' mirrors)

That gives the top 5 (from fastest to slowest) in the US using http. It should be reasonably clear how to adjust the number returned, the country, or the protocol (which could be 'ftp' or 'rsync'.) It erroneously considers canonical.com a mirror in Viet Nam (it fails to find the end correctly for the last country in the list), but there's only one mirror in Viet Nam, and this is a quick hack, so I can live with that.

June 18, 2008

PDF Viewer

I don't use a desktop environment; I use an antidesktop environment featuring the ultra-minimalist ratpoison window manager and the ultra-maximalist Emacs.

It makes me grumpy when applications depend on installing huge portions of Gnome or KDE. So I was never thrilled with the PDF viewer choices.

ghostview and xpdf are good tools, but ugly, and they don't natively talk to CUPS print servers. evince and kpdf want to install huge portions of Gnome and KDE, respectively. I haven't tried acroread, but I scramble for alternative's to Adobe's bloated reader in Windows, so I thought I'd spare myself.

So I was happy to find epdfview, which shares some of evince's dependencies on graphics libraries without the gratuitous dependencies.

But there was a catch: Ubuntu 8.04's binary package doesn't include CUPS support, for no apparent reason (there's already a bug filed.) The good news is that you can build it yourself.

So I'm now a happy viewer and printer of PDFs while still avoiding having dbus, gamin, bonobo, etc., installed.

October 4, 2007

First look at Ubuntu Gutsy Beta

The forthcoming Ubuntu release, 7.10, the Gutsy Gibbon, is scheduled for release next month, 10/18. I recently tried installing it, and quickly encountered this bug, reported as fixed yesterday.

Ubuntu had inherited from Debian a problem whereby network interfaces' names can be inconsistent from one reboot to the next. The installer identified my mobo's wired network interface as eth1. On rebooting, the OS decided it was eth2, but /etc/network/interfaces had been configured to use the (now non-existent) eth1, hence no network.

In days' past, I've used /etc/iftab to ensure it didn't recur, but, apparently, as of Gutsy, this approach is deprecated, and the shiny new method is to use udev.

I then spent much time bashing my head against trying to arrange to boot into an encrypted root filesystem within an LVM2 logical volume on an encrypted LUKS partition, similar to this but using yaird to create the boot image. This is something I've done in the current Ubuntu release, Feisty. But I ran into a couple of bugs in Gutsy's yaird package. (The trivial one also existed in Feisty, but I didn't report it then.)

It'd be nice if Ubuntu offered an encrypted root installation option like Debian Etch, but I'd probably want enough things different from any set of options offered to end up doing it manually anyway.

I'm pretty sure I know how to fix the problem now. But I haven't had the time to take another crack at it, so my first look has been stalled here.

Maybe when I'm done, I'll write yet another encrypted root howto.

July 3, 2007

Seeking Random Numbers. Must pass Chi-Square test. No freaks.

Pocahontas had some little webcam she'd gotten a while ago as a promo item for signing up with an ISP. For a while, I've had in the back of my mind to use it to build a LavaCan. Because, you know, every home needs a cryptographically secure source of random numbers in hardware. Well, it seems like people were lucky to get this camera working with an allegedly supported OS. This guy heroically analyzed the signal between the PC and the webcam and came up with some sort of picture, but his write-up falls short of providing code.

Oh well. The Weecam's off to the Alameda County Computer Resource Center, and I'll give iwrandom a try. (But a webcam in the dark is so much cooler, drat it.)

June 15, 2007

Apt-get globally, gem locally

It seems that Debian packages and Ruby gems don't play nicely together. I had apt-get installed rails, and my first attempt to use a rails app (someone else had written) blew up because it had an internal check for a Rails gem of a certain version. Since my Rails hadn't been installed as a gem at all, it immediately failed.

So far as I can read on the Interwebs, most people facing this install rubygems as root, and do their subsequent gem installs as root, letting them write wherever in the filesystem they like.

That makes me queasy. I don't want to mix two package systems in the same environment.

So here's how I installed ruby/rubygems/rails in Ubuntu 7.04, with all gems under /usr/local.

Following the ruby1.8 package's own instructions for a full Ruby 1.8 distribution:

sudo apt-get install ruby1.8 ruby1.8-dev ri1.8 rdoc1.8 irb1.8 ruby1.8-elisp ruby1.8-examples libdbm-ruby1.8 libgdbm-ruby1.8 libtcltk-ruby1.8 libopenssl-ruby1.8 libreadline-ruby1.8

I assign ownership of /usr/local and everything under it to the admin group, and make /usr/local and its subdirectories group-writable (per Ubuntu's defaults, my primary login, which I created during installation, is a member of the admin group.)

sudo chown -R root:admin /usr/local 
sudo chmod 775 /usr/local /usr/local/*

I get and install rubygems.

mkdir /usr/local/lib/rubygems
export GEM_HOME=/usr/local/lib/rubygems
cd /usr/local/src
# as of this writing, the latest rubygems from http://rubyforge.org/frs/?group_id=126
wget http://rubyforge.org/frs/download.php/20989/rubygems-0.9.4.tgz
tar xzf rubygems-0.9.4.tgz
cd rubygems-0.9.4
ruby setup.rb config --prefix=/usr/local
ruby setup.rb setup
ruby setup.rb install

I add the following to my .bashrc, but you'll want them in any environment using gems. With multiple users on a system, you might want to put this in /etc/bash.bashrc.

export GEM_HOME=/usr/local/lib/rubygems
export RUBYLIB=/usr/local/site_ruby/1.8
export RUBYOPT=rubygems
export PATH=$PATH:/usr/local/lib/rubygems/bin

The grand finale:

source .bashrc # or wherever you put them
gem install rails --include-dependencies

It's that easy!

References:

April 14, 2007

Tolerance

I enjoyed this take on an Emo Philips joke (found on the Church of Emacs page.)

I asked my email-pal: "UNIX or Windoze?". He replied "UNIX". I said "Ah...me too!".

I asked my email-pal: "Linux or AIX?". He said "Linux, of course". I said "Me too".

I asked him: "Emacs or vi". He replied "Emacs". I said "Me too. Small world."

I asked him: "GNU Emacs or XEmacs?", and he said "GNU Emacs". I said "oh, me too."

I asked him "GNU Emacs 19 or GNU Emacs 20"? and he said "GNU Emacs 19". I said "oh, me too."

I asked him, "GNU Emacs 19.29 or GNU Emacs 19.34", and he replied "GNU Emacs 19.29". I said "DIE YOU OBSOLETE NOGOOD SOCIALLY MALADJUSTED CELIBATE COMMIE FASCIST DORK!", and never emailed him again.

Ubuntu Linux 7.04 beta, GNU Emacs 23.0.0.1 alpha, with Xft support. But I'm reformed -- any Linux or BSD distro and Emacs flavor is OK by me. (Everyone else can DIE!)

December 7, 2006

Movable Type 3.2+ Annoyances

The default individual entry archive template includes a block of template markup for posting comments... but that block doesn't support Typekey authorization. You need to boost the markup from the comment preview template.

The text boxes on the edit entry page are tiny little things, because mt-static/styles.css is missing an entry for the full-width class. This can be fixed by putting this in your mt-static/user_styles.css:

.full-width { width: 100%; }

October 16, 2006

But am I paranoid enough?

This security professional is so paranoid that Bruce Schneier thought he had to be kidding.

And for Bruce Schneier, SHA-1 is merely a compression algorithm.

October 13, 2006

(The awful truth)

The truth about Lisp:

If you're good enough to use lisp, you'll soon be frustrated with lisp. Lisp is not an adequate lisp. By the time my bus had made it two blocks I'd written some simple lisp macros that were so powerful they made lisp completely obsolete and replaced it with a new language. Fortunately, that new language was also called lisp. And i was able to prove, mathematically, that the new lisp i'd created was both far superior to lisp in every conceivable way, but also exactly equivalent to lisp in every possible way. I was very excited by this. But also found it very boring.

October 12, 2006

Black magic square root computation

Computing square roots through subtracting half the operand from a magic constant actually works tolerably well.

It brought to my mind the treacherous optimization of grep.

October 11, 2006

A subversive life

Keeping your life in subversion is a really good idea I really should implement.

October 10, 2006

All the bandwidth you can't use

When I first heard of FIOS, Verizon's fiber-optic Internet service provision, I was amazed: 15 Mbps downstream and 2 Mbps upstream for $44.95 a month? But the devil's in the details.

The consumer offers do not permit customers to host any type of server, personal or commercial.

And they block port 80 and inbound port 25, the standard ports for HTTP and SMTP.

Too many things could be accurately termed servers for this to be meaningfully enforced without outraging all of their customers. Allow remote desktop connections in Windows XP Pro, and you're running a server.

Nearly anything useful you could do with any significant percentage of that upload speed could be described as operating a server. Clearly, they have no intent of enforcing the rule to the letter, or they'd be forbidding a lot of things that most of their customers want.

But it gives them a means of cracking down on anyone daring to actually make use of that upload speed.

This is false advertising + plausible deniability.

October 9, 2006

Beautiful Data

I am scheduled to take Edward Tufte's Presenting Data and Information one-day class in San Francisco in December.

Envy me.

Here's a story about two Sun engineers showing a new UI to Tufte.

We were very proud of our user interface and the fact that we had a way to browse 16,000(!!) pages of documentation on a CD-ROM. But browsing the hierarchy felt a little complicated to us. So we asked Tufte to come in and have a look, and were hoping perhaps for a pat on the head or some free advice.

He played with our AnswerBook for about 90 seconds, turned around, and pronounced his review:

"Dr Spock's Baby Care is a best-selling owner's manual for the most complicated 'product' imaginable -- and it only has two levels of headings. You people have 8 levels of hierarchy and I haven't even stopped counting yet. No wonder you think it's complicated."

Oh.

October 6, 2006

The very model of a modern major database

Is it just me, or is Sqlite3 goofy?

I am the very model of a modern major database,
For gigabytes of information gathered out in userspace.
For banking applications to a website crackers will deface,
You access me from console or spiffy user interface.

My multi-threaded architecture offers you concurrency,
And loads of RAM for caching things reduces query latency.
The data is correctly typed, a fact that I will guarantee,
Each datum has a data type, it's specified explicitly.

October 5, 2006

House, S.D. (Senior Developer)

Sumana's title makes this funnier. If House were a software engineer (the character names are complicated acronyms):

Black sidekick improbably even thicker than the other two and pompous with it: The error message does imply some sort of dynamic linkage.

Me, gravely: Error messages always lie.

Necwfh: So what shall we do?

Me: Double the RAM, update the virus checker, scan the string tables, log the exceptions and put it on a sampling profiler.

Bsietttotapwi: How will this help isolate the problem?

Me: It won't, you moron. We've got 45 minutes to fill. It would be fatal to make a correct diagnosis this early in the episode. And while you're up, go have a look round the original programmer's auntie's holiday cottage in Cornwall. I've a feeling we may discover an Important Clue there.

October 4, 2006

How much I hate Windows

It can be easy to forget how much I hate Windows.

A couple of weekends ago, I planned to install Ubuntu Edgy Knot 3 on a new hard drive. I'd been mostly planning on leaving off Windows entirely, but I'll probably want to play Civilization 4 some day -- its price is finally dropping, and there have been two patches released. What the heck, thought I, I'll install Windows.

Windows is fussy about being the first thing on the disk, so I went to install it first. I didn't take notes on the process, so I may err in some of the details that follow, especially on the exact order of things.

The disk partitioner was crude and unfriendly. There was no solicitation of keyboard preferences beforehand, so I had to operate it in QWERTY rather than my preferred Dvorak. My Windows XP CD is an update SP2 disc, so I had to pop my Windows 2000 CD in and out to prove I was eligible to use the update disc. And type in a long ugly string from the packaging. The installation took a long time, but didn't require more attention.

Rebooted into Windows. Balloons popped up about having 30 days to activate, and my system may be at risk. Well, actually, I couldn't activate, and my system was not at risk, because I had no Internet access -- it had failed to install a driver for my ethernet hardware -- an Intel chip on a 4-year-old Dell server whose motherboard is a clone of an Intel motherboard, so we're talking cutting-edge esoteric hardware, you understand.

Dug up the driver CD that came with my machine. Installed the ethernet driver. Went to Internet Options and set my home page to update.microsoft.com, the only page I ever want to use IE for, and disabled ActiveX controls everywhere else. Opened IE. It chugged for a while, and then said I needed to update my Windows Update version (to include, among other things, Windows Genuine Validation.) I did so. Had to reboot; did so.

Realized I forgot to take the driver CD out; had to wait for it to boot to that so I could exit gracefully and reboot into Windows. Went back to update. It chugged for about a minute, then said I needed to validate before I could update. Tried to validate. It told me I had to activate before I validated. I activated, crossing my fingers that changing the hard drive (again -- I'd done it in the past with Windows installations on this machine) wouldn't cross the threshold of hardware difference that would require me to talk to Microsoft to make a case that I deserved to install their OS. It didn't -- woo hoo! Then I went back to update. Chugged for a minute again, but then I could finally validate.

Looked through the 60-some-odd updates. Declined to install the one where they'd run a service in the background to check whether my OS was legitimate and pop up warnings if it wasn't. Installed them. Rebooted.

Then I went about installing all the things I wanted to have some sense of security on a Windows box -- firewall, antivirus, Firefox, startup control monitor, the TweakUI powertoy so I could disable autorun on all drives current and future.

Then I installed Edgy.

Had a much better tool to partition the remainder of the drive. Answered some questions about locale, including getting to select Dvorak before I had to do any typing. It recognized my ethernet hardware. Spent a while installing things (a much shorter while than Windows), I rebooted, and there I was.

Yeah, there are some bumps in the road with Linux, usually having to do with using hardware whose use the manufacturers support only with Windows, or using software to handle propietary formats, which tend to come with licenses that preclude a free Linux distribution from installing by default.

But, on balance, I find installation and maintenance of Ubuntu to be easier than Windows.