The Curious Incident of the Dog in the Nighttime

The Curious Incident of the Dog in the Nighttime is an amazing book. I read it a little while back. And now it is an even more amazing play. We got to see it today and it was one of the best pieces of theatre that I've ever seen in my life. 

The play is on tour around the UK at the moment, we got to see one of the final performance in Hull this afternoon. The theatre was packed, and quite right too. 

If you want proper drama, brilliantly staged, massively original and with characters you really care about, then you must, must go if you get the chance. 

Making a Camera

I got a Konstructor camera for Christmas. It reminds me very much of the first camera I ever had, which was made of plastic, had a plastic lens and took photographs which were almost recognisable as the thing it had been pointed at. From the samples online this one has performance quite a bit better than that. But I'm not really looking for quality images here. I'm looking for interesting ones. And I think I'll get those. 

The camera  also reminds me of the Airfix models that I used to carefully construct when I was a kid,  bearing in mind it comes as a kit. I've just spent a very happy evening attaching Part A12 to P11 and whatnot, and with a bit of luck I'll have it finished tomorrow. It actually uses real, proper, 35mm film too. I've got a bunch of cassettes and over the weekend I plan to take some shots and get them developed. I used to love getting my pictures back from the labs and seeing how they come out, now I'll be able to do that again. 

Paddington the Movie

Go see Paddington. You'll enjoy it. It's a rather slight tale, but very well told. It's from the producers of the Harry Potter films. You can tell this because they seem to have employed a large number of British actors who have all worked with the young wizard. 

I wasn't exactly dragged along to the showing. I've always quite liked Paddington. We had one or two of the books by Michael Bond floating around the house as I was growing up and the TV series voiced by Michael Hordern was always good fun. But I was a bit worried about what they might have done with the story when they made it into a film. 

I needn't have been concerned. It is very well done, with some lovely set pieces and running gags. One musical joke is direct steal from "There's Something About Mary", but since they stole it from "Blazing Saddles" that's fair enough. And it was still funny.

If you are like me and want to walk out of the cinema feeling happy, then you should go along. There's enough knowing, and silly, humour to keep grown ups occupied and plenty of slapstick for the kids (and grown ups like me).

I don't go to the pictures to get depressing insights into the human condition, or to learn of the terrible things that people do to each other. I can get all that from five minutes of the news. I go the the cinema for a good time. And you get that from Paddington.

Mistreating a Surface Pro 3

My Surface Pro is really coming into its own now. Folks I know who have purchased new ones recently seem to have a very high opinion of them. None of them are complaining of the issues that I had a while back. Perhaps recent firmware updates have sorted out the problems I was having with suspend and resume. 

So for the last few days I've tried something new with my poor device. I've been treating it abominably.  Up until now I've been very careful about starting up and shutting down and docking and undocking. But recently I've given up on that. I've been snapping the machine in and out of the dock and just closing it when I'm done and opening it up again when I want to work.

It seems to work really well. In fact last night I went a bit too far and undocked the machine while Adobe Lightroom was still running and connected to an external drive. That caused Lightroom a few problems as its universe collapsed around it, but the Surface took it all in its stride. 

The one major difference in my approach is that I'm very careful not to interrupt the machine when it is sorting itself out on startup. Previously I'd press the power button, not see anything happen and then press and prod other buttons. I'd also probably press the power button and close the cover and generally do things that confused things. 

I'm much more careful now. If I want it to shut down I just close the cover. When I open the machine I check by touching the Windows button to see if the Surface is trying to wake up. I get a buzz from the haptic feedback motor in the machine if it is doing something and so I just wait for things to appear, which they have done so far.

I hope this post doesn't jinx things, because at the moment the machine is completely living up to the promise it had when I bought it.  

Getting Started with LittleBits

I'm turning into a bit of a fan of littleBits. They are a bit like Lego, but for electronics. They are rather hard to get hold of in the UK at the moment but I reckon they are worth the effort. Each of the "bits" has magnetic couplings on it that let you snap it to other bits and pass electrical signals around between them. It is intentionally very simple and works very well. 

LittleBits started off making simple circuits which have lights and dials and stuff, but based on the success of those kits they've branched out to make lots of other devices.

While I was in the 'states last year I picked up a Korg synthesizer kit. This is awesome. It lets you make the most amazing sounds.  I'm sure there are computer programs you can use to make these kinds of noises, but for me there's nothing like wiring things together and making sounds with them "the hard way". If I was making a space shooter game I'd definitely be using this kit to do all the sound effects. There are even people on the web who have recorded musical pieces using this simple hardware. And some of them are very good. 

