Karmic RC sound problem

Installed Karmic release candidate. Trying to play various media. Oops. Attempts to get plugins for Firefox failed but fortunately I know the magic trick:

sudo apt-get install ubuntu-restricted-extras

OK. But no sound to hear the media with. I seemed to fix the problem with two small changes under System>Preferences>Sound>Output. I changed the device for sound output from one option to the other (both labelled “Internal Audio Analogue Stereo”) AND the connector from “Amplifier” to “No amplifier”. No idea why those weren’t set correctly for my system from the get-go and no idea why they’re relevant – just grateful to be hearing sound :-). My soundcard is a Soundblaster Audigy 2.

BTW the command cat /proc/asound/card0/codec#* | grep Codec didn’t work for me as the only thing similar in the rough location was cat /proc/asound/card0/codec97#0/ …

Python fits in my brain – no accident

One of the things I like about Python is the way I can hold so much more in my brain without having to look stuff up. If you know the tools for working with sequences (strings, lists, tuples, dictionaries etc), you know what to do with anything that is a sequence. Data from a database can be handled using the standard tools for processing lists and tuples etc etc etc. You don’t need to know how ADO differs from DAO etc. This is no accident – it was by design. Anyway, it was nice to see that a prominent programmer feels the same way about Python:

Bruce Eckel: They say you can hold seven plus or minus two pieces of information in your mind. I can’t remember how to open files in Java. I’ve written chapters on it. I’ve done it a bunch of times, but it’s too many steps. …

The other issue is the effect of an interruption. If you are really deep into doing something and you have an interruption, it’s quite a number of minutes before you can get back into that deeply focused state. With programming, imagine you’re flowing along. You’re thinking, “I know this, and I know this, and I know this,” and you are putting things together. And then all of a sudden you run into something like, “I have to open a file and read in the lines.” All the clutter in the code you have to write to do that in Java can interrupt the flow of your work.

Another number that used to be bandied about is that programmers can produce an average of ten working lines of code per day. Say I open up a file and read in all the lines. In Java, I’ve probably already used up my ten working lines of code for that day. In Python, I can do it in one line. I can say, “for line in file(‘filename’).readlines():,” and then I’m ready to process the lines. And I can remember that one liner off the top of my head, so I can just really flow with that.
http://www.artima.com/intv/aboutmeP.html

64-bit Jaunty guest on 32-bit Jaunty host with VirtualBox

If your processor supports 64-bit you can run a 64-bit OS on top of your 32-bit OS using VirtualBox. Which can be very useful e.g. for testing an application you are developing in different environments.

