Why have I started using WordPress for my blog?

Some of you may wonder why a professional web developer is using wordpress for their blog instead of building their own custom site from the ground up.

My answer is actually pretty simple – I aim to have a wide array of knowledge in web development technologies and WordPress is not something I’ve ever really looked into. Playing with tools is always interesting, but I don’t think you can really learn something without using it properly for an extended period of time.

Consequently, I shall be using WordPress and building my own templates (slowly) for a (maybe indefinite) period of time.

Hope that explains it well enough!

Setting up a Transparent Proxy in XAMPP / MAMP

Ever wanted to make javascript requests to your own API but not wanted to host your own version of the API locally? Of course, if you try and make a request from http://localhost/example to http://www.youtube.com/api you will encounter issues with cross domain javascript not being allowed. This article shows you a way of making this kind of request possible.

What is a transparent proxy?

Simply put, a transparent proxy is a something that acts as an intermediary for request between a client and another endpoint. By requesting one particular URL your proxy causing the request to be sent somewhere else.

Can’t I do this some other way?

Yep, there are a few traditional (and a few much newer) solutions to this problem. One of the most common being to run a local file written in a language such as PHP to proxy your requests and send them on via curl….For example, you may make a request passing the actual API request in the query string: to http://localhost/example/proxy.php?url=http://example.com/api?query=a&param=b

Your PHP would then make the request to the domain and simply set the headers of the response and print out the data returned for your javascript code to handle.

It’s actually a lot simpler just to choose a specific URL on your localhost and get apache to proxy the requests for you, no backend proxy script needed. So you would proxy from http://localhost/api to http:///api. Then in your javascript app, you can just request data from http://localhost/api.

How to implement it.

I’m going to detail how to set this up on XAMPP running under Mac OSX and then how to do it using plain old Apache2 on Ubuntu, but the steps should be very similar regardless of which particular method you are using to run your web server. All that is probably different are the file locations and mods you currently have enabled.

IMPORTANT NOTE / DISCLAIMER

I am recommending this method for running for development purposes only. Simply copying the steps below on a production server is asking for trouble as this is essentially running an open proxy and can open some serious security flaws. If you need to run this kind of proxy on a production server, additional steps must be taken to secure the system but these are above the scope of this article. As long as you understand this…Carry on.

XAMPP on MacOS

Firstly, we need to check that the necessary modules are already being loaded by apache when it starts up. This is a relatively simple task. I am going to assume you have installed XAMPP at its default path of /Applications/XAMPP. If you changed it, substitute the paths below for your individual XAMPP paths.

(If you are doing this in terminal, you’ll probably need to run the command to open the file as sudo e.g sudo vi /Applications/XAMPP/Xamppfiles/httpd.conf).

If you’re using an application to open the file, you’ll probably need to enter your password when you hit save. Don’t be alarmed if the password auth box pops up.

Open /Applications/XAMP/Xamppfiles/etc/httpd.conf

