Matt Waterworth

Biography

Matt Waterworth is an experienced web developer and second-rate Jack Osbourne impersonator. He specialises in devising and implementing PHP-based web applications. He is an advocate of practical pattern-based object-orientated design.

He is a part-time internet marketer, blogger and domainer who catalogues his entrepreneurial misadventures on TakeMoreRisks.com.

Contact Matt

Fake project idea

This Monkey's Gone To Heaven.com

A religious community forum that prays for the salvation of recently deceased monkeys

Regular trips will be planned to Belfast Zoo in order to preach the word of God to the apes and to convince them to leave sin and bananas behind.

The community will provide support to bereaved zookeepers who may be concerned that their monkey is in hell.

Checking out the Cake Bakery & Blog Errors

Finding and Installing Useful CakePHP Components

I've spent a while this morning browsing around the CakePHP Bakery website searching for snippets of code that I can import into my base CakePHP install.

So far I've come across the Image Resize and Pagination helpers which I could definitely reuse across a number of applications.

To install the Image and Pagination's helpers for server-wide access, I copied the relevant code from the Bakery site, opened up the pico editor in Linux, pasted it in and saved it inside the /usr/lib/php/cake/libs/view/helpers directory. Thankfully Cake has the intelligence to look here if the helper isn't present within the application directory.

On the Hunt for More Components

I don't like the design of the Bakery website. I wish you could sort packages by the number of times they've been downloaded like you can on the PEAR website.

Moving the CakePHP Core Library Files For Reusability

Over the past week I've established the aim of completely eliminating code repetition on my server. This morning I've moved the CakePHP core library files to the /usr/lib/php/ directory.

Since this is directly within PHP's default include path I no longer have to include the cake/ or vendors/ libraries inside of my application. Instead if I want to install some third party code I place it within /usr/lib/php/vendors whereas previously I'd put it in EVERY installation directory that I required it in.

As you can see from below, my new directory structure is much cleaner thanks to this.

500 Server Error? Oh Shit!

For some reason every 3 out of 4 times I visit the Week 6 page on this blog I get a blank screen with a 500 Server Error message. What's even more confusing is that it doesn't happen for any other week.

Solution : The Services_Delicious package is the culprit. Actually that's inaccurate. It's the Delicious API that is causing the problem. It seems to be refusing requests almost at random but this still doesn't explain why it's only happening for Week 6 on my blog.

I'm gonna disable the This Week block for the next day or two until I debug the problem. I'll need to fill this position with data from another source for the first few weeks which have no Del.icio.us posts saved anyway.

I Am An Absolute Idiot

Broken Blog

If you tried to access my blog anytime after Wednesday last week you'll have noticed that there was nothing here. On Thursday morning I transferred this site over to my VPS dearly hoping that things would go smoothly. Turns out I'd have no such luck. Now the blog didn't work because of some complex technical issue. No. It was broke because I forgot to import the database from the phpMyAdmin.

So yes. I'm an absolute idiot.

And I'm still hungover from Thursday night.

So what have I been at recently? Good question. I've been slacking a bit. And by slacking I mean pissing about with this server and overdosing on Crackerbread.

Stop Press

I've just discovered that too much Diet Tesco Kick gives you the shits.

Yes, you needed to know this.

Anyway on to stuff that's actually related to IMD.

What really pissed me off about my shared hosting account was that I had very limited shell access meaning I couldn't install any additional software.

The cool thing about the VPS is that I can and I took the time this morning to learn how the PEAR Package Manager works.

What is PEAR and Why Is It Important?

I'm sick and tired of rewriting the same code in PHP. It's a serious pain in the arse. Take validating email address as an example. I don't know how many times I've written a piss-poor regular expression to validate emails. It's insane. Thankfully PEAR has an email validation function built into it and much much more.

The Validate_UK package is immense. It can validate National Insurance numbers, Post Codes, Phone Numbers and practically everything else in between. There's even a Validate_IE for Irish data.

Installing the Validate UK package.

I'm no Linux guru by any stretch of the imagination. In fact I've often refused to use it in the past because most supporters of open source software are intolerable tree hugging lefties who are even more insufferable than Mac lovers.

To run the PEAR manager you simply type in pear at the command line. If you supply no additional arguments you see something like this.

To install a package you simply type in pear install PACKAGE_NAME. However whenever I typed in pear install Validate_UK I received this error message.

Since the Validate_UK package isn't a stable release I had to type in pear install Validate_UK-0.5.3 to install it correctly which was no biggy really.

It'll definitely be worth searching through the repository for code that I can reuse in my major project. In fact I'm gonna do that now.

PEAR Packages That I Could Use / Possible Uses.

I'm gonna spend the next few days messing about with PEAR to see if I can add interesting (yet probably pointless) functionality to this blog. I'll need to find out why the content on this page keeps displaying twice as well. It's really weird.

Aha! Found the cause of the problem. For some reason I was calling the dispatcher twice in the Front Controller. What the hell was I thinking? Christ Crackerbread must be psychoactive these days!

My Youtube Favourites

I've used the Services_Youtube package to import a list of my favourite videos from You Tube to help give the blog a personal touch. The code I've written is a bit scrappy at the minute and I'll eventually need to move it into a seperate CakePHP component/helper set.

Unfortunately the Youtube API doesn't allow you to specify a limit value with the listFavouriteVideos function, which means I'm having to pull back all of my favourites which is a bit of a pain.

Abstracting the YouTube service into its own component

This is where my head starts to hurt. If I want to limit the number of videos that are returned from the Youtube API I'll need to write some code that will be available application-wide, which is why I decided to use a CakePHP component.

Since a component is essentially a class in itself I moved the code that initalises the service into the constructor.

function __construct() {
$this->inst = new Services_YouTube($this->dev_id, array('usesCache' => true));
}

Now the thing is, if I want to call the listFavouriteVideos method from any controller I'll have to do it like this.

$this->Youtube->inst->listFavouriteVideos('blah', 'etc');

It's dangerous to expose the inst property publicly as it contains all of my login data. I need to find a way to make the Youtube compontent automatically call the listFavouriteVideos method with a call like

$this->Youtube->listFavouriteVideos('blah', 'etc');

And I've found a solution! I'm now making use of the magic method __call and the call_user_func_array function to automatically call the method inside inst. This took ages to get my head around and I still don't think I understand it fully.

public function __call($method, $args) {

return call_user_func_array(array(&$this->inst, $method),$args);

}

My head hurts. I'm gonna move onto something more fun.

The Frank Mitchell Weather Watchers Experiment

I found out about the Services_Weather package sometime last week and thought it'd be cool to test it to see what type of functionality I could add to the blog. Before you can use the package you must first signup with a weather service provider and in this case I chose weather.com. After signing up I received a developer id and an api key which entitles me access to the API.

The API itself is really easy to use through PEAR. These next two lines of code return the current weather for the location specified which is subsequently stored in an array inside $weatherData.

$id = $weather->searchLocation('Carrickfergus');
$weatherData = $weather->getWeather($id);

So far I've generated a random Frank Mitchell weather report for Carrickfergus using only the temperature and wind attributes along with a set of if's and elseif's.

 

I've since added a facility that dynamically pulls back an acoustic video from Youtube depending on the overall weather condition (which is stored inside the condition element in weatherData). It's a very basic example of a mashup that will hopefully evolve depending on whether or not Frank Mitchell tries to sue me. It doesn't make sense a lot of the time either. Sometimes the weather condition will be "Fair" and the Youtube API call will bring back the same cover version of Scarborough Fair. God damn it.