Presenting with a Netbook

I’ve been giving a few talks in the last few months and I’m increasingly realising that although I love my thinkpad, its overkill for anything where I don’t really need the hardware, or where I don’t want to be carrying a full-size laptop all day. So I’m increasingly taking just my netbook, which is an acer aspire one with 512 MB of RAM, and using that along with some xrandr skills and my much-loved Kensington Slimblade Presenter Mouse (its the multimedia version, has extra controls on the underneath).

Presenting Setup

The netbook is easily up to this job – it happily runs the open office presenter program, I don’t have the presenter view plugin installed on it yet but just use the screens mirrored and use the netbook screen to see the current slide rather than having to look at the screen. This saves me either having to look away from my audience or from being completely floored by slides WAY too big for me to read when I’m standing in front of them (I presented at the FOWA roadshow, great venue but slides so big I didn’t dare look round at them!). The netbook screen is small but font sizes on slides should be quite big and I’m kind of long sighted so I can read the text at a distance of 6 to 8 feet without an issue.

The presenter mouse has a little USB dongle and then controls for controlling the presentation, with a laser pointer and a button to turn slides to black – once I begin I don’t need to be back within reach of the computer at any point. Which is really useful if you get one of those awkward spaces where the dock for the laptop is in a corner you don’t want to be standing in (I see this a lot at the informal geek events). Just start it going and get into position – and present from there. Of course this relies on knowing the presentation well enough to not need your slides or notes or having a paper copy you can refer to.

Don’t be fooled that you need great hardware or particular equipment to give a talk – anything with a monitor socket to talk to the projector is good enough, and if you can get a remote of some kind then all the better. Other accessories that might help is a stop watch (or use the timer on your phone and put it somewhere you can see it), so you know how you are doing for time, and some notes on index cards that you can easily hold without rustling. Above all, take a step away from your computer and look your audience in the eye – they’re here to see and hear you.

Version Parameters for Web Services

This is a mini series on points to consider when designing and building web services. So far there have been posts on error feedback for web services, auth mechanisms for web services and saving state in web services.

When designing a service API, there are lots of things you can do right, and plenty of pitfalls. Most of both of these are completely specific to the situation you are designing for but I have one tip that has helped me out in a number of scenarios: Include a version parameter with every method call.

This is invaluable, not just in development where you can increment when you change the API (which could be quite often!) but also in production. For example if you want to extend or alter an existing service, you can identify which version of the API the client thinks it is accessing and behave accordingly – either letting them know there’s a new version, or preserving previous behaviours. Its never ideal to change the API of an existing service but sometimes it makes more sense to do so, especially if its just to include an additional parameter or something else quite minor, but which does cause an API change.

When you publish your shiny new service which does everything you need (including the hoovering), it might seem a bit redundant to require a field which is always set to the string “1.0” … but in 18 months time, you’ll be patting yourself on the back.

Saving State in a Web Service

This is a mini series on points to consider when designing and building web services. So far there have been posts on error feedback for web services and auth mechanisms for web services.

Web services, by their very natures, are stateless, and this is no different to any other web application with a frontend. Its often helpful to keep track of the sequence of events something experiences. Similarly we might want to store the details a particular piece of data encounters on its lifetime in the system. When it was created, when it was changed, where in a given process it is up to, and so on.

A good example of this is a service I run for a few friends which accepts a URL, requests it and takes a screenshot, then turns that into a thumbnail and makes it available. There’s a few definite states in that sequence and its better to store which it is than try to guess from which fields have dates in or something. So the states are something like “new”, “error”, “in progress”, “ready” and “expired”. I can look at any of the jobs that come in, at any time, and know exactly where that item is up to.

When Things Go Wrong

It’s also pretty to have a strategy for failure. I already talked about giving users sensible feedback from a service, but the service also needs to keep track of what’s happening. There are decisions to make which depend entirely on the application under consideration but for example whether a failure is terminal, or whether the system should keep trying is quite an important thing to consider. Perhaps you just want to flag records that failed, so you can check on them later. Or you might want to retry – a set number of times? Or at decreasing intervals? An undesirable outcome would be to have the same record submitted every minute (or whatever) forever, so its worth planning to avoid this eventuality. Think also about the likely causes for failure – a split-second glitch or a likely human error which might take a day or two to be noticed and rectified?

Logging

Logging is something which is ideally of zero value. If nothing ever went wrong, you’d never care to look at an individual record and dig into its journey. However in the real world, we do need to be able to debug systems, sometimes under pressure. With logging there are a few different choices – whether to log to file or database, and whether to log continuously, or only at given times. Times when you might want to enable or increase logging are in development and when tracing a bug. However having some background amount of logging (and a way to stop the archives becoming too large) is recommended to keep track of who did what and when. Bear it in mind for a service just as you would for a web application.

