Archive for June, 2016

Combining arrays in PHP

Monday, June 6th, 2016 | Programming

html-code

If you need to combine two arrays in PHP, you first thought might be to use the + operator. However, this is unlikely to do what you want it to to. If we look at the following example, you might expect it to output an array with all three elements.

<?php

$listA = ['banana'];
$listB = ['apple', 'pear'];
$listC = $listA + $listB;

var_dump($listC);

However, what you will actually get back is an array containing two elements: banana and pear. This is because when you use the + operator in PHP it combines it using array keys. Even though these are non-indexed arrays, PHP looks at them like this:

[0 => 'banana']
[0 => 'apple', 1 => 'pear']

Therefore when you add them together, it combines the keys, taking the earliest. In this case, to get the result you want, you want to use the array_merge function. For other scenarios, PHP has a range of different functions to combine arrays in different ways.

Word Search, a PHP library

Sunday, June 5th, 2016 | News, Programming

Have you ever been working on a PHP project and found yourself thinking “what I really need is a way to quickly and easily drop a word search in to this code”? The answer is almost certainly, no.

However, while working on Learn Finnish I found myself in exactly this situation. Being unable to find a good library, I wrote one and published it on GitHub. It is freely available under the MIT license and registered with Composer:

composer require xmeltrut/WordSearch "^1.0"

All you have to do is pass in some words and it will generate a puzzle. It supports horizontal and vertical words, intersecting words and comes with two alphabets by default: English and Finnish.

If you’re feeling generous, head over to GitHub and star it.

word-search

Autoprefixer

Saturday, June 4th, 2016 | Programming

html-code

Web browsers come in various shapes and sizes: different users will have different ones, and inevitably different versions of the same one. When CSS3 arrived browsers began adding support for it before the specification had been finalised and so used vendor prefixes.

The result, now we have a standardised CSS3, is that some users have proper CSS3 support and some have the support, but only behind a complicated series of vendor names. Therefore, if you want to use flexbox for example, you cannot just rely on display: fiex; as for some users it will only work with the appropriate vendor prefix.

This means you have to tediously insert all of these vendor prefix statements to get cross-browser compatibility. However, there is a tool called Autoprefixer that takes this hassle away. It is an NPM module that converts your regular CSS into CSS with vendor prefixes. You write:

display: flex;

And you get:

display: -webkit-flex;
display: -ms-flexbox;
display: flex;

This means you have to compile your CSS. However, if you are already compiling from LESS or SASS, it’s really easy to integrate it. On one of my current projects I already had Gulp compiling SASS, so it was one-liner to add the step in. SitePoint have a tutorial on how to set it up.

Harrogate pubs

Friday, June 3rd, 2016 | Friends

A few years ago, while I was working up in Harrogate, my friend Alan and I refined the art of pub lunch. At Buzz, Jason and I achieved pub week, which was no mean feet. However, we could only dream of the system Alan and I put in place. Sometimes with other colleagues, sometimes not, we got it down to a schedule.

Day Pub Notes
Monday Smiths Arms Nice way to start the week. Food was okay. Mostly, it was close.
Tuesday Squinting Cat Quiet, plenty of tables, big range of food and the barman was a character.
Wednesday Black Swan, Fat Badger Usally Black Swan, but occasionally we would drive into the centre for the Fat Badger.
Thursday Old Spring Well, Pine Martin Good specials, though roadworks severely hampered our journey times, in which case we would fall back to the Pine Martin.
Friday Square & Compass Bit of a drive to North Rigton, but worth it for the food.

This went on for months. We managed two team lunches in my current team this week. That was great, but I can only dream of the glory days…

old-spring-well

Mary Berry’s Absolute Favourites

Thursday, June 2nd, 2016 | Books, Food

Absolute Favourites is 2015 cookbook by Mary Berry. It ties in to a TV show that I haven’t seen.

One of the things that Elina always comments on is how practical Mary is, especially in comparison to Paul Hollywood. Hollywood will insists on all kinds of different kitchen implements, whereas Mary will usually find a way to re-use the same bowl. This shines through in the book. Most of the recipes have a “you can do this bit in advance” or “make this and freeze it for later” section.

I was very much amused by comments such as “teenagers will love this”. It is organised by meal time and does classic dishes: steak with peppercorn sauce, meatballs in tomato sauce, fish pie. It still feels contemporary though: chilli burgers, sticky chicken and tapas all put in an appearance. The dishes are easy to make too.

Where perhaps it falls down in our kitchen is that perhaps the quintessentially English dishes are just a little bit boring. I felt like I was going easy on myself when I picked one of these up. The food does not suffer because of it though: everything we did was reasonably tasty or better.

My two favourite dishes were the lentil shepherd’s pie, a great alternative if you want to cut down on your meat intake, and the fish pie (shown below).

fish-pie

This is a super recipe that uses chunks of bread as croutons that you sit on top and toast slightly, revealing a sea of fish pie underneath.

This isn’t the most adventurous cookbook I have had but it has a lot going for it: the recipes are simple, easy to get right, have scope for pre-paring many of them and produce lovely results. Well worth investing in if you want to cook some English.

mary-berry-absolute-favourites

Warehouse of Gifts

Wednesday, June 1st, 2016 | Public Speaking, Video

Two days after I delivered Speak from the Heart at Leeds City, I delivered a speech called “Warehouse of Gifts” at Asselby Speakers. It was another speech I had written to try and develop my personal stories and improve the emotion in my speeches.

I did not go there with high hopes. The speech was rough, the idea was clichéd, and I was doing the whole thing in a Finland hockey jersey. However, it actually went a lot better than the other one did. People liked it.

Asselby Speakers is a great place to take a speech. It is an advanced club, only open to Competent Communicators. The result is that you get unparalleled feedback. Speeches that regular clubs fail to give any suggestions, Asselby will give you an A4 page full, which is what you want at this level.