Pragmatism in the real world

Turn off foreign key checks when restoring a mysql file dump

I recently received a MySQL dump file where the various tables in it had foreign keys to each other. I usually restore with this command: mysql –login-path=rob < dump.sql but this generated the error: ERROR 1217 (23000) at line 288805: Cannot delete or update a parent row: a foreign key constraint fails It turns out that the easiest way to solve this is to use the –init-command switch to set foreign keys off for this… continue reading.

Extracting the base name of a file in Bash

I have a handy bash script that transcodes videos using Don Meton's video_transcoding tools. This script was written in a hurry and one limitation it had was that it re-transcoded any source file even if the output file already existed. The script looked like this: #!/usr/bin/env bash readonly source_dir="${1:-MKV}" readonly output_dir="${2:-MP4}" for file in "$source_dir"/*.mkv; do ./transcode.sh "$file" "$output_dir" done What it should do is only run transcode.sh if the output file doesn't exist, so… continue reading.

Using Docker to create a MySQL server

When working on test code on my computer, I usually use the built-in PHP server (php -S) which works nicely. Every so often, I need access to MySQL and I use Docker to temporarily create a MySQL server for me. This is how I do it. The magic command is: $ docker run –name mysql \ -e MYSQL_USER=rob -e MYSQL_PASSWORD=123456 -e MYSQL_DATABASE=bookshelf \ -p 3306:3306 -d mysql/mysql-server:5.7 This creates a Docker container called "mysql" on… continue reading.

Getting started writing an Alexa Skill

We now have 4 Amazon Echo devices in the house, and, inspired by a demo LornaJane gave me at DPC, I have decided to write some skills for it. This article covers what I learnt in order to get my first Swift skill working. Our bins are collected by the council every other week; one week it's the green recycling bin and the other week, it's the black waste bin. Rather than looking it up,… continue reading.

Use curl to create a CouchDB admin user

This too me longer to find than it should have done, so I'm writing it here for future me. When you install CouchDB, it is in a mode where anyone can do anything with the database including creating and deleting databases. This is called "Admin Party" mode which is a pretty cool name, but not what I want. Creating admin users To create a user in 1.6 (I've not used 2.0 yet, but assuming it's… continue reading.

View an SSL certificate from the command line

I recently had some trouble with verifying an SSL in PHP on a client's server that I couldn't reproduce anywhere else. It eventually turned out that the client's IT department was presenting a different SSL certificate to the one served by the website. To help me diagnose this, I used this command line script to display the SSL certificate: getcert.sh #!/bin/bash echo | openssl s_client -showcerts -servername !$ -connect $1:443 2>/dev/null \ | openssl x509… continue reading.

View header and body with curl

I recently discovered the -i switch to curl! I have no idea why I didn't know about this before… Curl is one of those tools that every developer should know. It's universal and tends to be available everywhere. When developing APIs, I prefer to use curl to view the output of a request like this: $ curl -v -H "Accept: application/json" https://api.joind.in/ * Trying 178.208.42.30… * Connected to api.joind.in (178.208.42.30) port 443 (#0) * TLS… continue reading.

Proxying SSL via Charles from Vagrant

The Swift application that I'm currently developing gets data from Twitter and I was struggling to get a valid auth token. To solve this, I wanted to see exactly what I was sending to Twitter and so opened up Charles on my Mac to have a look. As my application is running within a Vagrant box running Ubuntu Linux, I needed to tell it to proxy all requests through Charles. To do this, you set… continue reading.

Customising Bootstrap 3

I'm sure everyone already knows this, but it turns out that you can customise Bootstrap 3 without having to understand Less. Part of the reason that I didn't realise this is that I run my web browser windows quite small and regularly don't see the main menu of getbootstrap.com as it's hidden being the "three dashes" button. However, there's an option called Customize on it. This page gives you a massive form where you can… continue reading.

Apigility tutorial on TechPortal

A few days ago, techPortal published my tutorial Create a RESTful API with Apigility. Apigility was announced at ZendCon US in October 2013 and I think that it looks like a useful tool for creating APIs. I particularly like that versioning is built in from the start and that it handles content negotiation. If you want to learn about Apigility, then have a read. The source code is available on GitHub.