Fixing Broken Serendipity Category

I migrated this blog to serendipity almost two years ago, and there have been a few things about it which have always driven me a bit mad. Many of these improved when I upgraded to version 1.4.1 of s9y but a few have persisted, including having two of my sidebar categories not display correctly. Where most of the categories behave as expected, two of of them just didn’t apply any filter at all and all my posts were visible on these pages.

I finally sat down today to diagnose the problem and discovered I was missing a record from the serendipity_permalinks table which was stopping s9y from being able to look up the id of the category. It was my craft category which is id 7 – all I had to do was run the following against mysql:

insert into serendipity_permalinks set permalink = "category/craft", entry_id=7, type="category";

So now my craft category works fine. If anyone knows how to stop my feeds from showing old articles as new when I edit them but don’t update the publication date, I’d be grateful! A bunch of imported posts are still missing their images, would be nice to be able to fix these without polluting my feed.

Updating Memcached on Ubuntu Jaunty

I’ve been working with memcache-related things lately and ran into a problem where the library I was using just didn’t seem to do what its documentation said it would. It turned out that it was making a “gets” call rather than a “get” call – and this functionality wasn’t introduced to memcached until version 1.2.4. Closer inspection shows that although Ubuntu Jaunty Jackalope (9.04) is only a few months old, and memcached 1.2.4 is about 18 months old, its not included and Ubuntu versions Hardy, Intrepid and Jaunty all had 1.2.2 version of memcached.

Credit to the Ubuntu people for resolving this issue already – since memcached 1.2.8 is currently pencilled in for Karmic Koala release of Ubuntu later this year – but I can’t wait that long so I updated my own memcached, it was pretty easy so here are the steps in case anyone else wants to do the same.

  1. download memcached from http://www.danga.com/memcached/download.bml
  2. check you have the dependencies you need. The only thing I didn’t have was the libraries for libevent, which you can install through aptitude with aptitude install libevent-dev
  3. compile as you usually would: configure/make/make install

The final step is to get memcached running – I actually did aptitude remove memcached to get rid of my old version and stop myself from being confused later. Then to start it from command line I used:

/usr/local/bin/memcached -m 64 -p 11211 -u nobody -l 0.0.0.0

The above worked for me and allowed me to use the functionality available in the newer library (specifically I was looking to use the cas (compare and swap) functionality in the new PHP memcached extension) – it probably works on other distros too but I didn’t test it, if it works for you or if you have anything to add then please leave a comment!

Top Tips from Linux-Fu

I have recently been giving a talk entitled “Linux-Fu for PHP Developers” (slides are here) and although it includes some really basic commands, even some quite experienced people have thanked me for particular bits that they picked up. I’m considering dropping some of the sections from this talk so here are the things people most tell me they learned:

cd –

If you pass a single minus as the argument to cd, you will change back into the directory you just came from. Ideal for those switching-between-two-deep-links situations.

pushd and popd

I didn’t include these in my talk formally but I mentioned them almost every time I gave it (or one of the attendees did!). I don’t actually use these commands, but they are like an extension to “cd -” – you can build up stacks of directories and then jump around between them. They sound pretty handy so do take a look.

ls -lrt

I got a lot of negative comments for including “cd” and “ls” in my talks – but I had quite a few people say that the -t (to sort by time) and the -r (to reserve the sort) switches were new to . I use these together for viewing which files are new in a directory, great for logfiles or upload directories.

Hope these are helpful to someone, let me know if you use these or have others you’d like to share!

Architecting Web Services – FOWA Tour

I spoke at the FOWA Tour event in Leeds yesterday, as their local speaker (they set aside a slot for each place they go). It was a great event, good atmosphere and I really enjoyed the both crowd and content. I can’t imagine what the logistics for something like this are like but it seemed like everything was going pretty smoothly.

My talk was “Architecting Web Services” – just a half-hour slot to give an overview of what services are and take a look at some things to bear in mind when designing them. The slides are on slideshare so feel free to take a look and let me know if you have any comments or questions.

I had a great time meeting up with so many friends – old and new – yesterday. Hope that I’ll see some of those again at future events or online. Anyone for Bar Camp Leeds?

Error Feedback for Web Services

I have been thinking, writing and speaking a little bit about web services recently, starting with a few thoughts on authorisation mechanisms for services. Today we’ll look at another really important aspect of authoring web services, and one feature that will definitely get used – error handling and feedback! Having clear and robust error handling in your service will help those trying to consume it immeasurably. Nothing is more annoying that impenetrable errors, unclear responses, or a service which accepts your input but then turns out not to have done what you expected. And I say that from experience.

