OSX Logo

Creating Mac OSX Aliases

10th November 2012 - 4 minutes read time

Adding an alias to your system is a good way of saving time when remembering complex commands. You can reduce a command down to a quick two letter command that is easy to remember.

The alias command can be used to assign an alias on the fly. You can create an alias to 'ls -lah' by typing in the following into the command line.

alias ll="ls -lah"

Now, when you type 'll' (i.e. two lower case L's) you will actually run the command 'ls -la'.

Or you might want to do more complex things like running your selenium server.

alias selenium-server="java -jar ~/Development/selenium-server-standalone-2.25.0.jar"

To remove an alias you can use the unalias command to remove an alias from your system.

Phing Logo

Checking Syntax Errors In PHP And JavaScript Using Phing

29th October 2012 - 7 minutes read time

Checking Syntax Errors In PHP And JavaScript Using Phing

Running a simple syntax check over your files is a good way to save time. This can be when testing code but best practice is to not to even commit code that contains syntax errors.

You can syntax check a single file using the -l (lowercase L) flag with the PHP executable like this.

$ php -l file.php

Unfortunately this can only check one file at a time so I set about trying to find a good way of checking a whole project at once. There are a couple of scripts available on the internet, but I set about creating my own solution using the phplint task in Phing. This means that I can just create a fileset and feed this into the phplint task without having to rewrite the whole thing if I wanted to include (or exclude) a particular directory or file.

Linux Logo

Happy Birthday Bash Script

29th October 2012 - 1 minute read time

Following on from the PHP script to print happy birthday I wanted do the same in a bash script. I don't really use bash for much more than stringing together commands so I had to figure out how to do loops and if statements using the simple bash syntax. I also wanted to pass the name of the person as an argument, rather than hard code it into the script. This is what I came up with.


for i in {1..4}
  output=$output"Happy birthday "

  if [ $i -eq 3 ]
    output=$output"dear $1\n"
    output=$output"to you\n"
echo -e $output

Save the file as happy.sh or similar and run it in the following way (Name is the argument that we pass to the script).

$ ./happy.sh Name
PHP Logo

Happy Birthday PHP Script

29th October 2012 - 1 minute read time

When posting happy birthday messages to developers over social media I like to write it in code, just to be geeky. The following code will print the happy birthday song using PHP.

$string = '';
for ($i = 0; $i < 4; $i++) {
    $string .= "Happy birthday ";
    if ($i != 2) {
        $string .= "to you!\n";
    } else {
        $string .= "dear %s!\n";
print sprintf($string, 'name');

This can be easily personalised by just changing the second parameter in the sprintf() function.

PHP Logo

PHPNW12: A Review

20th October 2012 - 48 minutes read time

The annual PHPNW conference gets better every year, and this year was no exception. I have been going to the PHPNW conference since their inception in 2008 and this year I was lucky enough to be involved in some of the pre-conference organising and helping out over the event.

When the call for papers ended in June I spent a weekend reading abstracts and bios of speakers to try and reduce the 169 talk submissions to around 32 sessions. I then sat down with Jeremy Coates, Rick Ogden and Jenny Wong to select which talks would be included in the final selection. Once the sessions were complete I sat down and started working on a blog schedule and wrote a few blog posts to garner attention.

#! code Logo

Why I Went For A Macbook Pro

13th September 2012 - 7 minutes read time

I very recently took delivery a 15 inch MacBook Pro (my first Apple computer) and I thought I would write about my reasoning behind it. Normally, people don't tend to ask why you bought a computer, but with Apple products it seems to be different. I think I have stated my reasons to a few different people already, so I thought it would make a good blog post.

Drupal Logo

Using Zend Framework In Drupal

14th August 2012 - 4 minutes read time

If you want to use Zend Framework in Drupal then most of the time you can use the Zend module. This takes a little configuration but will include the framework and instantiate the Zend_Loader_Autoloader class so that everything is ready to run.

The Zend module has a number of different strategies to including the framework, which is handy if you do or don't want to use the Libraries module. The module uses the hook_init() hook to include and instantiate the Zend_Loader_Autoloader object, which meant that this was done on every page load; even if the framework isn't being used.

Python Logo

Using Python To Beat The 2012 Olympic Google Doodles

11th August 2012 - 5 minutes read time

The other day I was inspired by a story on Reddit about a guy who had created a Python script to automatically play the olympic hurdles Google Doodle. The Python script just passed the correct keyboard commands to the game so that the game was finished in 1.5 seconds, earning a gold medal. The problem was that his script was specifically for Windows, so I set about trying to create a Linux version that I could run on Kubuntu.

After a bit of research I found a decent plugin that sends keyboard commands through Python called uinput. To get this installed I had to add the following lines to /etc/apt/sources.list.

PHP Logo

Testing Websites With Selenium And PHP

16th July 2012 - 6 minutes read time

Selenium is an application that allows automated testing of websites through a browser and consists of a number of different components. It allows the creation of browser tests that perform certain actions, which can then be run again at a later date. Three components are required to allow Selenium to run tests through PHP. These are as follows:

Mimicking Data Provider Functionality In Drupal SimpleTest

10th July 2012 - 5 minutes read time

Although Drupal SimpleTest is an extremely useful module it doesn't currently support data providers, which is a shame as I use that feature quite a bit in other testing frameworks. A data provider is a mechanism that allows you to call a single test case multiple times with different arguments so that you can ensure the correct output each time. This is useful because testing a single function once is fine, but testing it with a variety of different values can otherwise mean having multiple test cases.

To mimic this functionality in Drupal SimpleTest you can create a data provider method that returns an array, which is then used to test a particular function.

For example, let's say I have the following (trivial) function in a Drupal module.