writeAttribute() example

The documentation on http://prototypejs.org/api/element/writeAttribute is a wee bit scarce. So here’s a quick one on usage.

To add an attribute:

$('foo').writeAttribute('title', 'bar');

To remove an attribute:

$('foo').writeAttribute('title', null);

To enable all disabled form elements (in a form with the id ‘container’):

$('container').select('[disabled="disabled"]').each(function(e) {
  $(e).writeAttribute('disabled', null);
});

When MySQL servers go weird

The MySQL PASSWORD() function has started giving a different value on a client’s live server compared to local development servers.

This has resulted in end users not being able to log in when PASSWORD() is used to compare the stored and entered passwords.

Why this has happened I have no idea. Any thoughts?

dev
mysql> SELECT PASSWORD('foobar');
+-------------------------------------------+
| PASSWORD('foobar')                        |
+-------------------------------------------+
| *9B500343BC52E2911172EB52AE5CF4847604C6E5 |
+-------------------------------------------+
1 row in set (0.00 sec)

live
mysql> select password('foobar');
+-------------------------------------------+
| password('foobar')                        |
+-------------------------------------------+
| *9061D7B8DA0D4523AD448B53D80C2B551EDF8CD1 |
+-------------------------------------------+
1 row in set (0.00 sec)

Installing Boxee on Ubuntu 9.10 on Acer Aspire Revo R3600

This is on myrant.net rather than my other blog on lazygnome.net as it wasn’t as quick and easy as I’d have liked to set up. So, in a way, a very tiny rant with a lot of helpful content (I hope).

Inspiration for this article came from following Popey’s setup instructions with Ubuntu 9.10 alpha.

  1. Download Ubuntu 9.10 32bit desktop ISO: http://www.ubuntu.com/getubuntu/download
  2. a) if you have an external CD drive, burn the ISO to a CD.
    b) if you have a USB flash drive: download and install UNetbootin from http://unetbootin.sourceforge.net/. This is available for Windows and Linux. Use this util. to ‘burn’ the ISO to your USB flash drive.
  3. a) if you have an external CD drive, put the ubuntu CD into the drive.
    b) if you have a USB flash drive, plug it into the Revo (Any USB port seems to work).
  4. Power on the Revo and hit f12 to enter the boot menu.
  5. Select CD or USB depending on your install medium.
  6. Select Default, or wait and it’ll select it for you.
  7. The Ubuntu desktop will eventually load.
  8. Have a play, or click ‘Install Ubuntu 9.10’.
  9. On step 4, partitioning, I chose to use the entire disk. If you don’t want to ditch the shipped OS, choose another option.
  10. Set up a username/password then choose if you want to log in automatically.  Normally, I wouldn’t set this, but as it’s going to be a media centre, you might as well have it log in automatically.
  11. Step 6 will allow you to check you have set the options you want. Once you are happy, continue the install and go make a cuppa tea, do the washing, feed the cat, read a book; as this will take some time.
  12. Reboot the machine once installation has finished.
  13. When the desktop is usable, run the Update Manager – at the time of writing, there were 86 packages to be updated.
  14. Click on Restricted drivers available and activate the NVidia accelerated graphics driver.
  15. From this point, follow Popey’s install instructions.
  16. Whilst following Alan’s instructions, I had to grab 3 debs from Jaunty (rather than his stated 1). These are:
    http://packages.ubuntu.com/jaunty/i386/liblzo1/download
  17. http://packages.ubuntu.com/jaunty/i386/libdirectfb-1.0-0/download
    http://packages.ubuntu.com/jaunty/i386/libkrb53/download

By this point, Boxee is accessible via the Sound & Video menu.

Next task, for me, is to get an external enclosure for my internal blu-ray drive (still waiting for decent blu-ray support in linux).

Please, somebody standadise the order of function variables

Finding a needle in a haystack is a wonderful bit of symbolism and I welcome its use in many situations.

It’s just the implementation of that symbolism that needs to be standardised. For forgetting the order in which a function expects variables to be passed in is tedious.

In PHP, for example, there are some very useful functions: in_array() and strpos() to name but two.

Usage is in_array($needle, $haystack) and makes sense as you want to check that the needle is in the haystack.
But, it’s strpos($haystack, $needle) that messes things up. You can’t look for a haystack within a needle!

So, because of strpos() confusing things, it’s quite often that I (and other’s I’m sure) mix the order, no matter which function is in use. Unless I’ve been using the function within the last few hours, I’ll most likely get it wrong.

These are long standing functions in a well established language, so there’s no hope of these ever being corrected.

For new functions, a possible answer would be to pass variables by associative array when the function has more than 1 variable input.

An example of calling such a function would be: myFunction(array(‘needle’ => ‘malteser’, ‘haystack’ => ‘bag_of_revels’));

This way, it wouldn’t matter which order you remembered to pass in the variables. As it happens, this is how I write my own functions.

Apparently, something similar is done in Python. Might get around to learning it sometime…