Stacks of Errors

What’s more annoying than getting an error from a web service? Getting another error from the service every time you fix the first one!

Most services have a few steps of checking incoming variables. Checking that the user has supplied all required fields, and that all incoming fields are of the required format, and that the data they refer to does actually exist – there’s a lot going on here. Too many systems take fright at the first sight of an error, and return straight to the user like a child reporting a sibling’s misdeeds to a parent. I mean something along these lines:

if(!isset($_POST['username'])) {
  return 'username is missing!';
}
if(!isset($_POST['password'])) {
  return 'password is missing!';
}
foreach($_POST as $key => $value) {
  $expected_fields = array(
    "username",
    "password"
  );
  if(!in_array($key,$expected_fields)) {
    return "unexpected field ".$key;
  }
}

What’s more useful is if the user can have a better overall view of everything that is going wrong, since often they might be caused by the same misunderstanding or perhaps be related to one another. So I’m considering code that looks more like this:

$messages = array();
$can_proceed = true;

if(!isset($_POST['username'])) {
  $messages[] = 'username is missing!';
  $can_proceed = false;
}
if(!isset($_POST['password'])) {
  $messages[] = 'password is missing!';
  $can_proceed = false;
}
foreach($_POST as $key => $value) {
  $expected_fields = array(
    "username",
    "password"
  );
  if(!in_array($key,$expected_fields)) {
    $messages[] = "unexpected field ".$key;
    $can_proceed = false;
  }
}

if(!$can_proceed) {
  return $messages;
}

The nice thing about something like this is you’ll see a series of messages where there are problems – so when you mis-spell a field name, you’ll see the “missing field” message for a field you know you are sending, but you’ll also see the “unexpected field” message and hopefully that will make it easier to spot what’s gone amiss.

Error format

Its tempting to return error information in a completely different format, after all it is quite different from the request that probably would have been returned from a correct request. Some web service protocols dictate how errors should be sent – SOAP has the soap-error response, for example. But for something where we have more control, such as an RPC style or REST service, we can choose. Usually I think its appropriate to return an appropriate status code (for REST) or wrapper (for RPC) and then include the error information in the same format as the response would have been. This is mostly for ease of consuming the response, saving clients from having to parse an additional format!

Approaching Errors

Having malformed input to services is inevitable – through misunderstandings, typos, and of course rubbish input by users. Making sure that all these eventualities are gracefully caught and information returned to the user means that the user stands a much better chance of being able to interact successfully. If only the success case works, but the service either doesn’t respond, returns nonsense (or worse, misleading information!), or appears to work but actually hasn’t, your users won’t hang out for long to work out why.

I’ve covered some really basic ideas here but I’m sure there are plenty of other nice ways to help guide users – feel free to add comments for the features you implement in your systems to help users when things aren’t going quite right!

By giving more information to users, it becomes much easier for them to develop against your service quickly and easily – and its not much more to add on the service side.

Speaking at FOWA Tour, Leeds, May 28th

I’m surprised and delighted to announce that I will be one of the speakers at the rather excellent FOWA Tour even in Leeds on 28th May (two weeks today!). The day is like a roadshow version of the famous FOWA conferences, with a morning of (free!) cloud workshops and an afternoon of excellent speakers. I had been hoping to attend this event anyway so to get the invite to speak is very exciting indeed!

My talk is entitled “Architecting Web Services” and will take a look at the types of service available, and identifying functions which would be useful as a service. I’ll run through how decisions about service and format can be taken and we’ll look at some examples of these while we’re at it. I’ve been building a few services lately for one thing and another and I’m pretty excited about the whole topic! Luckily I only have a half-hour on stage but rest assured I’ll probably still be talking about it over drinks later in the day!

Anyone going? Thinking of going? Let me know and make sure to come and say hi on the day :)

Leeds GirlGeek Dinner 27th May 2009

I’m delighted to hear that the date has been set for the next Leeds GirlGeek Dinner – Wednesday May 27th 2009! I’ve been really enjoying this series of events and always meet some really interesting ladies when I attend these events. The idea is to get geek girls together for some talks (and there have been some really good ones in Leeds), some food, some drinks and some networking – men are allowed but only as the invited guest of one of the girlgeeks. This enables us to keep the balance and actually makes for a brilliant atmosphere. Its not often the men in the room are horribly outnumbered :)

This month we have Reshma Sohoni from SeedCamp and Jennifer O’Grady from Democracy PR – and I can’t wait to hear both these women speak and hear their stories. The details are all on the website but in short the event starts at 6pm, its at The Loft Leeds, and I hope I’ll see you there!