Your CPU must support 64-bit. To test (thanks http://www.cyberciti.biz/faq/linux-how-to-find-if-processor-is-64-bit-or-not/):

grep flags /proc/cpuinfo

and look for lm (long mode) .

Your BIOS must support 64-bit. I believe it will usually be set correctly if using something like a Core 2 Duo CPU but that needs confirmation.

Install a 64bit version of Linux. NB the correct Ubuntu package will say AMD64 even if it is for an Intel CPU because of some licensing deal. E.g. “Alternate install CD for 64-bit PC (AMD64) computers (standard download)” is still the correct option even if using an Intel Core 2 Duo CPU.

Apparently, “A 64 bit host CPU is not enough to run 64 bit guests (in contrast to VMWare). It must also have virtualization extensions. ” (https://help.ubuntu.com/community/VirtualBox/Installation). See http://en.wikipedia.org/wiki/X86_virtualization for a list of supported CPUs.

To confirm your OS is 64-bit

uname -a

Finally, here is relevant information from the VirtualBox User Manual:

Starting with Version 2.1, you can even run 64-bit guests on a 32-bit host operating
system, so long as you have sufficient hardware.
In particular, 64-bit guests are supported under the following conditions:
1. You need a 64-bit processor with hardware virtualization support (see chapter 1.2, Software vs. hardware virtualization (VT-x and AMD-V), page 11).
2. You must enable hardware virtualization for the particular VM for which you want 64-bit support; software virtualization is not supported for 64-bit VMs.
3. If you want to use 64-bit guest support on a 32-bit host operating system, you must also select a 64-bit operating system for the particular VM. Since supporting 64 bits on 32-bit hosts incurs additional overhead, VirtualBox only enables this support upon explicit request.

and

VirtualBox’s 64-bit guest support (added with version 2.0) and multiprocessing (SMP, added with version 3.0) both require hardware virtualization to be enabled. (This is not much of a limitation since the vast majority of today’s 64-bit and multicore CPUs ship with hardware virtualization anyway; the exceptions to this rule are e.g. older Intel Celeron and AMD Opteron CPUs.)

Ubuntu Karmic Alpha 5 Editing GRUB2

I used to know how to edit /boot/grub/menu.lst to change the order of Operating Systems (e.g. Windows XP, Ubuntu Jaunty, Ubuntu Karmic, and Kubuntu Jaunty), set the default, and set the delay. But with alpha 5 of Ubuntu Karmic that has all changed with the introduction of GRUB2. Here’s what I did instead.

Your goal is to change /boot/grub/grub.cfg but you shouldn’t do that directly. You should change some config files and then run a special grub update command.

Open one of the config files for other OSs (as root):
sudo gedit /etc/grub.d/30_otheros
[update]
sudo gedit /etc/grub.d/30_os-prober

I commented out redundant entries e.g. different kernel versions, and then saved it.

Then edit the main grub config file:
sudo gedit /etc/default/grub

I changed the relevant line to:
GRUB_DEFAULT = 4
so that the 5th item (0,1,2 …) would boot by default.

Finally, run the grub update command to regenerate /boot/grub/grub.cfg:
sudo update-grub

You can check the result in /boot/grub/grub.cfg to see everything went well.

Not a lot trickier than under plain GRUB and apparently GRUB2 has a lot of possible benefits depending on your circumstances (http://www.gnu.org/software/grub/grub-2.en.html).

BTW GRUB2 has attracted some controversy and there are some interesting points in the following article and its comments (http://aronzak.wordpress.com/2008/09/30/stay-away-from-grub2/).

F-spot and the date sort order of pre-digital photos

F-spot is very useful but it has a few quirks which can be very confusing. Especially if you are working with photos which do not come from a digital camera (e.g. scanned, taken from the web etc). The order in which they display, and the dates under which they are stored, can be quite confusing. And quite difficult to adjust.

First, some background. When a digital camera takes a photo a whole lot of information (metadata) is stored with the photo e.g. camera band, exposure time, date taken. The latter seems to influence the order a photo displays in F-spot, not the date of creation*, or the name of the photo.

Here is an example:

> Image Type: jpeg (The JPEG image format)
> Width: 2272 pixels
> Height: 1704 pixels
> Camera Brand: Canon
> Camera Model: Canon PowerShot G2
> Date Taken: 2004:04:16 12:12:22
> Exposure Time: 1/199 sec.
> Aperture Value: 4.00 EV (f/4.0)
> Flash Fired: Flash did not fire, auto mode.
> Metering Mode: Pattern
> Focal Length: 7.0 mm
> Software: f-spot version 0.4.3.1

Photos like this are stored and sorted by F-spot much like you would expect. But what do you do with images which didn’t come from a digital camera?

One option is to manually change the datetime of the image. To do this, select a photo, then from the main f-spot menu Edit > Adjust Time. If you change the time, you also change the sequence.

For further information on F-spot there is a great article here – http://www.linuxjournal.com/article/9110.

* I wrote a little python script utilising the Python Imaging Library (PIL) which created new versions of the photos in the order I wanted and gave a creation date accordingly. Didn’t solve the F-spot ordering problem though.

Printing Scripts from Eclipse in Ubuntu

Printing scripts can be very useful – but not if the font size is enormous. Unfortunately, eclipse (3.4.1) under Ubuntu (Jaunty) had exactly this problem (see also http://www.coderanch.com/t/106543/IDEs-Version-Control-other-tools/Printing-eclipse). A solution I found was to shrink the font, print, and then restore the font. Given that I hardly ever want to print scripts (only when I’m really, really stuck and dealing with a complex piece of code) this is an acceptable workaround.

But how do you change the font? Doug Hughes supplied the answer here – (http://www.alagad.com/go/blog-entry/changing-the-font-size-in-eclipse). In Ubuntu it is Window>Preferences>General>Appearance>Colors and Fonts>Text Font. Because of the hundreds of options available, it can be very difficult to find the ones you need most.

Full-screen Warcraft under Wine

Dimitar Boichev shows how you can play games like Starcraft and Warcraft in full-screen under WINE in his Full Circle article (Better Game Speed With X).

Here is what worked for me (minor changes from what Dimitar did):

sudo gedit /etc/X11/Xwrapper.config

Change:

allowed_users=console
to
allowed_users=anybody

Then save and quit.

Applications>Wine>Configure Wine select the game you want under applications and then, under Graphics, make sure you untick “Emulate a virtual desktop”.

I also copied /etc/X11/xorg.conf as /etc/X11/only_one_monitor.conf so that I could handle my dual monitor setup by playing Warcraft full-screen in one monitor only. I needed to change:

"TwinView" "1"
to
"TwinView" "0"
i.e. turn dual (twin) view off

Then I created a bash script with the following content (NB to use your username and the correct path to your game) and saved it to my desktop:

#!/bin/bash
X :2 -ac -terminate -config only_one_monitor.conf & sleep 2
DISPLAY=:2 nice -20 env WINEPREFIX="/home/username/.wine" wine "c:\Program Files\Warcraft III\Warcraft III.exe"

NB there are only 3 lines – the line starting DISPLAY goes to the end.

Then make the bash script executable (under the file’s Properties>Permissions>Execute – tick the tickbox). Double click it and select run to enjoy full-screen Warcraft etc.

Ctrl+Alt+F7 and Ctrl+Alt+F9 lets you switch between X windows.

One further way of improving your Ubuntu Warcraft experience – grab the latest patches. Then there will be no need to have the CD in the tray to play plus some other enhancements. NB not to confuse Warcraft The Frozen Throne (TFT) with Reign Of Chaos (ROC).

A key link is here – http://www.tipsfor.us/2009/06/04/install-warcraft-3-on-ubuntu-linux-a-visual-guide/ thanks to Brian. You can also grab some nice icons.

For reference, the files I needed were War3ROC_122a_English.exe and then War3Patches_ROC_122a_123a_enUS.exe.