We need to make sure the following lines are uncommented (A comment in a .conf file begins with #)


LoadModule rewrite_module modules/mod_rewrite.so
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so

If all these are now uncommented navigate to the very bottom of the file and add the following:


#Include local proxy rules
Include etc/extra/httpd-proxy.conf

Save and close the file.

Next create a new file called httpd-proxy.conf at /Applications/XAMPP/Xamppfiles/etc/extra and add the following:


ProxyRequests On
<Proxy *>
Order deny, allow
Allow from All
</Proxy>

ProxyPass /path/to/local/api <remote api url>
ProxyPassReverse /path/to/loca/api <remote api url>

Save and close this file. A couple of things to note here the ProxyPass and ProxyPassReverse lines contain the url you would like to proxy on, ignoring the base url of your host. For example if you use /api – http://localhost/api will be your proxy URL. If you use /proxy/api http://localhost/proxy/api will be your proxy address.

Now you should restart XAMPP.

You should now be able to make requests via your local proxy to your remote API url. If it’s not working, put your local proxy address in your browser…You should see exactly what you would if you put the remote api url directly into your address bar.

Apache2 on Ubuntu

This is a pretty simple process. You will probably have to run most of the commands as with sudo.

Firstly, enable to mods needed to run the proxy by typing the following commands into a terminal.


sudo a2enmod rewrite
sudo a2enmod proxy
sudo a2enmod proxy_http

Next, add the following inside the default VirtualHost in /etc/apache2/sites-available/default (Or if you’re running your own vhosts add it to the most appropriate.


ProxyRequest On
<Proxy *>
AddDefaultCharset off
Order allow, deny
Allow from All
</Proxy>

ProxyPass /path/to/local/api <remote api url>
ProxyPassReverse /path/to/local/api <remote api url>

Save and close the file and restart apache:


sudo apache2 restart

You should now be able to make requests via your local proxy to your remote API url. If it’s not working, put your local proxy address in your browser…You should see exactly what you would if you put the remote api url directly into your address bar.

Summing up

You should now have a local proxy running to enable you to not have to run a backend script proxy locally. If you’re having any issues with this, leave a comment below and I’ll do my best to help you out.

Switching from Windows to Mac OS. The important bits no-one has told you.

I’ve read many guides on switching from Windows to Mac. Many of them seem to gloss over the every day differences between the two OS’s. Here are some things I mostly figured out on my own a couple of years ago in the first few frustrating days of being a new Mac user. I think you may find these the most useful.

There is no “Start Menu”

All those years of using the Windows Start Menu go out the window. If you’ve used launchy on Windows, you’ll be right at home with Spotlight, if not – it’s the easiest (in my opinion) way to launch applications in OSX if it’s not already present in the dock.

To use spotlight, hit cmd+space and type the first few letters of the name of the application you want to launch. Spotlight will display a list of the closest matches. Select your application and hit enter, or click on it.

An alternative way is to open a finder Window (use “Finder” in the dock, or open the “Macintosh HD” icon from your desktop) and navigate to the “Applications” folder – You should see it on the list on the left of your finder Window. Find the Application and launch it.

Of course, if your program is already in the dock (and you can get any application to “live” there) simply launch it from there.

CMD is the new CTRL

Most of the Windows shortcuts you are used to using also exist in OSX. The difference is that you now need to use cmd+key instead of ctrl+key. For example the “copy” shortcut on Windows ( ctrl+c ) becomes cmd+c in OSX, likewise, ctrl+v for paste becomes cmd+v in OSX.

Honestly, this can take a little bit of getting used to as years of muscle memory will keep you reaching for the ctrl key. You will get used to it and prefer it. Trust me!

You can’t cut and paste a file or directory

Nothing can cut and paste a file in OSX. The exact reasons for apple not implementing this are unknown. There are suggestions that it is for protecting files. The easiest way to move a file is to have two finder windows open and drag the file or directory from one window to the other.

If you are moving files between volumes (drives) you need to hold cmd and drag the file to move it, just dragging the file will duplicate it on the secondary volume.

Alternatively, if you a familiar with linux commands you can move (“mv”) the file through the OSX Terminal application.

Be careful when “replacing” the contents of a folder

If you’ve been a Windows user for a while, chances are you’ve had two directories of the same name with different contents. If you wanted to move one of these directories to the same location as the other, copying the contents, Windows will have “merged” the two directories.

OSX handles this differently and you need to be careful when you do such an operation as you may unexpectedly lose files.

If you do a straight replace in OSX, it will replace the original directory in it’s entirety INCLUDING it’s contents with the folder being moved/copied.

To get around this, you can again, use the OSX “Terminal” application to move (“mv”) the directory, which will perform a merge. Alternatively you will have to get used to copying and moving files at a deeper level. You will soon get used to it

There is no print screen key

One of the most commonly asked questions from new OSX users is “How do I take a screenshot?”.

There is no Print Screen key on your Mac keyboard. To take a screenshot in OSX, hit cmd+shift+4. This will turn your cursor into a crosshair. Click and drag the crosshair over the area you want a screenshot of and release the mouse.

You will now have the area you dragged over saved as a screenshot on your desktop.

If you want to take a screenshot of the entire window you are working in, hit cmd+shift+4 then hit space. The cursor turns into a camera icon. Click and the whole active window will be saved to your desktop.

cmd+option+escape is your new ctrl+alt+delete

Ahh, the three finger salute! Ever the saviour in Windows to quit unresponsive programs. In OSX if you need to quit an unresposive application the shortcut is cmd+option+escape. I agree, this is not as easy to press as ctrl+alt+delete but hopefully you won’t be needing it too often!

Maximise and minimise behave differently

Another one of the common annoyances about OSX is the behavior of window “maximising. Windows has always treated maximise as a way of filling your screen with the application that you have Maximised. OSX does not do this as default.

OSX will maximise the Window to the total size of the content it contains (although confusingly some third party OSX applications implement the Windows behaviour).

If you want a window to take up the whole screen, grab the bottom right corner and drag it to do so. Your preference will be remembered next time you launch the same application.

There is no task bar

In Windows, you may be used to looking at the “Task Bar” (the grey strip to the right of the start menu). The task bar will show you blocks for each application you have open and each Window for that application may have it’s own block or may stack with other blocks of its application type.

Things are slightly different in OSX. The dock will show you which applications are running by highlighting their underneath, but not how many active (if any) windows the application currently has. For this, there is the beautiful functionality of Expose. On newer macs (2006 onwards) you can simply hit “F3″ and all your active windows will be shown on the screen. You can then mouseover each to get it’s title and click to make it the active window.

Closing a window does not ‘quit’ the program

This is actually the same in Windows, however Windows does not show that a program is still loaded in the memory and it will silently take up a portion of your RAM (this is why a program will load more quickly the second time you open it).

In OSX, if you close all instances of a running application, you will notice that it is still highlighted as running in the dock and the universal menu will still be available. To fully quit a program, you can either right click (or cmd click) it on the dock and select quit, click the applications name in the universal menu and select “quit ” or use the shortcut cmd + q.

Programs share a toolbar

The universal application toolbar is arguably the hardest thing to get used to for switchers. For some, it’s too different and they never get used to it and fight it forever. For others it’s a great feature.

The basic fact is that all applications in OSX share one toolbar that is always at the top of the screen. The toolbar will change to show options for the currently active program. To show the toolbar for another application you have open, you need to make an instance of that application active.

Note: The apple icon in the universal toolbar is always the “system” menu and as such as unrelated to the currently active application.

Renaming files is different

The most common way to rename a file in Windows is to right click and then select “rename”. In OSX the easiest way to rename a file is to select the file and hit your return key. Alternatively, you can bring up the files properties (CMD+i) and then rename the file in the dialogue.

System Preferences is the new Control Panel

All of your system preferences including common things such as display resolution, printer options and wallpaper are contained in the System Preferences application. This basically functions in the same way “Control Panel” does in Windows.

Right clicking IS possible

One of the most common criticisms levelled at the Mac by Windows users is that the mouse only has one button and that you can only ‘left click’. This may have been true 10 years ago, but definitely isn’t now. You can eiher CMD+click for the secondary menu or enable right click in the system preferences.

You can do this on a desktop mac (or if you have a mouse plugged into your notebook) by opening System Preferences, selecting “Keyboard and Mouse” and then selecting the “Mouse” tab. If you’re using your notebook trackpad, open “Trackpad” from System Preferences instead of “Keyboard and Mouse.

Full details are explained at theappleblog.com

Most applications do not have “installers”

There is no registry

Unlike Windows, OSX has no “registry” for software.

Conclusion

I hope that has helped with your switching journey, as you will see I have refrained from saying which OS’s methods I prefer as I wanted to keep any preference out of this article. Consequently, please refrain from turning any comments into a Mac vs PC war! Thanks.

If anyone has any suggestions or think I should add something else, please post it up in the comments!

Testing and Hiring Developers – You need to put some effort in too.

This is a topic that has been covered by a number of other websites before now, but I just wanted to add my thoughts into the mix. It’s a difficult question…How do you test and hire a developer?

Unfortunately, unlike many other job roles, time and experience does not have a direct correlation as to how good a developer may be. I’ve met developers who have only been in the field professionally for a year or so, yet have outstanding skills. Conversely, I’ve met developers with nine or ten years experience that are nowhere near as good.

So, as a hiring manager, how do you figure out if you’re hiring a duff or a diamond? Obviously, the answer is that you have to formulate some sort of testing methodology to separate the wheat from the chaff. However, this is a monumental minefield in itself that inspires heated debates whenever the subject is mentioned.

So what can you do?

Firstly, before you even consider testing a potential hire, make sure you are doing the following.

Hire for the right position

This sounds pretty obvious, but I’ve often seen companies recruiting for a ‘PHP Developer’ when they’re actually looking for a Web Architect or a similar level position where a high skill level in engineering and application design and architecture are far more important than solid PHP skills. Whilst it’s possible that a good PHP developer may be able to do this, you are far more likely to get more relevant applications if the job title is appropriately named.

Spend some time on the job spec.

The majority of job specs that I’ve seen are useless. They often have very little detail, are very vague and don’t really give much information. If the job is going to be difficult and requires a high level of skill make sure the spec communicates this. I know it’s probably quite tempting to rush the spec and give it to an agency and let them wade through the hundreds of CVs sent for the role but in doing this there is inherently a higher chance in candidates that aren’t of the required level getting through to an interview and consequently wasting your (and their own) time.

A higher level sounding spec will entice a higher level developer.

Don’t expect people to know everything

Don’t put things like the following (which I actually found on a job spec recently) in your spec:

”Must be highly proficient in PHP, ASP.NET, C#, Java, Apache, HTML, CSS, JavaScript, jQuery, Ajax, XML, XSLT, Linux, MySQL, MSSQL, Python and Perl.”

Now, whilst some people do have a decent knowledge of technologies and languages outside of their core set of skills (most PHP developers should have a fair knowledge of HTML, CSS, Apache and Linux for example) expecting people to be “highly proficient” in such a wide range of technologies is asking for trouble. If somebody did happen to have knowledge of all of those, chances are they would not be particularly brilliant at any in particular – the old phrase “jack of all trades, master of none” springs to mind.

Much better is to focus your skill requests on the real core aspects of the job. Think what the job couldn’t be done without. Don’t just spam a load of keywords at your agency or HR department as it will almost certainly degrade the quality of applications for the position. I know of developers who would deliberately not apply for any spec that had this kind of listing in it.

The Testing

Once you’ve got your spec sorted and have some candidates for interview you’re going to need to formulate some kind of test for them. Developers hate tests by default. We dislike having to prove our skills to someone else. However, we also understand that a degree of testing, particularly for a Senior or higher level job is a necessary evil.

There isn’t really a standard qualification that proves someone is a great developer (though if you’re in the Java world the [url=http://uk.sun.com/training/certification/java/scjp.xml]SCJP[/url] would do so, but it is expensive and many can’t afford to pay for the SCJP even if they possess the skills to pass).

PHP has the [url=http://www.zend.com/en/services/certification/]Zend Certification[/url], but this doesn’t really prove that someone is a good developer as in my experience it hinges too much on testing peoples memory and knowledge of the PHP manual rather than their general programming and development skills.

This isn’t a dig at the Zend Certification, if someone has passed it then there’s a high chance that they’re pretty solid at PHP and it’s not easy to formulate a programming certification that will test peoples development ability above knowledge of a particular language.

In answer to this, we’ve seen a few ‘online testing’ websites and companies spring up ([url=http://www.brainbench.com/]BrainBench[/url] is one such example) and to a hiring manager, these must seem great. Cheap, easy, don’t take much time to set up and if you’re using an agency then they can do it all for you and it takes no time at all. There’s one problem with this though, the tests are mostly meaningless.

I’ve taken a couple of tests on one such website and apparently, I’m among the top 3% of PHP developers in the world….Whilst I like to think I’m pretty good at it, that’s pushing it a bit far! I’m also in the top 10% of MySQL users in the world. My SQL skills, compared to a hardcore DBA would be average at best.

Why are they bad? Again, they rely far too heavily on testing the tiny details of syntax. Most questions are ‘which line of this code has a syntax error’ or ‘what function would you use to perform x task’. Contrary to popular belief, us developers don’t sit in our chairs all day memorizing the PHP manual. Nor do we sit on the train on the way home reading it for ‘fun’.

Have someone from your technical team involved in the whole process. They and the potential hire can willingly speak “geek” to each other and you won’t have to worry about what the hell they’re talking about. You can get your tech guy to translate after the interview.

What kind of test should you give a developer?

There are a few ways you could go about this. As I’ve said before, there is no real “winner” when it comes to the best way of testing developers.

Sit them down with a piece of paper and a pen describe some simple program and have them write it down. Do not ask them to do this in any particular language or check it for syntax errors or correct function names. They may write it in a particular language and that is fine. The script would not need to run for them to be successful at this task. This kind of test should be used purely to see how their brain works out programming logic and communicates it to you. See the post on [url=http://www.codinghorror.com/blog/archives/000781]FizzBuzz[/url] at [url=http://www.codinghorror.com/blog/]Coding Horror[/url] for something similar to this kind of test (although it seems to be language / syntax specific).

Give them a very open ended, real world task to complete using a computer with internet access and a limited timescale (say 1 or 2 hours). Produce a specification for a basic program and let them go and build it in their natural environment.

That involves having a computer with internet access. I’m sorry to break any notions you have of developers brains, but we use google a lot. Don’t make this test something that is very niche or would require knowledge of your company code base to complete. Give them a coffee and make them feel comfortable and make it clear that not completing the spec is OK. In fact it should probably be a bigger task than can reasonably be completed in the allotted time. You should be using this kind of test to see how they would go about working on a project in terms of prioritizing sections. It should also give you some idea about the general quality of their coding skills.

Get some print outs of code and see if they can figure out what it’s doing and explain it to you. You could also field questions on what might be able to be done to improve the code. Don’t use this kind of test to ask the candidate to spot potential syntax errors. We are not walking compilers/parsers.

Get some non programming, but logic related questions to ask the candidate, but let them answer them in a non pressured way. Maybe email them to the candidate before the interview. One such question would be:

  • The number of false statements here is one.
  • The number of false statements here is two.
  • The number of false statements here is three.
  • The number of false statements here is four.

Which of the above statements is the true one?

Such questions can test one’s mental aptitude to a degree. I would advise that you don’t use the exact question above as it’s now fairly well known.

Summary

Having covered the details in a fair amount of depth in this post we could summarize by saying that you should be putting a fair amount of effort into your recruitment and testing processes if you want to attract and hire good developers. If you hastily throw together a spec and farm it out to an agency the chances are the calibre of your applicants will be lower. A few of the best developers I know actually refuse to be recruited through an agency, something to bear in mind if you’re looking for the best.

I hope some of you find this useful in improving the way in which you recruit your development team members, please leave any thoughts or comments.

Implementing the Zend Framework with CodeIgniter

Whilst I am not a huge fan of the Zend Framework as a whole (it’s always felt more like a monolithic PEAR like library than a Framework to me), there are undoubtedly some very useful features and classes that are held within it.

Why do we want to use the Zend Framework?

This aim of this article is to show how we can use whichever aspect of the Zend Framework we want, from within a CodeIgniter application with a minimum of fuss. The goal is to be able to use Zend components, without littering our beautiful, lightweight CodeIgniter application with php requires and without coupling ourselves too strongly to the Zend Framework. The result of this is that should you want to drop the Zend Framework at a later date, you won’t have to pull your code to bits to replace it.

I hear you all. There have been many libraries written for CodeIgniter that do some of the things the Zend Framework does. Elliot Haughin has done a great job in writing many libraries for various applications including: Twitter, Facebook Connect and Last FM (full list available at Elliot Haughin’s Site

However, whilst these are great (and I highly reccomend them for sites where you’re only going to need a couple), if you are building a larger, complex application, then many of the Zend libraries that there is not yet a CodeIgniter implementation of, can be very very useful and save you bags of time in writing your own libraries. (Zend Cache, Zend AMF, Zend ACL as a couple of examples).

The Zend Framework is also very well maintained and updated on a regular basis, so if you’re yearning for a feature, chances are other people will be and it will show up in a not too distant release.

How do I implement it?

Fortunately, implementing the Zend Framework in this way is a fairly simple excercise.

If you haven’t got it, you’re going to need the Zend Framework. You can get it from the Zend Framework Website.

Once you’ve got it, create the following directory in your CodeIgniter installation:

../system/contrib/Zend

* N.B – The case of “Zend” is important.

Extract the downloaded Zend Framework and move the files from the “Zend/library” directory it into the “Zend” directory we just created.

You should now have a directory structure like the following:

../system/
contrib/
Zend/
Acl/
Acl.php
Amf/
Amf.php
...

If you’re struggling with this, download my contrib folder and extract it to your codeigniter “system” directory.

Next we need to create a helper to do the loading for us. Create a new php file called “zend_framework_helper” in your helpers directory and place the following code in it.

ini_set("include_path", ini_get("include_path").PATH_SEPARATOR.BASEPATH."/contrib/");

require_once 'Zend/Loader.php';

We could now call the Zend Loader anywhere by using:

$this->load->helper(‘zend_framework”);

However, it’s probably going to be easier if we use CodeIgniter’s autoloader. Place “zend_framework” in the helpers section of your application/config/autoload.php file. It should look something like this:


$autoload['helper'] = array('url','text','zend_framework');

We’re now ready to start using the Zend Framework components in our CodeIgniter application, but before we go any further, it’s worth running your application to make sure you’re not receiving any errors.

Once you’re happy that your application is running OK, you can simply initialize the Zend component you want to use by calling the Zend_Loader::loadClass method in your code and passing it the name of the component you wish to use:

Zend_Loader::loadClass(‘Zend_Cache’);

I will be covering an actual use of one of the Zend Components (Zend_Cache) in a future post.

So, there you have it, the Zend Framework implemented in CodeIgniter.

I hope have found this useful, please let me know via comments of any issues or feedback you may have.

Note: it is entirely possible to only move the Zend components you are interested in, rather than the entire framework, into your CodeIgniter application, but you will have to check it’s dependencies in the Zend Framework Documentation. Most of the Zend libraries seem to depend on “Exception.php” but I have not extensively researched this. I would recommend you always include the “Loader/” directory and “Loader.php” as this makes loading the Zend Components very easy and avoids littering your code with lots of “include” and “require” statements.