Developing software in the Real World

Logging in to Bluemix via wsk

To set up the authentication for the OpenWhisk cli tool wsk you do this:

The host and key are provided to from your OpenWhisk supplier. For Bluemix OpenWhisk, you can find it by logging in and then going to the Download OpenWhisk CLI page. To make my life easier, I use a bash function to swap OpenWhisk environments and I documented it in my Switching OpenWhisk Environments article. Log into Bluemix for API Gateway… continue reading.

Creating an OpenWhisk Alexa skill

In a previous post, I looked at the mechanics of how to create an Alexa skill to tell me which colour bin I needed to put out next. I'll now look at how I chose to implement it in OpenWhisk, using Swift. An Alexa skill consists of a number of intents and you register a single end point to handle them all. As I'm using OpenWhisk, I have direct web access to my actions without… 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.

Simple way to add a filter to Zend-InputFilter

Using Zend-InputFilter is remarkably easy to use:

How do you add your filter to it though? This is the world's most simple filter that does absolutely nothing: We'll call it MyFilter and store it in App\Filter\MyFilter.php:

Now you have a couple of choices: Extend Zend\InputFilter\Factory I needed to add my own filter in the least invasive way that I could and so I created App\InputFilter\Factory which extends Zend\InputFilter\Factory:

This class extends the… continue reading.

Default route arguments in Slim

A friend of mine recently asked how to do default route arguments and route specific configuration in Slim, so I thought I'd write up how to do it. Consider a simple Hello route:

This will display "Hello " for the URL /hello and "Hello Rob" for the URL /hello/Rob. If we wanted a default of "World", we can set an argument on the Route object that is returned from get() (and all the other… continue reading.

Slim's route cache file

When you have a lot of routes, that have parameters, consider using the router's cache file to speed up performance. To do this, you set the routerCacheFile setting to a valid file name. The next time the app is run, then the file is created which contains an associative array with data that means that the router doesn't need to recompile the regular expressions that it uses. For example:

Note that there's no invalidation… continue reading.

Inserting binary data into SQL Server with ZF1 & PHP 7

If you want to insert binary data into SQL Server in Zend Framework 1 then you probably used the trick of setting an array as the parameter's value with the info required by the sqlsrv driver as noted in Some notes on SQL Server blobs with sqlsrv. Essentially you do this;

Where $db is an instance of Zend_Db_Adapter_Sqlsrv. If you use SQL Server with ZF1 and happen to have updated to PHP 7, then… continue reading.

Autocomplete Composer script names on the command line

As I add more and more of my own script targets to my composer.json files, I find that it would be helpful to have tab autocomplete in bash. I asked on Twitter and didn't get an immediate solution and as I had already done something similar for Phing, I rolled up my sleeves and wrote my own. Start by creating a new bash completion file called composer in the bash_completion.d directory. This file needs executable… continue reading.

Switching OpenWhisk environments

When developing with OpenWhisk, it's useful to use separate environments for working locally or on the cloud for development, staging and production of your application. In OpenWhisk terms, this means setting the host and the API key for your wsk command line application.

(Of course, for live and staging, ideally, you will be using a build server!) For a Vagrant install of OpenWhisk, the host is 192.168.33.13 and the key can be found inside… continue reading.

POSTing data using KituraNet

I had a need to send a POST request with a JSON body from Swift and as I had KituraNet and SwiftyJSON already around, it proved to reasonably easy. To send a POST request using KituraNet, I wrote this code:

As you can see, I've liberally commented it, so it should be easy to follow. Let's look at some interesting bits. SwiftJSON is convenient SwiftyJSON does all the heavy lifting of converting dictionaries. As… continue reading.