Wednesday, June 2, 2010

Trouble using Eclipse 3.4.x on Ubuntu Karmic

I was using Eclipse 3.5+ last months, but fo a project I needed to use 3.4. I downloaded three versions so far and they all die after trying to open or create a workspace: After the splash screen, an empty dialog appears which you can't even close.

I found the solution here: It appears that I had to add -Dorg.eclipse.swt.browser.XULRunnerPath=/usr/lib/xulrunner to eclipse.ini This is odd, since my /usr/lib/xulrunner is empty (except for a plugins folder, which has the flash plugin only?), and my xulrunner lives actually in /usr/lib/xulrunner-1.9.1.9. Anyway, it works with /usr/lib/xulrunner but it does not work with /.../...-1.9.1.9 -- for now!

(Another suggestion on that post is to add "-vm /path/to/your/bin/java" but I do not seem to need this).

Sunday, May 9, 2010

Google Codejam 2010 participants feeds

On May 7th the Google CodeJam 2010 started, with about 15,000 contestants in the Qualification round! If you are competing, you surely hit this blog looking for some stats.

I have not found any feed (yet) about participants. All I found was this thread from the google group: where Igor N. from Google said: we still have the AJAX requests that the scoreboard page uses to grab 20 rows at a time.

So I went ahead and grabbed, 20 rows at a time.... One bash command line that iterates and gets 15000/20 small json files, and a few python lines to parse and pretty print them. Here is how my output currently looks like (the scores for each problem overflow to the right):
## Country: Argentina
#210 (99): ged       [ 4:42:08]  [s 2:16:12 L 2:16:57]  [s 4:37:31 L 4:38:08]  [s 3:24:24 L 3:25:22]
#326 (99): lrearte   [ 6:47:22]  [s 6:46:17 L 6:47:22]  [s 6:43:08 L 6:44:32]  [s 6:34:26 L 6:36:44]
#408 (99): aurinegro [ 8:29:45]  [s 0:43:37 L 0:44:24]  [s 1:09:52 L 8:25:45]  [s 2:12:08 L 2:13:43]
#454 (99): axelbrz   [ 9:16:12]  [s 4:35:26 L 4:41:16]  [s 9:04:06 L 9:08:12]  [s 2:54:08 L 2:58:50]
#466 (99): dodi      [ 9:28:48]  [s 5:34:01 L 5:37:01]  [s 9:20:20 L 9:28:48]  [s 7:27:13 L 7:31:59]
#709 (99): fidels    [12:40:11]  [s 0:12:58 L 0:15:09]  [s 3:35:34 L 3:39:19]  [s12:37:54 L12:40:11]
(....)
There are more fields to show; basically everything shown in the scoreboard is obtained from these feeds so you can look for the extra data in the json files.

Feel free to use your script for yourself. I would love to hear similar pages or your own usage of these feeds.


Here is the python script (note that the bash command line to get the results is in a comment)
#!/usr/bin/python
import os
import json