Because each of the bits is compatible with all the others you can plug the sound generation components together with other sensors in the kits and make things like touch controlled musical instruments.

I've been playing with the bits for a while now (I've even got them talking to Windows Phone). In the next few weeks I'll be putting out some posts that tell you how.

Failing Properly

There's nothing like writing a program to get you thinking about how to do things properly. My Magic Marker program is one such example. Turns it it is possible to use it incorrectly. If a file is open when you try to save it (because you've got the spreadsheet open in Excel for example) the save is doomed to fail. Above is the message that you see if you try to save in this situation.

private bool saveEverything()
{
    try
    {
       // write the file
        }
    }

    catch (Exception e)
    {
        System.Windows.MessageBox.Show("File error: " + e.Message,
            "Magic Marker");
        return false;
    }

    return true;
}

This the code that makes it happen. It catches files exception and displays it. It then returns false to indicate that the save has failed.

I've also written the program so that it automatically saves the data when you exit it, which seems sensible. It's what most people will expect to happen these days. But if the save fails when you exit you get this message:

This is the best (i.e. least worst) way I can come up with for dealing with this problem. At least it gives the user the chance to go back and fix the problem (for example they might not have entered a valid mark value which is stopping the save from working).

private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
    if (!saveEverything())
    {
        if (System.Windows.MessageBox.Show(
        "The file save has failed. Do you really want to exit?", "Magic Marker",
         MessageBoxButton.YesNo) != MessageBoxResult.Yes)
            e.Cancel = true;
    }
}

 

Here's the code that makes it happen. This is the event handler for the WindowClosing event for the application page. It tries to save everything and then, if the save fails, gives the user the option to cancel the exit. I've tried to make the answer options (yes or no) directly match the question. 

The only thing I'm not completely happy with is that it is possible for a programmer to use my saveEverything method and ignore the situation where the method doesn't work properly (you don't have to use the result of a method call).

Ideally saveEverything should rethrow the exception or not catch it and rely on the caller to deal with the problem. However, in this case I'm happy to keep things comparatively simple. 

Spell Checking in XAML applications

When I was writing my Magic Marker application I wanted to make my notes input box spell checked. Turns out that this is really, really easy. This is the XAML for the notes texbox. 

<TextBox Name="NotesTextBox" Width="500" Height="315" AcceptsReturn="True" ScrollViewer.CanContentScroll="True" TextWrapping="Wrap" SpellCheck.IsEnabled="True"></TextBox>

I just had to add the one extra property (that I've highlighted above) and it works a treat. 

VISR Virtual Reality from Hull

Visr is a Hull based product development aiming to bring a bit of "other worldliness" into your life. It takes the idea popularised by Google's "cardboard" project and moves it on a notch or two, with the aim of making a properly durable personal virtual reality device powered by your phone. 

It arrives ready built, so you just have to drop your smartphone into the end and set out to explore the new worlds that developers in Hull are working away to create. It looks very interesting, perhaps we should have a "Visr games" section at the next Three Thing Game. 

I've signed up (always one for a new gadget me). You can find the project on Kickstarter here.

json2csharp is magic

Json (JavaScriptObjectNotation) is a really popular way to pass information around on the internets. Lots of services will serve up lumps of json for your programs to munch on. It works very well with JavaScript (which is not surprising) but in the strongly typed world of C# (a great place to be in my opinion) it is a bit of a pain, because C# likes to have proper classes to back up the contents of the Json strings. 

That's where the wonderful json2scharp web page comes in. Grab the chunk of json that you get back from the service (in this case I pulled it straight out of the string in my app while debugging with Visual Studio) and paste it into the window at json2csharp.com and it will spit out all the class definitions that you need.

You can then paste these into your source code and hey-presto, you have all the types that you need to read and work with the json formatted data you just received.

Wonderful stuff.

Robs Magic Marker

In December last year we spent a happy four days marking first year coursework. I'd printed out a marking sheet for each student and we sat down with each one and went through their programs filling in the marks. At the end I had around 200 forms that had been filled in during the marking, the next step is to enter these into the assessment system.

This seems like the hard way to do it, and it is. But it is the only way that I can check to make sure that all the grades from the different makers line up and that every student gets appropriate feedback.

Imagine my joy when I discovered that when I created the assignment on the university assessment system I'd accidentally selected the "anonymous marking" option. This means that the submissions on the system are, ahem, anonymous, not in an alphabetic list like the one that I'd carefully created. And there's no way that I can "de-anonymise" them. So now I have to sort all my paper sheets into numeric order and then run the risk that I'd get things mixed up.

Fortunately I'm a programmer and so I reckoned I could fix this. Turns out that "anonymous" means "indexed by student number", which is something I can easily obtain for each student. And the submission system has a "bulk download" option so I can bring down all the submissions and then fiddle with them on my computer.

I've ended up with a little program that does all the heavy lifting for me. It gets all the entries, matches names with numbers, lets me enter comments and generates the marking spreadsheet ready for upload into the system.

It took me a morning to create (which is around the time that it would have taken me to sort the paper copies) and I can use it with the assignments from now on.  Sometimes you do get progress from your mistakes.....

Update: A sharp eyed reader has spotted that my cunning technique makes a bit of a mockery of "anonymous marking" as it turns out I was able to map the submissions onto the students with just a bit of C#. That's true, and any member of staff who wanted to could find out the author of a so-called "anonymous" work. However, we don't use this technique to prevent this kind of bad thing. Instead we use it to prevent "unconscious bias".

I was not a fan of anonymity when it was introduced, I saw it as a criticism that implied I might be inclined to victimize particular students if I knew who they were. However, it is not like that at all. If I know Fred, and I'm marking Fred's work, then I'm going to bring to the process all my knowledge of what Fred is like. If the mark I come up with is a bit low, but I happen to think that Fred is quite good, I might inflate it to compensate for this. This is unfair. Fred should get the mark the work is worth.

If all I see is the student number when I'm marking it is much less likely that I'll know  that it is Fred who did the work, and the mark I come up with will be impartial. 

In this case we mark the work in front of the student and so the question of anonymity does not arise. The student is in a position to discuss the mark that they have been awarded to make sure that justice is done, and so I don't see a fairness problem in this situation. But I'd never use it to break "proper" anonymity as this actually makes my job more difficult. When I'm marking exam scripts I much prefer not to know who wrote them, this makes it easier to just focus on what is in front of me. 

The Quest for a Tidy Desk

One of my more sensible resolutions is to have a tidy desk where possible. I tried this before and it worked well, until some kind of task based entropy kicked in and things got all untidy again. But today I started with my "making things" desk and it is now a lot more tidy, as you can see above. . 

The idea is to have enough storage space so that I can get something out, work on it and then put it away before moving onto the next task. We'll just have to see how this goes. When I get my office desk tidy (which is presently such a mess that I'm too ashamed to post a picture) then I'll be able to say that I've cracked this one. 

Exploding Robots

So I fancied having a go at building one of these Sainsmart balancing robots. But I wasn't sure how hard they would be to build. So I hatched a cunning plot. Get one for each for myself and number one son as Christmas presents and then, once he had built his and got it working, carefully copy it. 

The plan was working very well until a wire came off my robot and rather than providing a nice friendly 5 volts to the robot controller it delivered a much more unpleasant 11.3 volts. This did not end well. The voltage surge took out the Arduino board, the radio receiver and the gyroscope. Around ten pounds worth of damage. Wah. 

The good news is that the spares arrived today and my robot is now back on his wheels, lurching around the kitchen under sort of remote control. Getting the robot to balance was a bit of a challenge, my top tip is to just use the values given at the end of this video

I'm looking forward to adding a few more features.  Ideally I'd like to make him self tuning, or at least be able to tune the PID loop using the remote control rather than the fiddly trimmers that are supplied.

The kit is good value, the components are good quality and you get a lot of them. This would serve as the basis of a lot of interesting projects. 

Roundabout is Crazy-Wonderful

The Roundabout game is completely crackers. You play the role of Georgio Manos, 'arguably the world's most famous revolving chauffeur'. Your job is to drive a bunch of wacky characters around the town of roundabout using a constantly rotating limousine.

The game is a fantastic example of how an interesting movement mechanic (timing the moves of your spinning car around obstacles including, er, roundabouts) has been used as the basis of a weird but wonderful narrative built around the strange folk who want to be taken for a ride. 

The whole affair, from the knowing dodginess of the acting to the crackers story, is a delight. You'll play through it in an afternoon (at least that is what number one son did) but there are missions aplenty once you've finished.  You can find it here.