day macha
"Error #2044: Unhandled onError:. text" - Loading youtube videos from Flash

I was getting this error in a Flash file when loading Youtube videos with SWFLoader. But only in Firefox - not in Chrome or Internet Explorer. I added various event listeners for EventError and IOEventError to try to catch the error. I even added a security exception for youtube.com. None of this worked.

What I didn’t realise was the error was coming from Youtube itself, not my application directly. The ‘onError’ error appears to be this (http://code.google.com/apis/youtube/js_api_reference.html#Events) error. A simple event handler:

yourSwfObject.addEventHandler(‘onError’, function(e:Event):void{

//your event handling code here

}

deals with it. But only if:

Security.allowDomain( ‘http://www.youtube.com’ );

is also added to the code. It all seems a little voodoo though: only Firefox splurges out this error - and not on all Firefox/flash combinations - and the event handling code only works when youtube.com is given a security exception. Ho hmm. If anyone can shed light on this mystery, I’d be very grateful.

To hell with for loops

All these process an array, returning the processed:

var array_to_return;

for(var i=0;i<old_array.length;i++) {
array_to_return.push(processed old_array[i]);
}
return array_to_return;

and

var array_to_return;

for each(var i in old_array) {
array_to_return.push(processed i);
}
return array_to_return;

are not as nice as

return old_array.map(function (i) { return processed i; });

and (this removes things from an array)

Read More

There is a place for the adjective and for the descriptive passage, but these must be carefully handled. A piece of prose that had no adjectives would very quickly become sterile; so it really is a question of restraint. There is a psychological reason for this: If somebody sets out in great detail what is before us, we very quickly become bored. That is not the way we see the world; we look for salience, we look for the feature that will engage our interest… The trouble with overwritten prose is that it takes away from the reader the opportunity to imagine a scene. We do not want to be told everything; we want a few brushstrokes, a few carefully chosen adjectives, and then we can do the rest ourselves.
Alexander McCall Smith on Writing Concisely WSJ.com (via somethingchanged)
Problem with qemu-kvm: keyboard and mouse

qemu-kvm wasn’t detecting my mouse and keyboard during emulation for some reason. I’d click on the qemu window and nothing would happen. Even weirder, it was opening up in TTY8—that is, completely separate from Xorg.

Eventually, I found out the problem that some VMPlayer background daemon was still hanging around, somehow forcing qemu-kvm to TTY8 and stealing its mouse and keyboard focus.

I removed VMPlayer and all was well again. qemu-kvm even opened up within Xorg.

bash time saver: for loops

Just now I had a bunch a packages I wanted to install.  I was going to do install package_1, then install package_2, etc etc.  Instead:

for a in package_1 package_2; do install $a; done

Fairly simple, and I knew for each loops existed in bash—just never got around to making part of my console habit.

Edit: install {package_1,package_2} works as well, making sure there are no whitespaces.

Rebinding the Escape key in Vim: the k j approach

As using vim involves switching between command and insert mode a lot, you end up reaching for the Escape key often—too often for my fingers.

You change your Escape key for Caps Lock. I was using C-c for the Escape key, which is a default alternative in vim. C-[ appears to be a old time short-cut, too.

But they all suffer from the same problems: moving your fingers away from the home row, and holding down the Ctl key in two of the approaches. And I hate doing both those things.

I stumbled across this excellent solution on a forum recently though:

Read More

Unicode and UTF-8 Explained

I spent some time reading this excellent but lengthy guide to Unicode and UTF-8 and playing with Unicode a little. Here’s a hopefully clearer and gently paced guide telling you what you need to know, especially if you’re working with a programming language that does not automatically handle Unicode (it’s a good overview for non-programmers, too).


Before Unicode

Everything, as you know, in a computer is stored as naughts and ones. These naughts and ones can represent numbers. 01000001 represents 65. These are also used to represent letters. 65 (1000001) is the uppercase letter A, for example.

Read More

Soft word wrap in VIM 7 (for prose mainly)

Soft word wrap seems like a black art judging by Google’s search results, especially as many of the solutions are for previous version of Vim.  I finally came across the solution via vim’s homepage.  And this solution automatically re-soft wraps the text when you insert some text in an existing line, thankfully.  There are few more tweaks needed, however.

Read More

bikeshed:

via asset.soup.io
"mtp" mobile phone devices in linux

MTP, a Microsoft invention, sits on a lot mobile phones and other devices these days. It’s a protocol that makes the transfer of media better/more convenient somehow (whatever is wrong with plain filesystems, I really don’t know…) Wikipedia has a list of devices it infects.

This doesn’t work to well with Linux, as with most Microsoft protocols. libmtp does support some devices, however. See if yours is listed here. As libmtp develops that list may become out of date. There’s a simple command you can type to see if your device is supported: ‘mtp-detect’.

If you receive something like ‘LIBMTP PANIC: Unable to read device information on device 12 on bus 0, trying to continue. Unable to open raw device 0' or other errors occur then you're out of luck, I'm afraid. If you don't find any critical errors, then I suggest you try 'mtpfs' — you can view your phone's files in a filesystem format.