## Run first:
## for i in `seq 1 20 10500`; do wget -O $i.json "http://code.google.com/codejam/contest/scoreboard/do?cmd=GetScoreboard&contest_id=433101&show_type=all&start_pos=$i&views_time=1&views_file=0&csrfmiddlewaretoken="; done
def time(pty):
  return "--:--:--" if pty<0 else "%2d:%02d:%02d" % (pty//60//60, (pty//60)%60, pty%60)
def problems(arr):
  s = ""
  c = 's'
  for t in arr:
    s += '   [' if c=='s' else ' '
    s += c+time(t)
    if c=='L': s += ']'
    c = 'L' if c=='s' else 's'
  return s

country='Argentina'
print "## Country: "+country

i=1
while True:
  try:
    f = open(str(i)+".json")
  except:
    exit
  if (f.closed): 
    break
  s = f.read();
  f.close()

  obj = json.loads(s)
  for coder in obj['rows']:
    if coder['c']==country:
      print "#%5d (%3d): %-30s  [%s]    %s" % (coder['r'], coder['pts'], coder['n'], time(coder['pen']), problems(coder['ss']))

  i += 20

Wednesday, April 21, 2010

Add a Java runtime to Ubuntu using update-alternatives

I just installed a Java JDK not using the package system. I wanted all users in this machine to be "aware" of this java runtime so the "java" command defaults to this implementation.

Ubuntu offers the "update-alternatives" utility to do this. This is both used to configure which of your (in this case) java implementations to use, but it can also be used to add a new one to the list. Here is the recipe (run as root, or sudo all commands):
# update-alternatives --install /usr/bin/java java \
  /opt/jdk1.6.0_14_x64/bin/java 100
# update-alternatives --config java

There is 1 program that provides 'java'.

  Selection    Command
-----------------------------------------------
*+ 1           /opt/jdk1.6.0_14_x64/bin/java

Enter to keep the current selection[+], or type selection number: 1
# java -version
java version "1.6.0_14"
Java(TM) SE Runtime Environment (build 1.6.0_14-b08)
Java HotSpot(TM) 64-Bit Server VM (build 14.0-b16, mixed mode)
Note that in my case, since this was the only Java installed, there was no need to configure it via --config. I just ran it to make sure this one was the current choice. Also, if you do not want the interactive prompt you can just run:
sudo update-alternatives --set java /opt/jdk1.6.0_14_x64/bin/java

Thursday, April 8, 2010

Skype video on Ubuntu 9.10

I had solved this long ago but reappeared in my relatively new Ubuntu 9.10 install: Skype (2.1.x) does not show video from my webcam; a usb Logitech QuickCam Pro 5000:
$ lsusb
Bus 001 Device 002: ID 046d:08c5 Logitech, Inc. QuickCam Pro 5000
I tried a few things and it turned out that the solution was something I had found that was supposed to aim a problem with 64bit systems and 32bit libraries. One needs to set the variable LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so. (That's the path in my Ubuntu, it may vary in other system).

Then, to launch Skype, I am using a small script:
#!/bin/bash
LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so skype
for which I also created a menu icon.

Sunday, March 28, 2010

Odd 1366x768 LCD res on Nvidia

I bought a LCD monitor (LG Flatron W1943S) months ago for my mother. This desktop PC runs Kubuntu 9.04 with an NVidia 6600 card. I had never been able to fix a problem: about 60 pixels of overscan to the right, which is very awful and annoying specially when you need to move scrollbar...

(My mother with infinite patience has moved too many windows to the left to pick these missing buttons... I would have already thrown the monitor out the window.)

Some further debugging today let me find this:

First, the native resolution 1366x768 is not supported by nvida (the card? the driver?). You need exact 16:9, or multiples of 8, I igore it -- the point is that you need to get the modeline for 1368 horizontal pixels; I used this to generate it and put it on xorg.conf:

$ gtf 1366 768 60
# 1368x768 @ 60.00 Hz (GTF) hsync: 47.70 kHz; pclk: 85.86 MHz
Modeline "1368x768_60.00" 85.86 1368 1440 1584 1800 768 769 772 795

(In Screen section, under a Display subsection, added Modes "1368x768_60.00")
It also works with 1360x768, I still don't know which one is better.

Then, the most important part was in the monitor itself: I read in a forum (about different hardware I think) that there was a "reset to factory defaults" in the monitor. So, afer setting this resolution, I navigated through the unintuitive OSD monitor menu, under Setup - in the last screen - last option is Factory Reset. That simply accomodated all the pixels within the screen! And easier: There is an "auto/set" button that appears to be the same! All this time I was looking for a xorg vs. drivers vs. monitor configuration issue, I never thought it would be that simple.

I am still trying to get a real 1:1 sampling, I see some pixels appearing as "blurred" horizontally. Suggestions are welcome...

Tuesday, March 23, 2010

Rosegarden, Lilypond, Timidity and my sax lessons

I started trying to write some decent music sheets, for my sax lessons. I wanted to find some free, opensource linux alternatives to programs like Sibelius, and indeed I found them!

Fortunately, all of them are in Karmic repositories, so I just apt-get install rosegarden and this installed Lilypond, a latex-based music-typesetting (if that's a word) system, and Rosegarden, a very good stand alone GUI that not only serves to write the music, but also allows listening via MIDI (something I could do yet, but I will...)

So this post is actually about how to use Rosegarden to save a MIDI file that Timidity can play (my Timidity install just worked, while Jackd soundsystem did not). So go ahead and type some music in Rosegarden. Then export it as a .mid file. Then, timidity file.mid should already work.

Sound fonts But, the default piano sound of my cheap soundcard is far from nice. I wanted to install some sound banks ("sound fonts"). There are some of them here.

Unpacking? I downloaded a file 1276-Soft Tenor Sax.sfpack. Now, how to open it? First problem, there is no sfpack-unpacker for linux. There is a small DOS utility here that runs fine under Wine, so I used it: run wine SFPACK.EXE, click Add Files, select the .sfpack file, and click Go. This unpacks the file 1276-Soft Tenor Sax.sf2, which is something the sound card (or the midi system) can use.

Installing. To use the soundfont, you must give Timidity a config file. There are many config files for several fonts here, but my file was not there. So I created a very raw configuration for it. First, comment the enabled "source" line in /etc/timidity/timidity.cfg, and add a new line source /etc/timidity/my.cfg. Then, edit that new file /etc/timidity/my.cfg, adding just this content:
bank 0
0 %font "1276-Soft Tenor Sax.sf2" 0 0 tune=-14 amp=31 pan=0
Note: I am using "-12", not "-14", so other MIDIs are played on tune as well... but the reasoning is still useful so I am leaving this version in this article (See update at the end)

what this does is creating a single program "0" on bank "0", using the .sf2 file given. (Note: I put that file also in /etc/timidity, otherwise type the full path in there). The tune parameter is explained below (you can omit it). The amp tells how much to amplify, and the pan can be used to balance it to left/right (I use it in another example to send different instruments to left and right channels).

Save it wav/mp3. I wanted this as an easily playable sound file, so I ran timidity input.mid -Ow -o output.wav to convert it. My music file was just one instrument, number 0, bank 0, so it now vaguely resembles a sax (better than the original piano, at least). I later converted it to mp3 and put it on my player to study listening to it.

Tune to Bb! One caveat: I typed whas was supposed to be in C, while my tenor sax is Bb. I could have exported to Midi one tone down from Rosegarden, but I missed it. Also, the way it was originally exported it was one octave higher than the way I play that music in my sax. That's the reason of the tune=-14 parameter in my .cfg file: 14 semitones down (12 semitones = shift 1 octave down; and another tone to tune it in Bb). Note: There is an alternate, better method -- see the update at the end

Swing! One more thing -- the song I am practicing was supposed to be played with swing rithm -- that is, octaves lasts 2/3 and 1/3 of the time of a half -- but we just type them all the same way, as regular octaves. I imagined there should be an easy formula or script to apply to a Lilypond file, that could convert a regular rythm to swing... and there is! In Rosegarden, use the Quantize option (after selecting the whole file), use type=grid, base=eight, swing=100%, and make sure to check "quantize durations". That's it! I did not saved the result, but only exported it to .mid, but it sounds perfectly :)


That was my experience from last night -- while children sleep I cannot play the sax, so doing this was a funny alternative!

Update (Apr 20th): While tuning 1 tone down im timidity.cfg is possible, it does of course has side effects. Every MIDI will be shifted down... quite undesirable. Later I found that Rosegarden allows to shift instruments, so most of them in my partiture (written fo four saxophones) just appear as "-2" (one tone down) or "10" (one octave higher, but still 1 tone down) to be played in Bb.

Thursday, February 25, 2010

Install Ubuntu from Alternate CD image; booting from USB flash drive

I recently tried a couple of ubuntu versions, installing them on a partition to play a few hours. In the process I re-discovered unetbootin, a wonderful tool for this: I burned the CD ISO images in a USB flash drive, instead of burning CDs (even if you use rewritable, it is slower than a USB key). UNetbootin let's you make a bootable pendrive from any ISO image; you can even download your favorite distro CD from there.

The main comment of this post is, however, not just the unetbootin process, but two tips that solved issues with these images.

First, the simpler one: You have to mark the partition in the USB drive as bootable, or you will not be able to boot... To do this, run fdisk /dev/sdb (or whichever your drive's device is), and add its boot flag.

The second on is subtler. With the Ubuntu 9.10 Desktop CD everything worked perfectly; I was able to boot. But later I tried the Alternate CD, which after booting it could not find the contents of the "CD" it was installing from. Somehow it missed the point it had boot from USB; so there would not be any contents on CD-ROM to read (in fact, that machine does not even have a CD drive). What I had to do was to add a flag to the kernel boot options: When UNetbootin starts, before pressing Enter on the "Default" option, press Tab to edit it. Edit the kernel line, to make it look like this one:
/ubnkern initrd=/ubninit vga=normal cdrom-detect/try-usb=true -- quiet

(Everything should be in a single line). Your line might not be identical; but the important part is to add "cdrom-detect/try-usb=true" before the "--". With this option the installer found the contents and was able to continue the rest of the install process.

Wednesday, February 24, 2010

Resizing a VirtualBox bootable WinXP drive

I have a couple of Windows images running in VirtualBox machines. (Yes I only boot linux, but still have a couple of windows images confined to their VMs). They ran out of diskspace; I created too small disks. I had attempted to solve this by adding increasingly larger secondary disks; but Windows does not like small "C:" partitions; sooner or later problems arise.

I found tips from several places about how to do this so I am going to compile my experience here. Since VDI images cannot be just resized (disk geometry can be altered), one needs to move the data to another VDI disk. The procedure is then: 1) Create a new (bigger) disk, 2) Clone the old disk into the new disk, 3) replace the disk in the virtual machine.

So far, that's more or less simple if the disk is not the primary, bootable disk. But I tried cloning with Acronis TrueImage, GParted and a couple of other tools, and they all resulted in an unbootable disk with "Disk reader error, press Ctrl+Alt+Del" message when trying to boot. I tried using the windows recovery console rebuild the MBR (fixmbr.exe) or the boot sector (fixboot.exe) but none of them worked. The extra tip was touching a parameter in the boot sector of the disk... find the details below.

Before you start, you might want to backup your entire VDI image; just in case (none of these steps will modify it... but there is always the case of selecting the wrong option).

All the steps then look like:
  1. Create the disk

    1. Shut down the virtual Windows machine
    2. From VirtualBox disk manager, create a new disk (bigger!), and attach it as secondary to that machine.

  2. Copy data. Use some cloning tool to copy the entire disk from the old disk to the new one. In my case, I found the simpler way was:

    1. Download a GParted LiveCD,
    2. Add it to the list of VirtualBox ISO images,
    3. Mount it on the virtual machine, and make sure the CDROM is first in boot order sequence.
    4. Boot GParted. Select the old disk/partition, click "Copy". Select the new disk, create on "Create Partition Table" (type "MSDOS"), then click "Paste" to bring the new data. In the resizing dialog, you can extend the partition to the end of the disk. Click "Apply" and it will take a while until the partition is copied. Then go to "Manage Flags" and enable the "Boot" flag.
    5. Shutdown the virtual machine; remove the ISO cd image.

  3. Enable the new disk (You might want to try seeing if the new disk just boots -- If you do not get a "Disk Read Error" message, skip next steps and you are done!).

    1. Start the virtual machine (still with the old disk as primary). You should be able to view the bigger, secondary disk, with the same contents as the old one.
    2. From within Windows, download Roadkil's Boot Builder. Then a) Read the boot sector of the NEW disk, b) change the "Heads" parameters to 255, c) write the sector back to the NEW disk. (Make sure not to screw up disk names! your old disk is still the backup.). See screenshot.
    3. Shutdown Windows. From VirtualBox, remove the old (smaller) disk, and leave only the new (larger) disk. Start up the VM, it will nicely boot up. (Well, Windows will boot up...)

I have no idea why that Heads parameter needs to be changed; but changing it from 128 to the magic 255 value worked for me (enlarging a 3Gb disk to 10Gb one) and others as well.

Happy cloning!