We're growing into something new. Read More

Martin Bean  Pro


Facebook Cover Photo template (PSD)

I find myself regularly creating Facebook cover photo templates in Adobe Photoshop, repeating the process over and over. Therefore, I've decided to create a Facebook cover photo PSD template, which is also freely available to download. You can find it at http://www.martinbean.co.uk/facebook/cover-photo-template, with two editable layers for the cover photo and profile photo. Do let me know if anything could be improved.


# get parameters for hostname and document root
echo -e "Host name (e.g. dev.domain.com):"
read hostname

echo -e "Document root (directory):"
read docroot

# add entry to hosts file
echo " $hostname" >> /etc/hosts

# add entry to vhosts file
echo "
<VirtualHost *:80>
  ServerName $hostname
  DocumentRoot $docroot
  SetEnv APP_ENVIRONMENT development
</VirtualHost>" >> /etc/apache2/extra/httpd-vhosts.conf

# set correct permissions
chmod 755 "$docroot"

# restart apache
apachectl restart

echo "VirtualHost added for $hostname."

Create VirtualHost from Terminal

I had to reformat my MacBook Pro recently. I use it for the development of some sites, where my usual approach it to create a VirtualHost in Apache for the domain name prepended with "dev.", so for example "dev.forrst.com". What I realised is, I manually add the relevant entries to my hosts file and my httpd-vhosts.conf file manually each and every time, and now I've got to re-import all of my old working version sites, this will become tedious. So, I've knocked up a quick shell script. This is my first shell script that's not one line, so feel free to suggest any improvements if there's any to be made. To use the script, simply create an alias in your .profile file. I used alias addvhost=/usr/local/bin/addvhost.sh. Then, just run it from a Terminal prompt: ~ addvhost Raw Code » The script will then ask you for two pieces of information: a host name (i.e. dev.forrst.com) and the actual location of your files (the document root). Once you've entered these, it'll create entries in hosts and your httpd-vhosts.conf (assuming they're in the default locations). Tested on Mac OS X 10.6 (Snow Leopard). Also, I'm not responsible if you brick your Mac!


Can I alter the default form mark-up in CakePHP?

I'm a big fan of Twitter's Bootstrap framework at the minute. I wanting to use it on a CakePHP-powered web app, but the HTML generated via Cake's Form helper isn't consistent with the mark-up required for Bootstrap's form styling. So my question is, how can I alter the default HTML generated by Cake's Form helper?

Wrestling tale of the tape

A sample "Tale of the Tape" style screen for a professional wrestling organisation.


NWA UK Hammerlock website

Launched earlier than usual because the client was on the ball and one of the easiest to work with, it's the new-look website for NWA UK's Hammerlock Wrestling!

Hammerlock Wrestling website redesign

Currently re-designing the Hammerlock Wrestling website. Hammerlock are a member of the National Wrestling Alliance (NWA). This redesign hopefully conveys the organisation's strong UK roots and character when contrasted to websites of other NWA members. The website should be launching next week some time. EDIT: The website is now live! Check it out at nwahammerlock.com.


PHP wrapper for the Forrst API

A simple PHP wrapper for the Forrst API. Usage is simple. Simply include the class file and instantiate a new instance of the class: require 'src/forrst.php'; $forrst = new ForrstApi(); Raw Code » You can then call the built-in public methods to obtain Forrst data. For example: $result = $forrst->getStats(); Raw Code » Responses are returned as PHP objects. Available methods are: getStats authenticateUser getUsersInfo getUserPosts showPost listPosts getPostComments Do check the Forrst API documentation or the source code as some methods have required parameters, which are just passed to the method call as method arguments. Coming soon, the API will throw ForrstApiExceptions upon an API error. I'll probably get on this tomorrow. Errors are now thrown as a ForrstApiException. Hope you folks like it and find it easy enough to use and if you encounter any problems, do log them at github.com/martinbean/forrst-api/… Some code inspired by the Facebook PHP SDK.


$request = explode('/', trim($_SERVER['REQUEST_URI'], '/'));

if (strlen($request[0]) > 0 && file_exists('./modules/'.$request[0].'.php')) {
    require './modules/'.$request[0].'.php';
    $class_name = $request[0]; // we can camel case the request here if you like class names that way
    $method = $_SERVER['REQUEST_METHOD'];
    $instance = new $class_name;
    if (method_exists(array($instance, $method)) && is_callable(array($instance, $method))) {
        // here you would include any objects, such as databases etc.
        $params = array();
        switch (strtolower($method)) {
            case 'get':
                $params = $_GET;
            case 'post':
                $params = $_POST;
            case 'put':
                parse_str(file_get_contents('php://input'), $params);
        $response = call_user_func(array($instance, $method), $params);
    else {
        header('HTTP/1.1 404 Not Found');
        $response = array('error' => array(
            'message' => sprintf('Unknown path component: %s', $method)
else {
    header('HTTP/1.1 404 Not Found');
    $response = array('error', array(
        'message' => sprintf('Unknown path component: %s', $request[0])

header('Content-Type: application/json');
echo json_encode($response);

Simple API snippet (PHP)

After reading Janusz Bossy's "A snippet for fast API generation in PHP", I decided to share my own approach which is pretty similar to Janusz's, but fixes some of the shortcomings of his. A couple of things this approach rectifies are: Only the required files are loaded, cutting disk reads which are costly Parameters are stored in an aptly-named $params variable, but are more RESTful The API is an abstraction of one I use in production and currently developing; that API is heavily influenced by Facebook's Graph API and that is reflected above, most noticeably in the error messages when an endpoint doesn't match a valid class/method ("Unknown path component"). Any suggestions or feedback is welcomed.