Calculating text width programmatically

There are times when you need to calculate the width of a string of text but do not have access to a text rendering engine.

Letters in a (non-monospaced) font all take up different widths so at minimum we have to build a map of all the available characters we will need. After that there is the complexity of taking into account kerning, this is where certain character pairs are specifically moved closer or further from each other to improve the look of the font.

Combining OpenLayers raster and vector layers for cropping and masking

Openlayers contains the powerful feature which enables you to combine 2 (or more) raster layers using a custom function with access to the pixels of each layer.

As vector layers can also be rendered as raster using the renderMode:image, this can be used to implement client side cropping and/or masking based on any shape.

GET parameter manipulation with PHP

Using a combination of:

The behaviour of http_build_query() to remove parameters when passed null PHP array ‘union’ addition

gives a simple, yet powerful set of native GET parameter manipulation methods.

Device Orientation Test Page

Although device orientation APIs have been around for over 10 years now, they are still a complete mess of competing standards, experimental features and vendor specific prefixes.

This page is inspired by the very useful: timvolodine.github.io/deviceorientation-test, but updated to include API changes which have occurred since.

Slippy Tile Explorer

All the major raster map services use the same 'slippy map' tiling technique to create the grid of images. When dealing with map servers it can be useful to view them.

Here is my basic OpenLayers/OpenStreetMap implementation based around the ol.source.TileDebug and the OpenStreetMap implementation to calculate between coordinate and tile positions.

Using GIT to remotely deploy a PHP project to production

Here is my tried and tested method for setting up GIT to allow pushing from a local repository to production. Note: this is not a post about whether GIT should even be used as a deployment tool so I would recommend you research the pros and cons before selecting any solution.

CSV to SQL Importer

A tool which takes a CSV file, uses the first row as the field names and produces the CREATE TABLE and LOAD DATA SQL commands to import it into MariaDB/MySQL.

GeoHash Explorer

Geohashes provide a well tested method of parcelling the worlds surface into smaller and smaller discrete areas.

When dealing with geospacial data I often find myself returning to them as an elegant and simple technique of implementing searches against the data. There are enough articles out there on how they are created or how to use them for searching so I will not replicate those.

A true RGB565 colour picker

RGB565 is used to represent colours in 16 bits, rather than the 24bit (RGB888) web pages use to specify colours. To make full use of the 16 bits, red and blue are encoded in 5 bits and green in 6 bits. This is due to the human eyes capacity to see more shades of green.

Setup WiFi on a Raspberry Pi 3 with Raspbian Jessie

Getting the WiFi to connect via the command line can be a real pain, especially with the numerous out-of-date guides and lack of feedback during the connection phase. The following guide covers some tips and tricks I have found.

LetsEncrypt SSL certificate on CentOS 7

So, it's been a year since I installed my (paid for) certificate and much has changed in web-land. Chief among them, on the SSL front, has been LetsEncrypt which offers free SSL certificates to anyone who requests them.

Adding an SSL certificate

SSL certificates are so cheap, there really isn't much excuse to not set one up, even on a small site like this. If you don't buy the security arguments, then Google giving a slight SEO boost should be enough of a reason on its own.

URL Diff

A tool (like diff) to show the differences between 2 URLs, in particular including the query string broken down into an object structure.

Calculating Sphinx Memory Usage

Even when you are using on-disk indexes, Sphinx can require a surprising large amount of memory as it has to keep all the index files (except the .spd and .spp ones) in memory. If you have more than a couple of indexes it can be a hassle to calculate the RAM usage manually

Monolog human readable exception email with stack trace

For the times when you just want those exception to be delivered to your inbox with as much information as possible.

Converting over some smaller apps to use monolog I found my favourite snippet for emailing the critical exceptions which bubble to the top of the app wasn't that easy to replicate.

Setting up a CentOS 7.7 webserver on EC2

This is my entire setup process from start to finish. Although there are lots of guides on setting up a webserver with the basic software, they don't often cover the more practical decisions like where web files should be stored and how they are updated. Hopefully this guide should be of some help, if only to show how I have chosen to go.

BeagleBone Black Debian Config

Having got it for an excuse to play with node.js it was disappointing to find the included Angstrom Distribution couldn't even update to anywhere near the newest node.js version and so many tutorials referred to libraries which couldn't be used or didn't exist for it. Queue an embarrassing long time passing with it sitting idle on my desk...

Originally I had wanted to install Fedora, and while there is now support included with v20 (and postings suggesting it is possible to install), BeagleBone themselves have swapped to Debian so I will not fight against the officially chosen OS.

Gearman and GearmanManager build on CentOS 7.0

Gearman is useful when you want to run PHP scripts asynchronously e.g. to build a batch processing cluster or farm out slow running tasks such as email sending which should not block the view being rendered. The GearmanManager addon is not essential but does make the worker code simpler and provides a framework for managing the scripts. Here is my build process:

OpenSeadragon SVG Overlays

OpenSeadragon: An open-source, web-based viewer for zoomable images, implemented in pure JavaScript, for desktop and mobile.
Raphaël: is a small JavaScript library that should simplify your work with vector graphics on the web.

After researching around, no one seemed to have posted a proper working OpenSeadragon/SVG overlay. Let's get these working together for some rich data overlay goodness:

VIPS dzsave build from source on CentOS 7.0

VIPS is a great image processing system capable of working with very large images. In particular it is one of the easiest ways to create deepzoom image pyramids through the use of the dzsave feature.

Since 7.40 it now requires libgsf to be available for dzsave support. Without further ado here is my install process to build VIPS from source on CentOS 7.0: