Writing LESS, doing more

Lately I’ve been doing a lot of dabbling in different technologies. Some of them, like responsive web design, I should have got myself involved in a long time ago. Others are more for interest to keep up with the industry. Y’know… as you do.

LESS is one of those technologies. Laravel uses it. Bootstrap uses it. I’d done a bit with SCSS previously, but it seemed like LESS has more advantages… maybe. Because of my experience with SCSS I already knew about the powerful benefits of nested CSS and variables, but mixins are something I never really looked at until now. They’re really quite clever…

@my-colour: #CC0000;

p {
  a {
    color: @my-colour;

  a:hover {
    color: lighten(@my-colour, 10%);

Give yourself a base colour for something, and lighten the colour quickly without having to calculate the relative hex code. Genius. Maths calculations make the whole thing so much more programmer-like, and all of a sudden CSS has been given an overhaul. Yes I know it compiles into CSS, but I really love the way LESS gives programmers a better way to structure their styling code. As was once said in The Matrix Reloaded, “it’s like wiping your arse with silk. I love it.”

It only gets better when you add responsive into the mix. There are many ways to do the whole responsive thing, and most grid systems will have you adding classes all over the place – “grid-2″ and “grid-6″ inside “grid-row” divs.

But wait a minute… on my travels I found something really intriguing, and I’ve been messing around with it quite a bit. The Semantic Grid System gets rid of all that rubbish – instead of adding grid classes all over the place you define your columns as mixins in your styling code. Truly beautiful, semantic and makes for much easier reading when looking at your HTML code. In a 12 grid layout:

<div class="left-navigation">

<div class="main">

<div class="right-advertising">
.left-navigation {

.main {

.right-advertising {

To me, that is a much, much better way of dealing with grids. And then you can easily make that work when adding responsive media queries by setting .columns(); to 12, for example.

LESS definitely lets me do more. Hooked.

Laravel update to 5.0.16 – important change to stop your stack breaking

After running composer update on my Laravel stack, I was surprised to find a whole bunch of errors and exceptions immediately afterwards. Turns out I needed to do three things:

Update /bootstrap/autoload.php
Laravel’s developers seem to have made quite a large change to the framework (changing the location of some compiled assets for a patch release seems a bit large). In order to get 5.0.16 to work you need to modify the line assigning $compiledPath – should be around line 30 on an unmodified version of the file:


$compiledPath = __DIR__.'/../storage/framework/compiled.php';


$compiledPath = __DIR__.'/../vendor/compiled.php';

Once changed, I then ran the following on my shell (I have the PHP version of composer installed into my project):

$ sudo rm ./vendor/compiled.php
$ sudo artisan clear-compiled
$ sudo php composer.phar update

Boom – that did it!

Lock my composer.json file
I’m totally going to lock the version to a specific point release after this – rather unexpected – update. Sure it’s an experimental Laravel stack, but I want to be experimenting not fixing my stack! While 5.0* should be fairly safe… apparently not!

Imagine if… I had used Laravel’s scheduling to auto-update composer… and then ran that on a production server!

Keep an eye on Laravel’s upgrade page!
Turns out they posted the one line change here. My bad for missing that.

It’s time to say goodbye to CodeIgniter

I’ve been a massive fan of the MVC programming pattern ever since I was introduced to it 4 or 5 years ago; the one thing that really helped me get to grips with MVC was writing my own core framework. Since then, I’ve been a CodeIgniter advocate – it was my framework of choice and it served me well – I had built my own libraries for authentication, social media integration plus many other “common” tasks and had developed an advanced knowledge of its workings… enough to make easy work of otherwise more time-consuming code tasks.

However in 2015 it’s very much outdated, and with little to no development going on it’s being left for dust. Just some of the things I wish were in CodeIgniter but aren’t (or aren’t implemented very well):

  • Namespacing
  • Scheduling
  • Decent templating
  • Advanced routing
  • Middleware
  • Composer!
  • PSR-2
  • Decent autoloading

With this thought in mind, I went and had a look on what’s on offer today – and why you should try them. After running through as many as I could find, I settled on Laravel as my next learning target. Just a few reasons why:

It’s got namespacing!
Definitely a sore point with CodeIgniter… want a model and controller for the same purpose? Sure, but you can’t call the classes the same thing. Très annoying!

I discovered this one today, but I’ve worked on numerous projects where I’ve had as many as 10 cron jobs configured, because there was no nice way of getting this to work with CodeIgniter. wget was generally your friend.

What Laravel does is actually quite neat (and, for those with Magento experience, similar to Magento). You create a single cron job to point at Artisan with a parameter of schedule:run, then create your jobs in “console commands” – absolute genius. You can even set up scheduled external commands this way, so updating composer automatically on a schedule suddenly becomes really simple!

Decent templating
The Blade templating engine built into Laravel is quite a powerful beast – you can still use PHP code in your views if you really, really want to. My problem with that is that it makes the code quite ugly to read. Working with Blade is a breeze, and I wish I had used something like this a lot sooner.

Advanced routing
Speaks for itself, but what I really like is how easy it is to send different request methods for the same URL to different controller methods (or different controllers entirely).

I had never used middleware until last year, but it’s a seriously useful feature for performing actions on every route, or a selection of routes, without having to inject code into route methods all over the place. Maintainability just got better!

I never really understood the point in Composer. Yes, I was really slow to pick up on this as a developer… quite a big regret. But once I realised how it could benefit me, I’m always looking for ways to speed up project development by using Composer. Since Laravel is built around it, I’ve got to see its power. And I love it!

Coding standards were never really something I came across until the start of 2014. I had developed a clean way of coding that was massively readable and maintainable, but this was through experience. To my surprise it wasn’t much different to PSR-2 – a few changes here and there, but my code follows PSR-2 coding standards now. Laravel will also conform to PSR-2 in v5.1.

PSR-4 autoloading
CodeIgniter’s autoload features were bloody awful! That’s no exaggeration – I don’t miss them. Laravel’s autoloading is great, and I’ve never yet had to worry about getting something loaded in.

There are many more reasons, like the Eloquent ORM being great (in some respects), but the list above are some of the most useful features I’ve come across in Laravel that I’m not used to!

How Facebook manipulates our social interactions

Facebook. It’s one of the world’s largest names online. It consumes millions of people on a daily basis, and keeps them tightly held in a lockjaw grip. (Almost) all of our friends are on it. They know so much more about you than you think. Yet is it possibly one of the worst places you could actually entrust with your data, and your mind?

So, You post a picture from that party you went to on the weekend… that embarrassing drunk one, share it amongst your friends allowing them to comment on it and share further. Facebook have recently been doing some changes on the share function which I believe have been rolled back – at one point sharing a post from a friend’s wall would only be visible to mutual friends, unless the post itself was public. It was a bizarre change which I verified by running several tests between my wife’s account and my own, and essentially made the share link redundant – at least for non-public posts.

But what about when Facebook “manipulate” what you do and how you interact not only with the site, but with your own friends?

Yesterday – 7th August – was my 29th birthday. I sat there the night before and thought about what happens on the day of anyone’s birthday – you wake up that morning to a barrage of “Happy birthday” posts left on your wall from your various Facebook friends, with the trend continuing through the day and tailing off early evening. And why? Facebook actively asks you to wish your “friend” a happy birthday and keeps the prompt up all day, just for your convenience.

I hid my date of birth from everyone.

For the first time since I joined Facebook in 2008, I had not received a single happy birthday comment on my wall. With the exception of my sister. But my sister already knew my birthday of course. Everyone who wished me a happy birthday did so via text message or in person (including my sister, who sent me a message before doing so on Facebook), just like it used to be. My children were genuinely excited that it was my birthday.

It turns out that if Facebook doesn’t tell you to wish your Facebook friend happy birthday, then none of your circle of “friends” actually knows. And perhaps that’s a good thing. Facebook has become a site where you can have a circle of friends but know absolutely nothing about them. If Facebook were to close tomorrow, the people I care about and the people I would want to remember my birthday would do exactly what they did yesterday. They would get in touch with me because they genuinely wanted to say those two words. They weren’t told to by a piece of code telling the site’s software to prompt them.

It truly is amazing what happens when you hide one thing from a website. People who would have otherwise made a comment, didn’t.

It’s hard to imagine what the world would be like now without social media, but it does make you wonder if the world would be a better place without it.


Apple’s Magic Mouse and the Disconnect Problem

Apple's Magic Mouse

Magic Mouse. Photo by Paul Ingram

Apple’s Mac products are pretty outstanding. They’re also arguably overpriced in many respects. However millions of people worldwide buy their products – including me. I have an iMac, MacBook Pro, iPad Air and iPhone 5S. My experience with their support and Genius Bar in the past has always been outstanding (and I believe that your higher prices not only pay for the fantastic build quality but also the support you receive).

However, like any company they’re not perfect and while I have few complaints about their products, one particular bug bear I have is with their Magic Mouse. It’s a fantastic concept, taking the responsiveness of the capacitor touch screens of their iPhone product and incorporating it into a device that has been used for years to control an arrow on a screen.

The problem
I got my Magic Mouse in 2012 – it was a product that had already been out 3 years so should have been fairly polished. The problem is that it’s not – the device is plagued by constant disconnections and it’s sadly not an isolated issue as mentioned here, here and here. Given that the earliest posts are from 2009, it makes you wonder why Apple haven’t addressed such a simple issue.

Possible fixes
There are only two real fixes. Either it’s a software fault within the mouse, or it’s a design flaw which causes the radio hardware to drop its transmission and therefore drop the connection. Or something’s shorting. Or the mouse is losing power. Somehow.

My fix
I’m not endorsing this as an “official” bodge fix. I’m not saying this will work for everyone. But it’s worked for me and apparently several other people as well.

The actual problem appears to be the design of the battery compartment. The fault can be replicated at will, either by tipping the mouse on its end and tapping it gently on the desk, or gently dropping it on the desk. Or knocking it against something with little force. A little investigation revealed that the slightest jolt of the mouse and the batteries move relatively easily.

It’s clear that the batteries are losing contact with the metal contacts in the mouse, causing a brief power interruption which in turn causes the loss of radio transmission and ultimately disconnection of the mouse. I fixed this in two ways – packing out the connection between the negative terminal of the batteries with small squares of aluminium foil*, making it more difficult for the batteries to move about. The second way was to pack the bottom of the compartment (between the batteries and the cover) with a small square of paper which would reduce any movement in that direction. Many years ago most battery-powered items had a piece of sponge glued to the compartment cover to act in the same way.

* Take care to ensure you don’t cause the potential for short circuit by allowing the aluminium squares to touch each other.

The ideal fix
Apple actually addresses the issue and designs the battery compartment to stop battery movement and disconnections. Many other companies manage it, so surely it’s safe to say that one of the largest companies in the world, known for its focus on design innovation, should really be able to make this simple issue go away?

Using MySQL triggers for audit logging

If you’ve ever had to create a web application that requires user authentication, you may have been required to implement some sort of audit logging. Whether this would be for auditing user logins, maintaining a history of changes to content or keeping a trail of events in say, a call centre environment, there are various ways to achieve this.

Writing methods/functions to insert audit log methods
The “old” way (for me, at least). I had a database table set up for my audit logs, and I would write a method to write to this table. It would take a few parameters and perform the database write based on these; something like:

public static function auditLogSave($type, $userID, $data) {
  if (empty($type) || empty($userID) || empty($data)) { return false; }

  // Validation code
  // Write to database

  return true;

While there is certainly nothing wrong with the above, there are a few considerations that might make it less than desirable:

  • It’s an additional method call within your code
  • Potential for speed decrease in your application (particularly if you have a lot of audit log calls)
  • What happens when you want to change how the logger works, but in doing so you want to add an additional parameter? Refactoring time just increased significantly…

MySQL triggers
One way I’ve really taken a good grasp on lately is using MySQL triggers to achieve the exact same task. If you haven’t come across MySQL triggers before, take a look at this introduction – they’re a really good weapon to have in your arsenal!

The idea behind using a trigger is that you can write a query – or a selection of queries – and set them up to automatically run based on an INSERT, UPDATE or DELETE.

  • No additional code to run in your application
  • All of the work is taken care of by the database server
  • Changes mean updates to the trigger(s), which is likely to take a small fraction of the time it would take to refactor your entire application.

I’m currently writing a very basic page manager for a transactional-based website and have just deployed triggers to log any changes made to the content. It took me 10 minutes to set up the triggers for two tables and now I don’t have to remember to run any methods in my application code to audit log any changes!

Using SendMail and SELinux on RHEL-based distros

If you’re using SendMail in Linux and have SELinux installed, you may find emails are not being sent. More specifically, you may notice errors appearing in your /var/log/httpd/error_log file:

chdir /var/spool/postfix: Permission denied

SELinux is known to cause unexpected behaviour with many server functions if the defaults are left configured – in this case, Apache doesn’t have SELinux permissions to send email through Postfix.

Check whether this really is the case by issuing the following command in a bash terminal:

/usr/sbin/getsebool httpd_can_sendemail

The expected response will be (depending on the current setting):

httpd_can_sendmail --> (on|off)

If it is off, this can be changed to on by issuing:

sudo setsebool -P httpd_can_sendmail 1

-P in the command sets it to persist, which will retain your setting change when you reboot.

An exciting announcement

WARNING: This post is full of soppy, sentimental content. You have been warned!

Today was a very exciting day for both me and my wife.

My beautiful wife is currently 20 weeks pregnant, and today we went off to hospital for her scan. Those things are really quite amazing – they take your breath away in an instant when you’re sat there looking at your unborn child moving around, its little legs curled up and its hands waving around. The way you can see your baby’s heart beating, and the way the sonographer can actually tell body what is what. I know they’re trained to do that, but they move along at such a pace.

To think that in just over 4 months I’m going to be holding our developing baby in my arms. Those scans are just one amazing way of bonding with your baby in one way or another, even though it hasn’t actually arrived yet.

As it was the 20 week scan, we were asked if we wanted to know the gender. It’s something we have been waiting so long for, and of course we said yes. We were hopeful for a girl, and had gut feelings it was a girl – but if it wasn’t, we wouldn’t be bothered. As long as it’s healthy.

“It’s a girl,” said the sonographer. Big smiles all around :-)

I’m sat here 9 hours on, and still don’t think it’s quite sunk in that we’re having a girl. We already have a name for her, and I’m really, really looking forward to seeing her next year.

Roll on March 2014.

Remote database administration security

I’ve experienced a few cases recently where website owners have requested some work, FTP and MySQL details have been requested and for some reason, remote access to the MySQL database via a GUI such as Navicat or Sequel Pro has been disallowed. Instead, the hosting provider or website owner has insisted specifically on the use of phpMyAdmin, and very often this is for “security reasons”.

This statement alone worries me. phpMyAdmin, as the name suggests, is an administration panel for MySQL written in PHP. It can run on any web server running PHP, and allows a database admin to administer a database from anywhere. It is also open-source and used on a variety of systems, making it a good, useful target for opportunists to look for vulnerabilities, exploit them and potentially access your data.

Remote access can be restricted to certain IP addresses, either via MySQL user accounts or a firewall on the network. It’s really simple to do, and will provide far more security than using an open source application, simply because if done correctly, only the IP addresses specified will be able to connect to the server.

The verdict
phpMyAdmin is a great tool for quickly accessing a database and running small updates. In terms of efficiency, it’s going to fall flat on its face for anything more than an update here or there. Use remote access in conjunction with correctly configured firewall rules and MySQL user accounts to securely access your data.

For extra security goodness, and if your hosting provider allows, use SSH when connecting to MySQL to ensure your data transfers are encrypted between computer and server.

Why drummers post videos on YouTube

I recently had a comment on one of my YouTube videos asking why I would put covers on YouTube, as “1,000,000 other people in the United States can do that.”

Of course, the first thing that is so great about YouTube is that it’s not just limited to the US. I’m from the UK, so maybe 1,000,000 other people in the US can do it – I’m not one of them! 😉

There are a number of really good, really constructive reasons why drummers and other musicians post their videos on YouTube. Let’s look at the obvious first:

The YouTube audience is massive. More than 1 billion unique visits per month. Ironically for the commenter, 70% of YouTube traffic comes from outside the US. Both part of a collection of statistics found on YouTube’s “Statistics” page.

Tied in with the audience factor above, there are always people scouting YouTube, looking for that next big thing. Imagine if today was your lucky day! Certainly happened for Justin Bieber…

And now on to the less obvious…

It’s like a personal log
People improve with any skill when they practice. Over and over again. Having videos as you practice can help you see your progression. It can also help you see where you’re going wrong and where you need to improve.

So many other people do it
This was the point raised in the comment. The comment was posted in a negative, trolling fashion (and I’ve looked at the other comments by this person to other people – said person really does come across as a troll!) However the fact that so many other people do it is a massive benefit to any drummer – personally I watch other drummers before I embark on a cover attempt or try to learn something new. Just by watching people’s techniques you can quickly build up your skills and learn new techniques – and it hasn’t cost you a thing! My next cover video – filmed yesterday – is a cover of Paramore’s “Now”. It’s taken me around 14 hours to learn, refine and film the song on the kit, but if I had to do it all from ear it would have taken so much longer.

The fact that YouTube allows comments on videos means that you can establish a community with people from all over the world, who have similar interests to you. Comments allow you to post constructive feedback to fellow drummers and receive constructive feedback from others. “The sticking at 0:45 isn’t quite right” or “I think there’s a triple bass hit at 2:11″ for example. Another resource to help you learn, refine and improve. Maybe when you listened to the song the first time you missed that triple bass hit, but after seeing the comment and listening back over the song, it’s blaringly obvious.

YouTube is… free?
There’s nothing better than utilising freesources to their full potential – for you. Other people may not benefit and it may take you a while to become established or to find benefits yourself. Certainly the biggest benefit – and inspiration – to me is Cobus Potgieter. He is a drummer that – you guessed it – became “famous” by posting drum covers on YouTube. He’s certainly one of the most talked about YouTube cover drummers on the site, and has done some great things that I am really envious of. It takes serious dedication to fly out complete strangers who have auditioned over the internet to a recording studio, and record an album with them. This formed the band Ventura Lights, and they’re actually pretty good! The cover this comment was placed on was actually a competition entry relating to their band, and is clearly written on the video biog. I guess some people just don’t like reading! :)

My music
I’ve been playing music since I was very small. I find it difficult to write my own original content, but I enjoy simply playing music. There are so many talented artists out there who are able to use their instruments to produce outstanding pieces, over so many genres, and one day I would perhaps like to write a piece or two. My channel is over here, if anyone wants a listen!