New hardware ordered: printer and kitchen computer

The kitchen computer project will be powered by a black ASUS EeeBox B203! The ancient 800 MHz (VIA Samuel 2 crap CPU) Mini-ITX machine I use for the prototype is very slow, has issues with the USB network adapter (NetGear WG111v3, ID 0846:4260),  and freezes occasionally so it will be retired soon! I will try to use Ubuntu Netbook Remix on the EeeBox.

I also ordered a new network laser printer, and actually not an HP! It’s a Samsung ML-2851NDR. The OpenPrinting database says that the very similar model Samsung-ML-2851ND works perfectly so I hope that the “R” does not mean “Requires Microsoft Windows”. It was cheaper than the HP LaserJet P1505N, even though the Samsung has duplex support and the HP does not.  Hopefully I will not share the experiences in this negative Samsung ML-2851NDR review.

Firefox 3.0 freezes waiting to resolve safebrowsing-cache.google.com in DNS

My current daytime setup is for various reasons a Windows XP installation with Ubuntu Jaunty running inside VirtualBox. I use Microsoft Windows for Outlook, SQL Navigator and some web browsing while using the Linux installation for development. This morning I started Firefox in Windows XP, changed focus to VirtualBox or some other window, and when I returned to Firefox it was frozen. I followed the standard Windows trouble-shooting procedure: reboot and get a coffee. When I was logged in again in both Windows and Ubuntu I got the same issue with Firefox in Linux. WTF?

At least I have the tools in Ubuntu to debug this issue. This is a simplified version and approximate order of what I did.

First, create ~/.gdbinit to make GDB a tad more user-friendly:

set pagination off
set radix 16
set print pretty
set history save on

Second, add ddebs.ubuntu.com to /etc/apt/sources.list:

deb http://ddebs.ubuntu.com/ jaunty main restricted universe multiverse
deb http://ddebs.ubuntu.com/ jaunty-updates main restricted universe multiverse
deb http://ddebs.ubuntu.com/ jaunty-security main restricted universe multiverse
deb http://ddebs.ubuntu.com/ jaunty-proposed main restricted universe multiverse

Install some debug symbols:

sudo apt-get install firefox-3.0-dbgsym libnspr4-0d-dbgsym xulrunner-1.9-dbgsym

Debugging time!

$ gdb `which firefox` `pidof firefox`

(gdb) thread apply all bt

Thread 2 (Thread 0xb08eab90 (LWP 4253)):

#9  0xb7e16c7f in getaddrinfo () from /lib/tls/i686/cmov/libc.so.6
#10 0xb7c8d739 in PR_GetAddrInfoByName (hostname=0xbc01ff4 “safebrowsing-cache.google.com”, af=0x0, flags=0x8020) at prnetdb.c:2026
#11 0xb7267940 in nsHostResolver::ThreadFunc (arg=0x92d9fd8) at nsHostResolver.cpp:697

Thread 1 (Thread 0xb7d4b6d0 (LWP 4243)):
#0  0xb8003422 in __kernel_vsyscall ()
#1  0xb7fe30e5 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib/tls/i686/cmov/libpthread.so.0
#2  0xb7c94ed9 in PR_WaitCondVar (cvar=0xcd1ebf8, timeout=0xffffffff) at ptsynch.c:405
#3  0xb7c94f57 in PR_Wait (mon=0xd47d178, timeout=0xffffffff) at ptsynch.c:584
#4  0xb726621b in nsDNSService::Resolve (this=0x92d4b00, [email protected], flags=<value optimized out>, result=0xbff19ac0) at nsDNSService2.cpp:49

So, we have a thread that is resolving “safebrowsing-cache.google.com” and another thread waiting for this hostname to be resolved. Could this be an issue?

Back at the command line, is there an issue with this domain name? Checking on my local computer:

$ host safebrowsing-cache.google.com
;; connection timed out; no servers could be reached

Trouble at Google? I must confirm that, so I login to one of my servers and run the same command:

$ host safebrowsing-cache.google.com
;; Truncated, retrying in TCP mode.
safebrowsing-cache.google.com is an alias for safebrowsing.cache.l.google.com.
safebrowsing.cache.l.google.com has address 74.125.10.92

Works fine, but what does Truncated, retrying in TCP mode mean? I will investigate that later.

Apparently the company firewall is unable to resolve this domain name, at least for the time being. Google Safe Browsing is built into Firefox 3, so how do I disable it? I looked in about:config and yes, there was a setting called browser.safebrowsing.enabled set to true. I set it to false and… Firefox still froze. Looking at about:config again, I found browser.safebrowsing.malware.enabled and set that one to false as well. Now I am able to write this blog post!

