If you are thinking about building a Twitter bot the first thing you will probably do is google "twitter api". This will likely drop you onto the page for Twitter's REST API. This API is pretty powerful, it allows you to send tweets and retrieve tweets from your timeline and search for tweets with keywords and a whole lot of other stuff. The only drawback (I have found) is that the rate at which you can query the API is throttled so you cannot - for example - search for a tweet every second to detect new tweets as they come in.

Ever since SmarterChild showed up on MSN messenger I have liked the idea of conversing with web-based AIs and it seems like Twitter is a good forum for this, but the query throttling on the REST API does not exactly allow the conversation to flow.

Luckily since 2012 Twitter has provided an additional Streaming API, which allows you to listen for incoming tweets with specific keywords and respond to them instantly as they arrive. It's a conversation starter.

In order to test out the Streaming API I built a simple twitter bot called Calculatweet. If you tweet @calculatweet with a string that may reasonably be parsed as a sum (e.g. 3.14159*3^2/4) then calculatweet should respond quite quickly with a direct tweet to you containing the answer. Have a play with it below.

Feel like a challenge?

Currently Calculatweet is hosted on an Amazon EC2 server. Unfortunately I have not open-sourced the code yet because I am using Calculatweet as a platform for a coding challenge for engineers, which would be a lot easier if they could find the code online.

Very briefly: participants are invited to send Calculatweet a message containing the string "get data" Calculatweet will reply with a message like: "@SimonBox Strain data: ['240.7'; '222.7', '219.3', '221.7', '239.7', '215.2', '239.8', '233.4']". The challenge is to parse those strain data - where the first value is the last filtered value and the subsequent values are new raw measurements. Then participants must combine these recursively in a low pass filter (α = 0.1) and tweet the latest filtered value back to Calculatweet. The main challenge lies in the fact that you have to respond in under one second. In other words you need to build your own Twitter bot using the Streaming API.

Need to model the rotations of a rigid body in six-degrees-of-freedom? Use quaternions.They are *very* cool. I have written a small Matlab/Octave library of functions, for modelling rotations with quaternions. It includes an animated demonstration script which lets you visualize the rotations (see the .gif above). This is really useful for sanity checking your code and helping you to understand what's going on.

Download the 'manageQuaternions' library here: manageQuaternions.zip