Connecting to MQ Light from a web app via WebSockets

May 25th, 2015

How to subscribe to MQ Light notifications from a web app, via a WebSockets bridge

I’ve been working on a microservices app hosted on Bluemix. It’s one logical app, but it’s implemented and deployed as a bunch of separate Bluemix applications, each with it’s own separate responsibility.

I’m using MQ Light as asynchronous messaging between the apps. Each Bluemix app publishes notifications about changes to resources, and the status of long-running tasks.

mqlight on Bluemix

I won’t labour why or how we do this here, as it’s well covered in many other posts on microservices. For example:

…publish everything, however boring and insignificant it may seem to the rest of the system. Publishing is very lightweight and the publisher does not need to know whether 0 or 1000 other services are interested in that particular event, just fire and forget. This is extremely powerful and is what enables microservices to be built and deployed extremely quickly…

This is working well, but I also want a web app to be able to get some of these notifications.

If the web app has a resource open for editing, I want it to get a push notification if there are any changes to the resource.

If the web app started a long-running task, I want it to get push notifications of status changes.

I’ve done this by writing a small proxy, allowing a web app to subscribe to MQ Light topics and get the message via WebSockets.

Essentially, it’s an mqlight-WebSockets bridge.

mqlight with WebSockets on Bluemix

Read the rest of this entry »

The skills implications of Cognitive Computing

April 29th, 2015

STEMtech is a conference about the education of science, technology, engineering and maths. The attendees are an interesting mix of people from education and policy makers, as well as people like me from industry.

This year, they invited me to do a talk. My slides are shared but they’ll make no sense by themselves. What follows is roughly what I think I said.

Read the rest of this entry »

Recycling: a Scratch game for Code Club

April 19th, 2015

Grace and Faith have been helping me work on a new project for Code Club. It’s not quite finished yet (Excuse: Thanks to the holidays, it’s still over a week till my next Code Club class!), but it’s close enough that I thought it’s worth sharing the work-in-progress.

The basic idea (more than a little inspired by an old Mega Drive game we’ve played) is that you have to catch falling bits of rubbish and put them in the correct recycling bin.

A playable version is embedded here if you’re using a Flash-friendly browser. Press the green flag to start, use the arrow keys to run left and right, and press the space bar to throw what you’re carrying. (If the embed isn’t working, you can also get to it on the Scratch website.)

I’ve started writing up how we made it, using Code Club’s lesson format tool. (A tool that reads Markdown with a few Code Club-specific extras).

The write-up is still a little rough around the edges, but the source for what we’ve got so far is on github.

And I’ve used lesson_format to create HTML and PDF versions in the Code Club style.

How to use the IBM Watson Relationship Extraction service on Bluemix

January 25th, 2015

Before Christmas, I wrote about how I used the Watson Relationship Extraction service on Bluemix to pick out the things mentioned in news stories, as part of a mobile app we built on a hackday. I’d still like to do something more with that app, but in the meantime I should at least share how I did the Relationship Extraction bit.

From the official doc for the service:

From unstructured text, Relationship Extraction can extract entities (such as people, locations, organizations, events), and the relationships between these entities (such as person employed-by organization, person resides-in location).

This is provided as a hosted service on IBM Bluemix where any developer can sign up and give it a try.

It’s available as a documented REST API, but as part of using it in the hackday, I needed to write a bit of code around that, just to prepare the request and parse the response. I think it’ll save me time to reuse this the next time I want to build something with the API, so I’m sharing it as a standalone package.

In this post, I’ll walk though how you can use it, with a small app that grabs the contents of a BBC News story and picks out the names of people mentioned in the story.

Read the rest of this entry »

Watson News Companion

December 12th, 2014

newscompanion screenshotWe recently ran a hackathon at work: people within IBM were invited to try building a mobile app aimed at consumers using Watson services. It was a fun chance to try out some new ideas, as well as to build something using our APIs – dogfooding is always a good thing.

I worked on a hack with David which we submitted on Wednesday. This is what we came up with, and how we built it.

The idea

A mobile app that will help users to digest the news by explaining references in stories and providing greater context.

Background

It’s difficult to find the time nowadays to properly read and understand what’s going on in the world. We rarely have the time to sit and read through a newspaper. Instead, we might quickly read news stories online from our smartphones and tablets. But that often makes it difficult to understand the broader context that a story is in. There might be references in the story to people, places, organisations or events that are unfamiliar.

Watson could help. It could be an assistant as you read the news, explaining unfamiliar references and the broader context.

Features

Our Watson News Companion demo is a mobile news reader app that:

  • anticipates questions and suggests areas where it can help improve understanding
  • provides answers to questions without needing the users to lose their place in the story
  • allow the user to dig deeper with their own follow-up questions


A video walkthrough of the hack

Read the rest of this entry »

Parsing roman numerals with Python

November 2nd, 2014

Or… how I managed to make some of Grace’s maths homework into another Code Club session

IMG_0355 Grace had some maths homework to do this weekend, converting a bunch of roman numerals into normal numbers.

Being an interfering sort of parent, I got her to show me what she’d done when she finished.

I could see that she’d gotten a lot of them wrong. She had missed the subtraction you’re supposed to do when a large value follows a smaller value.

I’m a big fan of rubber duck problem solving, but she hadn’t spotted that she’d gone wrong. I decided to try something similar.

Read the rest of this entry »

Comparing XML files ignoring order of attributes and child elements

October 6th, 2014

I need to diff some XML files.

For these particular XML files, order is not important. The XML is being used to contain a set of things, not a list – the order of the elements has no significance. Similarly, the order of the attributes within each element isn’t significant.

For example, for my purposes, these two XML files are equivalent:

<myroot>
    <mychild id="123">
        <fruit>apple</fruit>
        <test hello="world" brackets="angled" question="answers"/>
        <comment>This is a comment</comment>
    </mychild>
    <mychild id="456">
        <fruit>banana</fruit>
    </mychild>
    <mychild id="789">
        <fruit>orange</fruit>
        <test brackets="round" hello="greeting">
            <number>111</number>
        </test>
        <dates>
              <modified>123</modified>
              <created>253</created>
              <accessed>44</accessed>
        </dates>
    </mychild>
</myroot>
<myroot>
    <mychild id="789">
        <fruit>orange</fruit>
        <test hello="greeting" brackets="round">
            <number>111</number>
        </test>
        <dates>
              <accessed>44</accessed>    
              <modified>123</modified>
              <created>253</created>
        </dates>
    </mychild>
    <mychild id="123">
        <test question="answers" hello="world" brackets="angled"/>
        <comment>This is a comment</comment>
        <fruit>apple</fruit>
    </mychild>
    <mychild id="456">
        <fruit>banana</fruit>
    </mychild>
</myroot>

I needed to compare some large XML files, which have big differences in the order of elements, and I couldn’t find a tool that would do the job. So I wrote a bit of Python to do it for me.

Read the rest of this entry »

Kids should learn to code

September 27th, 2014

Does a five-year-old need to learn how to code?

A couple of weeks ago I was interviewed by the BBC. In a fairly long phone call, I either rambled inanely or provided detailed and nuanced answers in context. That depends on your point of view.

Either way, obviously not a lot of it could make it into their story, as they really only needed a few quotes. So I thought I’d put more of what I said here.

The background for the story was the changes to the UK school curriculum which means that all kids are being taught to code. And the basic premise for the piece was that as we’re “entering an era when computers are actually beginning to teach themselves” that this is unnecessary and that coding itself is becoming an outdated skill.

Read the rest of this entry »