Tuesday, 23 September 2014

AWS Ubuntu Server 14.04 install LAMP stack

I've done this more times than I care to remember lately so I'm going to remember it here.

Boot up an AWS Ubuntu Server 14.04 instance, use MobaXterm to log in with ubuntu as the username then:

sudo apt-get update

Don't worry about grub - it's not used as far as I'm aware

sudo apt-get upgrade

Install LAMP (don't forget a password for root on MySQL)

sudo apt-get install lamp-server^

The web-root directory is /var/www/html so we'll give ourselves permission to play there using (adapted from Ulyssesonline):

sudo chgrp www-data /var/www/html
sudo chmod 775 /var/www/html
sudo chmod g+s /var/www/html
sudo usermod -a -G www-data ubuntu
sudo chown ubuntu /var/www/html/

We'll also need curl:

sudo apt-get install php5-curl

and Mcrypt:

sudo apt-get install php5-mcrypt
sudo php5enmod mcrypt
sudo service apache2 reload

Sort out Mod-rewrite

sudo a2enmod rewrite
sudo service apache2 restart

Move to web-root

cd /var/www/html/

Next to figure out how to install Laravel.

Wednesday, 17 September 2014

Well done Ash!

Thursday, 11 September 2014

PHP: Sorting an array by value (UK formatted date string)

function cmp($a, $b)
    $a_int = DateTime::createFromFormat('j/m/Y', $a["date"])->getTimestamp();
    $b_int = DateTime::createFromFormat('j/m/Y', $b["date"])->getTimestamp();
    return ($a_int == $b_int) ? 0 : ($a_int < $b_int) ? 1 : -1;

Dead simple isn't it? I end up using this a lot so maybe it'll be of use to someone else?

Call it like this:

    usort($arr, "cmp");

Monday, 8 September 2014

Hungarian notation for variables

So I've been playing with functional programming for a week or so and I'm getting somewhat lost with Scala's use of var (something I use all the time with JavaScript and something I keep writing in PHP ;-)) and val. I generally love that both JavaScript and PHP aren't strongly-typed but while I'm learning other things I guessed that it's be better to have a general idea about the type of values held by a variable. Then I clocked that Medhi had sent me something he'd found a couple of weeks ago. Brilliant!

Variable represents a node.
Variable represents an object.
Variable represents an array.
variable is a string.
Variable holds an integer value.
Variable represents a function.

I'm putting it up here as a reference.

Monday, 1 September 2014

More Date sorting for Datatables

My use case was that I display a figure either for a month and year or a specific date (in UK date format (i.e. day/month/year)) and that I need to filter on that date within a DataTable. I of course used the cracking Moment.js but I need to parse dates in different ways depending upon whether or not the figure was MMMM YYYY or DD/MM/YYYY. Dead simple using a regex test:

$.extend( jQuery.fn.dataTableExt.oSort, {
    "date-time-odd-pre": function (a){
            return parseInt(moment(a, "DD/MM/YYYY").format("X"), 10);
            return parseInt(moment(a, "MMMM YYYY").format("X"), 10);
    "date-time-odd-asc": function (a, b) {
        return a - b;
    "date-time-odd-desc": function (a, b) {
        return b - a;