Thursday, March 18, 2010

Nerd Food: Getting ls to behave

ls appears to be sorting rather weirdly of late (well, since quite a few Ubuntu releases), ignoring upper and lower case, e.g.:

drwxr-xr-x 2 marco marco 4096 2010-03-17 00:12 cmake
-rw-r--r-- 1 marco marco 8708 2010-03-17 18:39 CMakeLists.txt
drwxr-xr-x 2 marco marco 4096 2010-03-17 15:17 config
drwxr-xr-x 4 marco marco 4096 2010-03-11 18:22 cpp
drwxr-xr-x 2 marco marco 4096 2010-03-17 16:24 doc
drwxr-xr-x 2 marco marco 4096 2010-03-12 01:39 glade
drwxr-xr-x 5 marco marco 4096 2010-03-17 18:42 output
-rw-r--r-- 1 marco marco 1124 2010-03-17 16:26 README.TXT
drwxr-xr-x 2 marco marco 4096 2010-03-11 18:22 scripts
drwxr-xr-x 3 marco marco 4096 2010-03-11 18:22 sql
drwxr-xr-x 3 marco marco 4096 2010-03-11 18:22 templates

This is utterly annoying. The main reason people use upper case filenames is precisely because they come up at the top of the listing. It appears the reason why is the locale, more precisely LC_COLLATE.

$ locale | grep LC_COLLATE
LC_COLLATE="en_GB.UTF-8"

By changing it to C, it all behaves as expected:

$ export LC_COLLATE=C
$ ls
-rw-r--r-- 1 marco marco 8708 2010-03-17 18:39 CMakeLists.txt
-rw-r--r-- 1 marco marco 1124 2010-03-17 16:26 README.TXT
drwxr-xr-x 2 marco marco 4096 2010-03-17 00:12 cmake
drwxr-xr-x 2 marco marco 4096 2010-03-17 15:17 config
drwxr-xr-x 4 marco marco 4096 2010-03-11 18:22 cpp
drwxr-xr-x 2 marco marco 4096 2010-03-17 16:24 doc
drwxr-xr-x 2 marco marco 4096 2010-03-12 01:39 glade
drwxr-xr-x 5 marco marco 4096 2010-03-17 18:42 output
drwxr-xr-x 2 marco marco 4096 2010-03-11 18:22 scripts
drwxr-xr-x 3 marco marco 4096 2010-03-11 18:22 sql
drwxr-xr-x 3 marco marco 4096 2010-03-11 18:22 templates

Much better! To make it permanent, add it to your .bashrc.

Wednesday, March 17, 2010

Kids Thrive on Complexity

I've found a probability distribution that went unstudied until now, and the random process originating it is my nephew. To be more precise, its the dazzingly complex algorithm he uses to distribute the contents of a packet of crisps across a room - in his lingo: eating. Its not just the quasi-uniform floor coverage (including underneath all furniture), the fact that no two crumbs share the same size, or even its speed that makes it unique; its the efficient use of resources. A single room can be covered with _the remains_ of a small packet of crisps. Amazing.

Thursday, March 11, 2010

Nerd Food: use_action_appearance saga

While playing with Ian Remmel's instructions on how to use Gtk::Action and Gtk::ActionGroups, I've bumped into an annoying problem: for some reason my toolbar icons and menu items started behaving weirdly after adding some Gtk::Actions to them. Symptoms were blank labels on menu options and blank toolbar items, or toolbar items with words rather than stock items. After some head scratching, I think I got to the bottom of it. Basically, the toolbar or menu item is taking its caption from the Gtk::Action.


Stock item refresh not being displayed.

What is puzzling is that the Glade UI clearly says that "Use Action Appearance" is set to "No". However, close inspection of the .glade file shows no mention of this property at all, so somehow the default value for it appears to be "Yes". I proved it by manually hacking use_action_appearance, e.g.:

<property name="related_action">act_reload</property>
<property name="use_action_appearance">False</property>

This fixed all my prolems. Of course, this is not a long term solution because it gets overwritten every time you save your .glade file. A more enduring workaround may be to do this in code, possibly where you add the Gtk::Action to the Gtk::ActionGroup, at least until Glade fixes the bug.

Another puzzling aspect of this bug is that there has been a lot of work around it of late, as the release notes of glade-3 3.6.7-0ubuntu1 imply:

- Sync up remaining properties at load time (fixes use-action-appearance property and any other unmentioned property states at load time, also unvails broken orientation default value in GTK+, bug 587256).
- Fixed glitches with use-action-appearance at save time.

A quick apt-cache check reveals we're running the correct version:

$ apt-cache show glade | grep "^Version"
Version: 3.6.7-1ubuntu1

