Pragmatism in the real world

Making Slack accessible on macOS

I've written before about how I tend to use my Mac via the keyboard as much as possible to minimise pain in my arm. Possibly the best application on macOS to facilitate this is Shortcat which enables me to point and click at any UI element in any native Mac app. I rely on it a lot and it makes nearly every app I use accessible to me. Recently, Slack updated their desktop app so… continue reading.

A note on framework performance

A question came up recently wondering why Slim Framework was around 5 times slower than plain PHP. All frameworks are by definition slower than no-code as there's more going on. i.e. an index.php of: <?php header('Content-Type: application/json'); echo json_encode(['result' => 1]); is going to be much faster than a Slim application with this code: use \Slim\App; include 'vendor/autoload.php'; $config = include 'Config/Container.php'; $app = new App($config); $app->get('/do-it', function($request, $response){ return $response->withJson(['result' => 1]); }); $app->run();… continue reading.

Homestead per-project crib sheet

I wanted a drop-dead simple way to try and replicate a problem someone was having on the Slim forums. I couldn't reproduce with php -S which is my go-to for this sort of thing, so I thought I'd try Homestead. I had recently listend to a Voices of the Elephpant episode with Taylor Otwell & Joe Ferguson where Joe mentioned that Homestead worked on a per-project basis too. I didn't know this, so tried it… continue reading.

Automatic OCR with Hazel and PDFPen

I have a useful scanner as part of my networked HP printer that will scan directly to a shared directory on my computer. Once there, I want the file to be renamed to the current date and the document OCR'd so that I can search it. To do this, I use Hazel and PDFPen and this is a note to ensure that I can remember to do it again if I ever need to! Firstly,… continue reading.

Using Phive to manage PHPUnit

I recently came across the Phive project and have had a play with it. Phive is part of phar.io and is intended to manage development tools such as PHPUnit in preference to using Composer's dev dependencies. The main advantages of Phive are that it uses the phar file of the tool and only keeps one copy of each version rather than downloading a new copy into each project. How it works Phive stores one copy… continue reading.

2016 in pictures

Another year has passed which gives me an excuse to to reflect on what's happened. As usual, I look at the photos that I've taken and frame my thoughts around them. January At the very end of January I visited Phoenix, Arizona to see Evan, Priscilla & other friends. I also attended FOSDEM again and spent a tourist day in Brussels. February I was fortunate enough to speak at PHPUK again in February. March The… continue reading.

SSH keys in macOS Sierra

Now that I've upgraded to macOS 10.12 Sierra, I noticed that SSH required me to enter my passphrase to keys every time I used them. This was a surprise as it's not how 10.11 El Capitan worked. This is how to fix it. Firstly, add your SSH key's passphrase to the keychain using ssh-add -K ~/.ssh/id_rsa (or any other key file). You can now use your SSH key without re-typing the password all the time… continue reading.

Handling JSON data errors in Slim 3

When you send JSON data into a Slim Framework application with a content-type of application/json, then Slim will decode it for you if you use getParsedBody(): $app->post("/", function ($request, $response, $args) { $input = $request->getParsedBody(); var_dump($input);exit; }); Using curl to test: $ curl -H "Content-Type: application/json" http://localhost:8888 -d '{"foo": "bar"}' array(1) { 'foo' => string(3) "bar" } If there's an error however, you get this: $ curl -H "Content-Type: application/json" http://localhost:8888 -d '{foo: bar}' NULL… 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.

PHPNW 2016 API Tutorial

If you're attending my Building Modern APIs in PHP tutorial at PHPNW 2016, please bring a laptop with the following installed: * PHP 7 with the sqlite extension installed * curl command line tool * https://akrabat.com/stuff/2016-09-30-PHPNW-Slim-API-Tutorial.zip extracted to a convenient directory Thanks. I'm looking forward to it and hope you are too! Oh, and if you don't have an ticket yet, they are still available.