Disabling these configuration options is only curing the symptoms, not the disease. But can I cure an enterprise DNS server that fails to handle truncated responses? I doubt it.

Boot original Xbox directly into XBMC

I have some things left to say about installing XBMC on the original Xbox, in part because they are not done yet.

Today I finally made the Xbox boot directly into XBMC and not to EvoX.  Searching the web for instructions on how to do this may give some different answers, but the one that I decided to try and that worked perfectly came (unsurprisingly) from xbmc.org: Using the Team XBMC Shortcut.xbe.

The file names used as examples were the same as for my installation: I replaced C:evoxdash.xbe and created C:evoxdash.cfg containing E:AppsXBMCdefault.xbe. I actually made sure that the .cfg file had CRLF line ending even though I created it in Ubuntu, but it probably doesn’t matter.

I changed the XBMC network settings to use DHCP instead of “system settings” to make sure that XBMC would still get an IP address on the network after rebooting.

The reboot went smooth and took me straight into XBMC. Isn’t it nice when things just work?

Good at programming, bad at communicating

I can’t remember how I originally found the link (was it in someone’s tweet?) but I managed to find it again in order to share it here. The message may seem silly in retrospect, but I think it was enlightening. The article is called Sometimes, The Better You Program, The Worse You Communicate. The author writes that:

[…] good programming practices are directly opposed to good communication practices.

In bullet form:

  1. D.R.Y. Does Not Apply.
  2. Humans don’t mean what they say.
  3. Compilers don’t need to see an example.
  4. Programs love definitions; Humans get flummoxed.

From now on I will try to repeat myself more often, act on what people mean and not what they say, give more examples and avoid definitions. Except when programming!

Permute an array in PHP

I wrote this function recently when I could not find it in the PHP function list. Please provide any optimizations you discover!

function permute($array)
{
  $results = array();

  if (count($array) == 1)
  {
    $results[] = $array;
  }
  else
  {
    for ($i = 0; $i < count($array); $i++)
    {
      $first = array_shift($array);
      $subresults = permute($array);
      array_push($array, $first);
      foreach ($subresults as $subresult)
      {
        $results[] = array_merge(array($first), $subresult);
      }
    }
  }
  return $results;
}

assert(permute(array()) == array());
assert(permute(array(1)) == array(array(1)));
assert(permute(array(1,2)) == array(array(1,2),array(2,1)) ||
       permute(array(1,2)) == array(array(2,1),array(1,2)));
assert(count(permute(array(1,2,3)) == 6));
assert(count(permute(array(1,2,3,4)) == 24));

Amount of type checks in Java

Martin Fowler writes about DynamicTypeCheck:

Recently some of our developers ran into the accusation that with a dynamic language like ruby you use so many dynamic type checks that you end up effectively writing your own type system. So they thought, since we’ve written a lot of real ruby code – how often do we make dynamic type checks?

We define a dynamic type check as the use of the methods is_a?, kind_of?, and instance_of?.

This made me think about the use of instanceof in Java. A pretty non-scientific investigation of an Open Source Java application (Vuze) showed:

Lines of code: 740257 (find . -name '*.java' | xargs cat |wc -l)

Number of instanceof: 1926 (find . -name '*.java' | xargs cat| grep -c ' instanceof ')

LOC/Number of instanceof: 384

So, there is actually more instanceof in this Java project than there are dynamic type checks in the anonymous Ruby projects used for the statistics presented by Martin Fowler. I certainly hope it wasn’t a Java developer that accused dynamic languages to use lots of dynamic type checks!

Recommended reading: “Artisanal Retro-Futurism crossed with Team-Scale Anarcho-Syndicalism”

Brian Marick has created a site for AR⊗TA, short for Artisanal Retro-Futurism crossed with Team-Scale Anarcho-Syndicalism. I do not expect that a movement with a name like that will catch on in “the enterprise” but it seems like a good reaction to software development processes that are called agile but fail to be agile.

sticker

I’m an HTML Tag Criminal

I read the 10 HTML Tag Crimes You Really Shouldn’t Commit article and while I had suspected it for a while, I now know myself to be an HTML Tag Criminal. My biggest crime is:

Crime 4: Using <b> and <i> for Bolding and Italicizing

Actually WordPress will convert <b> and <i>to <strong> and <em>, respectively, but I’m pretty sure that my on-line diary suffer from the above crime and a few more…