Quick way to create a PHP stdClass

A very short and simple trick for creating new stdClass objects without having to set every property individually. This is akin to JavaScript’s object notation, but not quite as elegant. Creating a new object in JavaScript looks like the following example. const x = { a: 'test', b: 'test2', c: 'test3' }; With PHP it is possible to use type casting to convert a simple array into a stdClass object which gives you a similar looking syntax although there is a little more typing required.

Read On →

Functional Programming in PHP Second Edition Available Now

It is with great pleasure that I announce the second edition of the Functional Programming in PHP book that I have been working on. There is twice the content of the first edition of the book as well as updates for PHP 7 and Facebook’s HHVM (HipHop Virtual Machine). There are now more functional techniques and patterns included with pipelines, pattern matching and flat maps among them. I have added a section of the book dedicated to the handy syntax and functionality that HHVM can provide functional programmers with.

Read On →

Importing and aliasing PHP functions

As a follow on to my short post about namespaces and functions from a year ago I thought it would be worth covering importing a specific function and aliasing functions via namespace operators too. This has been possible since PHP 5.6, but there is a nice addition in PHP 7 I’ll cover towards the end. In the previous article I demonstrated how you can namespace functions and use them, but as a refresher; you can enclose functions within a namespace just like a class.

Read On →

Installing pgmodeler on Ubuntu

Pgmodeler is a handy tool for designing databases with an ERD style interface specifically aimed at the PostgreSQL community. It can come in a couple of different ways, but I am going to covering the self build process here. So if you want to learn how to build and install pgmodeler read on! To be able to build anything you’ll need to install the tools from Ubuntu’s repositories. sudo apt-get install gcc libxml2-dev postgresql The first dependency you will need to install is the from QT5 UI toolkit.

Read On →

Tamiya Manta Ray

I’ve finally found some time to look at my old remote control car again - I was so happy when I bought it as a kid nearly twenty years ago. I’ve still got the original nickel cadmium battery (all 1300mAh!) and charger so I charged it up expecting that there’d be little to no response from the car. Amazingly the kids and I got about 5 minutes of full throttle action out of it before it slowed to a halt.

Read On →

Brisbane

Way back in 2007 I arrived in London, England ready to start a new chapter of my life working in the big city. I’d left a good job at a web agency in Melbourne - one of the world’s most livable cities - to experience the financial capital of Europe. It was a fantastic time and so much happened I could write a novel, but here are a few highlights. During my time in England I met my now wife and decided to move to the south coast.

Read On →

Intelligent Vagrant and Ansible files

I use both Vagrant and Ansible to run and provision development virtual machines for testing work locally. This provides an easy to build environment as close to production as possible that all developers can easily create from the source code repository. A simple vagrant up and the associated Ansible scripts will handle all of the configuration and package installation for the VM. This is unbelievably handy and it really helps to reduce the kind of bugs that are difficult to track down - “it works on my machine!” Shared configuration Recently, though I got to thinking about how the configuration is bound up in a rather unhelpful Vagrantfile, which is a Ruby script underneath in reality.

Read On →

Scraping websites with wget and httrack

Scrapes can be useful to take static backups of websites or to catalogue a site before a rebuild. If you do online courses then it can also be useful to have as much of the course material as possible locally. Another use is to download HTML only ebooks for offline reading. There are two ways that I generally do this - one on the command line with wget and another through the GUI with httrack.

Read On →

Crop and resize images with bash and ImageMagick

Not wanting to repeat myself I have written a small bash script to handle the parallel processing of the post images for this site. This involves resizing, cropping and then compressing the images ready for the web. Currently the script supports both JPEG and PNG images for all these operations. On top of this I wanted to ensure that only recently added or modified images would be processed rather than processing the entire folder again.

Read On →

Namespace PHP functions

With the release of PHP 5.3 namespaces became a reality in PHP and they’ve made so much possible including better autoloading. The majority of the time you’ll be used to seeing them at the top of each class file. They can also be used to namespace functions however. A standard PHP namespace declaration would look similar to the following at the top of a class file. namespace Treffynnon\Html; class Tag { // ...

Read On →

SQL style guide

When you’re working in a team you need ways to easily share and denote good style and taste. This is true of your primary programming language with PEP8 for Python and PSRs 1 & 2 for PHP being well known. There is probably even a style guide for HTML and CSS set out at your company. So why should SQL miss out on the party? I have written a style guide for SQL to promote a consistent code style ensuring legible and maintainable projects - sqlstyle.guide.

Read On →

Copyright © 2003 - 2016 Simon Holywell. All rights reserved.