window rain

Iain's nonsensical words

Dear diary...

It's been ages since I last did anything here. And I find that I have little time for blog updating.

That said, I've started a new site over here myrant.net.

It's not to replace this site, more of a quick place for me to keep my semi-rants that are longer than twitter can cope with.

My intention is that anybody can register and post their rants, though I've not had any takers yet.

Peace out!

It's hard to believe, but it's been 2 years since I 1st donned these prescription specs.

Now, I have a new prescription and 2 new pairs of glasses. Having a deeper frame will allow me to start using them for night time driving.

I took a photo, I look fat:
New specs


No photo just yet, but here's an image for the time being:
Austin 24084086

As I haven't posted anything here for a while, why not enjoy some wintery photos from my flickr account.

I think that my fave has to be:
Police car slides into Great Malvern Post Office
Police car slides into Great Malvern Post Office

Following on from last month's Select the 1st letter of the last word in MySQL, I then needed a way to select the last word from string (or column).

SELECT REVERSE(LEFT(REVERSE('Iain Cuthbertson'), LOCATE(' ', REVERSE('Iain Cuthbertson')) -1));


Now I can sort rows by surname when the full name is in just one cell!

IE6, oh how you destroy my will to code.

1st Problem:
List item numbers dissapear in IE6.

Solution:
ol { margin: 0; padding: 0; }
ol li { margin: 0 2em 0 2.5em; padding: 0 }


2nd Problem:
List item numbers are all set to 1.

Solution:
ol li { zoom: 0; }


I recently had a need to select the 1st letter of the last word in a stored field.
This is my 10min stumbling result:

select SUBSTRING(REVERSE('Iain Cuthbertson'), LOCATE(' ', REVERSE('Iain Cuthbertson')) - 1, 1) as result;


MySQL only code I'm afraid folks.

I've mentioned this on Facebook and Twitter, I guess I should say something here as well.

Every now and then, I forget to shave. Sometimes I can forget to shave for several weeks in a row.

The most recent forgetting to shave lasted 4-5 weeks!
In an effort to look a little more human, I made the effort to shave on Sunday morning.

It's not that often that you get to try out a selection of different facial hair styles, so I took the chance to play around:

img_5258
Click for the full series!

  1. Create amazing new blog with symfony.
  2. Measure and cost tiling area around bath so a proper shower can be fitted.
  3. Figure out where workstation will go in own bedroom if 2nd bedroom is to be sub-let.
With regard to blog: what to do with old entries? allow commenting? look for a designer?

var elm = document.getElementById('foo');
elm.value = elm.value.replace(/(^\s+|\s+$)/g, '');

This is how I've tackeled the problem of changing the order of some SimpleXML objects.

Adding an attribute to the top level of an object can add as the position reference.
So Passing an array of SimpleXML objects to the following function will return the same array of objects, but reordered by the $key attribute.

[Edited 26th Feb 2008]
function xmlSort($dataArray, $sortKey)
{
$outputArray = array();

for ($i = 0; $i < count($dataArray); $i++)
{
$sortArray[] = (int)$dataArray[$i]{$sortKey};
}

for ($i = 0; $i < count($sortArray); $i++)
{
$outputArray[] = $dataArray[$sortArray[$i]];
}

for ($i = 0; $i < count($outputArray); $i++)
{
$outputArray[$i]{$sortKey} = $i;
}

return $outputArray;
}

See PHP.net SimpleXML for the dataset used.

Adding 'pos="#"' to each element will allow for reordering.

An example usage would be:
$sorted_xml = xmlSort($xml->movie, 'pos');


Diary feed
 + RSS 2.0 XML feed


Everything on this site is (c) Iain Cuthbertson unless otherwise noted.