So either all of this activity around use_action_appearance did not fix the bug or there was some kind of merge mistake downstream. Here we can see the commit that tried to fix the problem - nothing obvious to the layman, unfortunately. By downloading the tarball used to make the Ubuntu package, we can easily confirm that the upstream commit is present downstream.

An upstream bug report had been filled for this problem: #582882. Shame it wasn't cross referenced in the release notes, like some others were. Perhaps the maintainers haven't gotten to the bug report just yet.

Nothing more to do other than wait for the glade maintainers...

Update: Another workaround for this problem is to set the icon / lable text directly on the action.

Monday, March 01, 2010

Nerd Food: Suspend and Resume on Karmic

For some reason, the suspend and resume in Karmic (Ubuntu 9.10) fails to restart wireless properly on one of my laptops. According to lspci the card is a RealTek RTL8101E/RTL8102E . Everything else works ok, and the failure is intermittent - maybe one resume fails out of three or so. If you have the same problem, you can try the following before restarting your machine:

$ su
# cd /etc/init.d
# ./networking restart
# ./network-manager restart

This seems to sort the problem out, most of the time. Hopefully the Lynx is going to fix this.

Saturday, February 27, 2010

NP: See That My Grave Is Kept Clean (Blind Lemon Jefferson)

Only one kind favour I ask of you
Well, there's one kind favour I ask of you
Lord, there's one kind favour I'll ask of you
Please [see] that my grave is kept clean

There's a long lane, it's got no end
It's a long lane, it's got no end
It's a long lane, ain't got no end
There's a bad wind that never came

Lord, there's two white horses in a line
Well, there's two white horses in a line
Well, there's two white horses in a line
Gonna take me to my burying ground

My heart stop beating, my hands are cold
My heart stop beating, my hands are cold
Well, my heart stop beating, Lord my hands are cold
It wasn't long [till I understood] what the Bible told

Have you ever heard a coffin sound?
Have you ever heard a coffin sound?
Have you ever heard a coffin sound?
Then you know that the poor boy is in the ground

Oh, dig my grave with a silver spade
Dig my grave with a silver spade
Well, dig my grave with a silver spade
You may lead me down with a golden chain

Have you ever heard a church bell toll?
Have you ever heard a church bell toll?
Have you ever heard a church bell toll?
Then you know that the poor boy is dead and gone

Friday, February 19, 2010

Nerd Food: SSH darwin awards

Like every other Linux user, I use SSH extensively to connect to different computers and run applications remotely (-X in particular is one of my favourites). SSH has a tendency to remember hosts you've connected to in the past, and stores this information under ~/.ssh/known_hosts. This works quite well for fixed IPs in the WAN, where SSH key to IP address is bijective. It doesn't work so well for people who connect to different local networks using the traditional 192.168.X.Y space, because the same IP maps to many different keys, confusing SSH. Any DHCP environment also suffers from this problem.

In the past, I've solved this the brute force way by trashing the whole of .ssh:

rm -rf ~/.ssh

This solution works fine. Fine, that is, unless you happen to actually have created a private/public key to authenticate with servers requiring it, such as GitHub. Just as I pressed the enter key, it suddenly occurred to me that I had in fact started messing around with git and said provider, and had made no backup of the key - even though the FAQ states quite clearly that one should do so. Classic Homer Simpson moment.

Fortunately, GitHub must have thought about this exact same mistake and made it really easy to update one's key. From now on:

rm -rf ~/.ssh/known_hosts

Thursday, February 18, 2010

NP: Singapore (Tom Waits)

We sail tonight for Singapore,
We're all as mad as hatters here
I've fallen for a tawny Moor,
Took off to the land of Nod
Drank with all the Chinamen,
Walked the sewers of Paris
I danced along a colored wind,
Dangled from a rope of sand
You must say goodbye to me

We sail tonight for Singapore,
Don't fall asleep while you're ashore
Cross your heart and hope to die
When you hear the children cry
Let marrow bone and cleaver choose
While making feet for children shoes
Through the alley, back from hell,
When you hear that steeple bell
You must say goodbye to me

Wipe him down with gasoline
'til his arms are hard and mean
From now on boys this iron boat's your home
So heave away, boys

We sail tonight for Singapore,
Take your blankets from the floor
Wash your mouth out by the door,
The whole town's made of iron ore
Every witness turns to steam,
They all become Italian dreams
Fill your pockets up with earth,
Get yourself a dollar's worth
Away boys, away boys, heave away

The captain is a one-armed dwarf,
He's throwing dice along the wharf
In the land of the blind
The one-eyed man is king, so take this ring

We sail tonight for Singapore,
We're all as mad as hatters here
I've fallen for a tawny Moor,
Took off to the land of Nod
Drank with all the Chinamen,
Walked the sewers of Paris
I drank along a colored wind,
I dangled from a rope of sand
You must say goodbye to me