PHP Logo

Bogo Sort In PHP

23rd June 2018 - 4 minutes read time

I came across this sorting algorithm the other day called 'bogo sort'. This is a sort of joke sorting algorithm that is highly ineffective at actually sorting arrays. The name comes from the word 'bogus'.

Here is how it works.

  1. Take an array.
  2. Shuffle it.
  3. If the array sorted then stop.
  4. If the array is not sorted then return to step 2.

As you can see, this isn't so much a sorting algorithm, more of a game of chance. Due to the random nature of the sort you might need to wait a very long time before the array is actually sorted.

Here is an implementation of a bogo sort in PHP.

PHP Logo

An Implementation Of Array Binary Search In PHP

19th June 2018 - 4 minutes read time

I have been doing some reading and watching lectures of programming theory recently and I was reminded of this algorithm I learned about in university. Binary searching an array is a divide and conquer algorithm that takes an array and searches for a value in that array by splitting the array into halves. The algorithm works like this.

Drupal Logo

Drupal 8: Custom Ordering Of Comments

10th June 2018 - 7 minutes read time

Drupal 8's comment system has the ability to be threaded so that users can reply directly to other users comments and create threads of conversation. I have always found this difficult to use and difficult to read so I wanted to turn it off when I set up this site. The only issue I had was I could turn off the threading but couldn't alter the ordering of the comments.

The default ordering of comments in Drupal 8 is by thread. This means that even if you turn off threading the comments are always displayed in thread order. The CommentDefaultFormatter class is used by Drupal to display comments and contains this line of code.

PHP Logo

Color Sorting In PHP

9th June 2018 - 14 minutes read time

Sorting colors is the sort of thing that you never really think about until you need to do it. Sorting a bunch of items by their color is useful in a number of applications, but the simplest is just to display items to the user in a more controlled manner. As it happens sorting with colors is a much more complex topic than I originally thought and required digging into quite a bit more maths than I expected.

Incidentally, there is a whole world of color maths that I didn't know existed until I started looking into this. It was worth learning about though.

Setting Up

To start with, I created a little Color class so that I could have a standard way of storing a color. This just takes the red, green and blue values for a color and allows a simple way of accessing those values.

PHP Logo

Setting Up A Linux And Apache Server For Deployer

17th May 2018 - 7 minutes read time

Deployer is an amazing tool that is used to deploy websites (hence the name). I have looked at other tools, but because Deployer is built and run using PHP, using it to deploy PHP sites makes sense. It also means that I don't have to figure out complex XML documents or learn Ruby just to understand what the deployment is doing.

I have been using Deployer for a little while now to deploy my own site but I have been using the root user to accoumplish the deployments to get around any permissions issues. When I sat down with the developers at work we looked into how to setup the server so that deployments could be run without giving the tool unfettered access to the server. To this end we set out a plan to create a 'deployer' user on our servers that would be the user Deployer uses to deploy sites.

Collecting Information

Drupal Logo

Drupal 8: Date Search Boosting With Search API And Solr Search

15th May 2018 - 7 minutes read time

The Search API Solr Search module has a bunch of controls for boosting certain fields. This allows you to give more weight (i.e. boost) to the title and less weight to the body, which means that when a search term appears in the title of a page it has more weight than a page that only has the term in the body. This weight value is ultimately used to calculate the score of the page and this directly effects the ordering of results.

Drupal Logo

Setting Up Drush Aliases And Using sql-sync

2nd May 2018 - 8 minutes read time

Drush sql-sync is a very easy way of grabbing a copy of a Drupal database from one site and installing it on another site. The normal application of this task is to copy the database from the production site to your local environment for facilitate local development. There are one or two steps to sort out before you can use the command

This post assumes you have Drush 8 installed on your machine as Drush 9 uses a different syntax for sotring Drush aliases. This also assumes that you have setup SSH key access to all servers you need to get access to.

Setting Up Aliases

The first thing you need to do is set up your Drush aliases, this allows you to connect to the remote Drupal instance from your local machine. Drush aliases are kept in your ~/.drush directory. To see what aliases you have on your system use the command.

Drupal Logo

DrupalCamp London 2018

18th March 2018 - 13 minutes read time

It's been a couple of weeks since DrupalCamp London 2018 so I thought I would try to write up my experiences for the weekend. DrupalCamp London ran from 2nd to the 4th of March and consisted of a CxO day before a 2 day conference.

Getting to the conference this year was a little more troublesome than usual. The snow and frost from that week had caused chaos on the trains (not to mention the roads) and so after many cancellations and delays I eventually made it to London the night before the Saturday/Sunday conference. The snow didn’t just affect me though, a few people couldn’t make it and a few sessions had to be rearranged. Thankfully, everyone made it to the camp in the end.

Drupal Logo

Drupal 8 : How To Avoid Block Caching

11th February 2018 - 5 minutes read time

I was struggling with a problem on a Drupal 8 project that was in development recently where a block used to show information to anonymous users was cached for the first user who saw it. This meant that the special message meant for the first user was then being seen by all subsequent users who visited that page. This only happened when page caching was turned on, but as it's best practice to do that I didn't want to turn that off just to solve one little problem.

Drupal Logo

NWDUG Unconference 2017: A Review

20th November 2017 - 9 minutes read time
For the past few months I have been organising an unconference event with †he other organisers of the North West Drupal User Group (NWDUG). An unconference is just like a normal conference, with the exception of the sessions. All of the sessions are selected on the day and then presented by the delegates. Thankfully, everything came together and on November the 4th at MadLab in Manchester we had 55 people show up for the day. Once we introduced the day and got some sessions on the wall we started out.