What a productive day!

You know how sometimes you have those awesome productive days? Well, mine has been one of those… Got up at 6:45am (yeah, thank my little boy for that one! :-P ) and figured I might as well stay up, so unloaded the dishwasher, put in another load, cleaned the house from top to bottom, entertained friends for lunch, wrote my first jQuery plug-in, wrote my first set of PHPUnit test cases for a new app I’m working on, write two blog posts (OK; so one of them is this one, but it counts, damn it!), and posted my first proper twitter message!

Now if I can squeeze in a little tv watching or Overload playing, I’ll be golden!

jQuery plug-in – highlight external links

I’m pretty new to the whole jQuery game, having really only started to look at in a number of weeks ago. Until then I have been happily using Prototype and Scriptaculous, and as I knew them I didn’t see a point to move to another library. However, the more examples I saw of jQuery the more elegant I thought it was, and so now am in the process of learning it more, converting some code over and trying my hand at plug-ins. So here’s introducing my first jQuery plug-in!

This plug-in allows you to automatically append a class and title to any external resources. You can pass in multiple domains that are thought of as ‘local’, and anything else with a protocol that doesn’t belong on the passed local domains will be flagged as external. If no domains are passed then the current domain in the url will be used as-is (with the www., etc., if present).

That probably doesn’t make much sense, but I’m sure it will when using it…

So here’s the code:

Continue reading ‘jQuery plug-in – highlight external links’

Quick and easy email encoding view helper

Here’s a quick and easy view helper for Zend Framework that will encode an email address. It will encode just an email address or return a whole mailto link. The encoding is basically the same as in the Smarty template engine.

Obviously there’s a lot of room for improvement; javascript encoding, representation as an image, and so on… but then it wouldn’t be quick an easy – it’d be slightly longer and just a little more complex. ;-)

Continue reading ‘Quick and easy email encoding view helper’

Finally!!!

It’s been too long in the coming, and to be honest, I’d given up waiting for this game thanks to that darned World of Warcraft taking up all of Blizzard’s time, but Diablo III is in the making!!!

http://www.blizzard.com/diablo3/

Can’t wait! :)

Zend Framework 1.6RC1

If you haven’t heard already, Zend Framework 1.6RC1 is out and has lots of interesting new features. Finally there’s a SOAP component (seemed odd to me to have an enterprise-level framework without it!) There’s also a paginator, XML configs can have attributes, Dojo integration and lots more.

It’s been out for about 10 days as of the time I write this, but the only new thing I’ve tried as of yet is the Zend_Paginator component. And I must say that I am very happy with how easy it was to set up and integrate in to a site… Essentially, I just had to pass my select object to the paginator and write a view partial to handle how it looked – it was that easy! With the output of the pagination put in to a partial it makes the whole thing very easy to rebrand and configure to exactly how you want it to look. This is definitely a component I’m going to be using a lot.

Looking forward to using the other new features, too. There is a Zend Webinar to show the new features of ZF1.6 coming up on the 13th August, 2008. Also one in September to go over integrating the new Dojo features.

Application running really slow

While working on an application built on Zend Framework, I experienced a really odd slow-down of the system while running on the web cluster at work as opposed to my machine at home. I couldn’t see what the issue was myself, and it seemed to baffle people on #zftalk a bit as well as work colleagues. The speed difference was quite dramatic – going from near instant on my home computer to around 30 seconds for a page display while running on the cluster.

Naturally, this required a fair amount of investigation…

It was quickly ruled out to be any fault of ZF. After all, it is being used by companies such as IBM, Zend, Sourceforge, Fox, and more. If the framework were not suitable and produced slow results then they would obviously not use it, nor would any of you!

Next to be ruled out was custom code built on top of ZF. With the exact same code-base producing faster results on one machine and not on another it was highly unlikely to be the code.

Profiling the code proved a little helpful. I profiled the database connection for each query and ruled out any slowness with that as they were taking fractions of seconds. Code profiling was a little bit more tricky, as everything seemed proportionally slower, not any one thing in particular. However, the Zend_Loader component seemed to be taking quite some time to perform its tasks.

With a little command-line magic (using ktrace, kdump, grep, awk, etc. – not by me, but by talented colleague) it was determined that the OS itself, Mac OSX ‘Tiger’, was mainly to blame. The cause of the problem was trying to determine relative paths and the slow speed at which Tiger was doing this… As I understand it, to determine the current directory, ‘.’, the OS needs to back track all the way to the root, get the whole list of directories and work out which inode matches the one your current path is, and then work its way back down the directories until it finds a match. Once it’s done that you have your current path. If it sounds intensive, that’s because it is.

When comparing Tiger to Leopard we were seeing a 1000x improvement (4 microseconds as opposed to 4 milliseconds) to do various getdirentries() calls.

If you used the include path for a handful of files you’d never notice a significant drop in speed, but the application I’m working on, together with ZF will typically include 140+ files.

So how was the issue resolved?

For the short term there was a very simple fix; simply alter the include path so that the current path is last to be checked and the more significant paths (such as where the application or Zend library is located) are first. This simple tweak took a 30+ second load time to around two seconds – a vast improvement! Still, two seconds is not ideal so we will be having Leopard-based machine installed on the web cluster to see if that also helps to increase performance.

I’m curious; has anyone else had a similar problem?

Email address being used to spam

Some little *insert a whole stream of expletives* has used my email address as the sender of a lot of spam.  I know this because opening my email box today resulted in no less than 400 failure notices, undelivered notices, auto replies and bounce messages.

Needless to say; I was not the one sending you spam!

Tag cloud view helper

Here’s a little view helper to display a tag cloud. All you have to do is supply an array of tags, with the tag name being the index and how many times it’s used as the value, and the url you’d like the tags to go to.

Continue reading ‘Tag cloud view helper’

StringToTitle filter

I like the filtering capabilities of the Zend Framework, but for some reason there doesn’t seem to be a string to title case filter (though there is a string to upper and string to lower). So here it is:

Continue reading ‘StringToTitle filter’

Damn hackers.

Someone exploited a hole in the version of Wordpress that I Was using and managed to destroy my last post about automatically creating model for your Zend Framework app. Unfortunately, I just don’t think I have a recent backup of the database around so might not be able to recover it easily.

This has forced me, of course, to update my version of Wordpress. Along with that I’ve had to change my theme, which has also meant I’ve had to remove a few pages because they relied on widgets specific to that theme. This all means that this blog is now in a state of flux, so thanks for your patience while I spend a while fixing things back up (which, knowing me, will take months!!)