Updated C# Yellow Book available for download

I got an email over the weekend from Drew about a glaring typo in my downloadable edition of the C# Yellow Book. I was about to respond that I’d fixed the error when I thought I’d better check first. It turned out that I hadn’t.

So I’ve spent this morning going through all the reports of issues with the book and fixing them. Most of them have been typing mistakes but I’ve also made a few changes to make some things easier to understand. I’ve completely reworked the section on thread safety to incorporate a more meaningful example.

Thanks to Liz, Dina, Lilli, Neil, Richard, William, Don, Bram, Mitch, Jaswinder, Javi, Peter, Justin, James, Mike, Ian, Papartis, and Drew who took the trouble to get in touch and help me make the book even better.

You can download it here.

Tensorflow for Arduino

At the DDD last week I was talking to a young lad who had been to my IoT talk and wanted to make a voice controlled device. At the time we talked I was thinking that this is the kind of thing that you would push into the cloud for processing. However, TensorFlow Lite is now a proper part of the Arduino libraries (you can just add it as you would any other device driver - search for Tensor).

One of the examples actually does voice recognition on the device. I’ve not found anyone who has got this working on the ESP32 but it would be wonderful if it was possible.

Ikea on Sunday

After Lego on Saturday we continued our Scandinavian themed weekend by going to Ikea on Sunday. There was some method in our madness, in that we went right at the start of the day when it wasn’t supposed to be that busy - although it was still a lot busier than I expected.

We didn’t get out without spending something though, they had a nice line in wireless chargers for a not too bad price.

Cups of Lego are a thing

Saturday finds us in the Lego store in Leeds. The back of the store is filled with dispensers for individual pieces. I’ve never found these very interesting, but today it turns out that they are the only way to get the pieces for the nice little Halloween themed bat and ghost designs they had in store.

So we went round and filled a pot. The cost was 6.99 which compares favourably with the price of a set with a similar number of pieces. And you get to keep the pot. This meant I was able to distract myself during Strictly Come Dancing by building the models and then working out what to do with the rather large number of bits I had left.

I realise that this will probably require the use of more imagination on my part than just buying a kit, but I can see me picking up a pot full of interesting colours and shapes on my occasional visits to the store. It also raises the prospect of buying particular Lego bricks to make custom cases for devices and perhaps even gluing them together.

Bang Dice Game

We had a bunch of folks round this week and spent a while playing the “Bang!” dice game. It’s great fun. The sheriff and the deputies have to kill off the pesky outlaws before the sheriff gets shot, while the renegade just has to be the last man standing.

The dice action is fun and nicely unpredictable, although this can result in you being shot out of the game early on. The way that nobody knows who anybody is at the start of the game is fun, but it can result in deputies taking multiple hits from a sheriff who just wanted to begin the game by going “pew, pew, pew, pew” because he got the dice to do that. Worth getting.

Take a look at Jupyter

If I was still teaching a programming course (those were the days) I’d be taking a very long, hard, look at Jupyter. It’s a web based active notebook where the pages can contain text, images, programs and outputs from programs. You can write your code into blocks on the page, hit run and see the output. And you do this inside your browser.

I’ve had a go with Python and JavaScript and they just work. You can also use C# as well. It would make it possible to create an interactive text book which contained code and output that readers could play with in the text. You can also use it to create interactive labs in other things too. We’re working on some curriculum for experiments with particle sensors and I’m going to take a look at how we could use Jupyter to do this.

An apology

I feel that I must apologise for the blog post yesterday. Readers with long memories will no doubt be feeling short changed by the way that I failed to meet their appetite for new, relevant articles and recycled an old one from 16 years ago.

I’m not the kind of person who fill his blog with old posts from way back. But I am the kind of person who fills his blog with apologies for posting old posts from way back.

Maybe tomorrow I’ll apologise for this post…..

Magic from the Wayback Machine

If you think that the current internet is a bit of a time sink, try taking a look at the past one.

I’ve been playing with the wayback machine, which has been carefully salting away copies of my deathless prose for around twenty years or so. I’ve just lost a big chunk time reading stuff I wrote ages ago. But some if it I rather like. Take this one, about debugging and magic that I wrote on 25th September 2003.

The Power of Magic

Been thinking about debugging (as one does). Debugging is what you do when the program doesn't work. Or works but does the wrong thing (nearly the same problem). The thoughts were prompted by a magic show on telly a few days ago. They showed the 50 best magic tricks (for which the number one was David Copperfield being chopped in half). Debugging a program is a bit like figuring out how a magic trick works. When I watch a magician setting up a trick I always want to jump up and go "No! That padlock is fake. There's an open link in the chain, you're hanging from a wire and that solid case you're going on about has got a trap door at the bottom. Oh, and what's that up your sleeve? And how come your assistant is twins?"

You get the picture... If everything the magician tells you is true, the trick must be impossible. This means that at some point he is telling you whoppers.

Broken programs are just the same. Something somewhere is not how it should be. Some part of the system is lying to you. This means that you debug the same way that you find out from a magician how a trick works; asking "Is the chain real?" etc etc.

Saying "It should work, I dunno why it doesn't" is tantamount to saying that you believe in magic. What you must do therefore is test all the things that you are assuming are true. "I know that this contains the customer number..." Really? How do you know? Did it start off with that number and change? Did the system that delivered the number send something else? Is the range of the numbers what you are expecting? And so on.

The worst thing that can happen is that you can end up convincing yourself that everything is OK. In that case you have what I call a "reality fault". And you start to believe in magic. At this point you have to resort to desperate measures:

  • First thing you do is walk away from the problem for a couple of hours. Often you will think of the answer; how the trick was performed. If that doesn't work, explain the trick to someone else. Two times out of ten you'll think of the answer during the explanation. One other time out of ten the someone else will tell you how the trick is done, or ask a question which changes how you view the problem: "Do you think he might have a fork lift truck in there somewhere?" or "What if the guy from the audience is in on it?".

  • Next thing you do is fiddle with the system in stupid ways. This is like asking the magician to perform the same trick, but using an elephant rather than his assistant. You might spot something this time. Send in completely invalid data. Send in lots of it. Send in lots of the same thing. This quite often gets you some behaviour which lets you track down the problem.

  • Then get the magician to do the trick in slow motion and freeze frame. Step through the code. Put in print statements. At some point you may well spot where your program does something it is not supposed to - and there you are at the solution.

  • Finally, run the trick backwards. The great advantage that a magician has is he knows how the trick will end. The audience doesn't. You can often figure out how it was done if you start from the result and try to figure out how to end up there. It is the same with debugging. Try to think how it could have ended up with that result.

  • OK. If you've done all that and it still fails you are in the one time out of a thousand where magic might actually exist. In this case you change the documentation and abracadabra! Your bug is now a feature! Failing that it is probably time to re-write the code.....

DDD 14 at Reading

Thanks for being a great audience folks

I’ve not been to Microsoft Thames Valley Park for a while. It was very nice to be back there for the day at the Developer, Developer, Developer (DDD) conference. It was awesome. Four tracks of excellent content. I was talking about Air Quality and top hats and whatnot. I had a fantastic audience all my demos worked. (Note to self: stop sounding surprised when this happens). If you want the slide and the sample programs you can find them here.

These events are always amazing and kudos to Microsoft, the Black Marble Team and all the speakers. There was also a splendid set of lunchtime talks. The next DDD will be DDD North which will be back in Hull on Feb. 29th 2020. Make a note of the date now folks. I have.

Making a Useful SatNav

I’ve been moaning about SatNav software for years. It is getting better though. My latest car displays a map that contains 3D renderings of the car parks I’m failing to find a way into. Very useful. Of course it also has a habit of getting the lane guidance wrong, which makes for amusing antics at roundabouts every now and then, but I guess nothing is perfect.

One thing that struck me as I was threading my way through the rain-soaked streets in Reading tonight was how the navigation software proudly displays the names of the streets I’m supposed to turn into. I think this is a bit of a waste of time. Only a local would actually know the street names, and they probably wouldn’t need to use a SatNav. And as for using the street names to confirm your navigation, that’s a bit of a non starter bearing in mind how hard these things are to find and read. What I really wanted was useful directions like “Turn left in front of the pub” or better yet “Follow that blue Prius”.

Actually, having thought about it, “Follow that blue Prius” is just about doable. I sat in a Tesla that could discern the vehicles in the traffic around me and finding their make and colour wouldn’t be too tricky. Link that up to the SatNav and off you go. Hmmm. Perhaps I should patent this.

Then again, once we have cars which are that clever I guess we might just get them to do all the driving and navigation themselves.

Fixing broken Windows Services for Linux

Last week I upgraded to the latest version of Windows 10. And I rather like it. That’s the good news. The bad news is that the upgrade seemed to break my lovely Windows Services for Linux installation. When I tried to open my Ubuntu command prompt it just closed instantly. No error, no nothing. Wah. A bit of searching didn’t help, since most of the fixes were to an almost working system and mine was anything but.

After a bit of heart searching I deleted the application and re-installed it. This was rather annoying. I didn’t have any important data in the installation, but it took me a while to configure the machine with all the services I wanted. Fortunately, thanks to my habit of writing a diary when I do something like configure a computer I can retrace my steps to set everything up again, but it’s still a pain to have to do it.

Of course, the really bad news is that the reinstalled machine didn’t work either. But at least this one gave me an error code I could search for. Turns out that the fix was to turn it off and on again - in this case turn the Windows Service for Linux feature off and then back on again.

I wish I’d tried it before I deleted my original service, but at least I’m back running again.

Update: I’ve since tried WSL on other machines that have been upgraded and they all work fine. So it must be something about my particular machine.

Using the Postman to fetch data from a Swagger Site

We’re using The Things Network to get data from our PAX (passenger) counters. We have Things Network application that receives Lora messages from our counters and we’ve added a data storage integration to hold the data from the counters. We’re not doing much with the data at the moment, but today I thought I’d try and get it out of the Things Network data store sot that I could play with it.

I was thinking that I might have to write a little application to make the request that fetches the data but it turns out that it is actually very easy to use The Postman to fetch the data for me. The Postman is a program that posts web requests and gets the result back for you. It’s great for testing and also for performing quick web requests when you can’t be bothered to write a program to do it. Which is what I’m doing.

If you ever need to do this too it’s actually quite easy. Just open up the integration from your application on the Things Network as shown above. Press the Authorize button in the top right and copy the application key from the application into the dialog that appears so that you can authenticate requests to the Swagger api. Then find the query that you want to run. Iin this case it is the query one you can see on the screenshot above.

Now scroll down to reveal more of the query settings. I’ve set the parameter to get the last 7 days of data. The Things Network only hold the data for 7 days, so this will fetch all of the data. If you hit the “Try it out” button the query runs and you will see the data appear in the browser. That’s fine, but it is very hard to do much with the data in a web page like this.

To use Postman you just have to copy some of the elements from the sample curl query generated by the web page into a new Postman GET behaviour. As you can see below I’ve set the url for the GET request to the Request URL above and added two header values to the request. These give the output format and the authorisation key.

When you click the Send button the request is sent and you can then save the response in a file. You can save the query for later use. Postman and swagger are a couple of technologies that it is worth learning a bit about.

Super secure wallet

A while back I went into a clothes shop and bought something that fitted me perfectly. It was a wallet. It was half price, but since my old wallet had reached the point where my money might start escaping of its own accord, I thought it was a bargain.

It was sold as super secure because it uses special material to stop radio signals getting at the cards inside it. The idea is to stop sneaky people tapping into your bank balance by the use of portable contact-less card readers.

It works too. Last week I was trying to open en electronic lock and it didn’t work. I usually just wave my wallet at the door and it opens, but with the card in my super secure new wallet this failed to work.

I’m now pondering on whether super security is worth a loss of convenience….

Stupid Train Tickets

Every now and then I do something that I (but probably nobody else) think is rather clever. Like using both cores of an ESP32 so that a display keeps running when the WiFi is used to updated it.

And every now and then I do something that everybody thinks is rather stupid. Like last week. A while back I subscribed to an alert to tell me about the release of cheap train tickets. I wanted to get a day trip to London which would cost less than a flight abroad.

So today when I woke up and checked my phone I was pleased to see an alert that I could order some tickets at a massive discount. Mindful of the fact that lots of other people had received this message and there would only be a few seats as these prices I booked my trip and paid for it in double quick time. Clever me.

However, any feeling of smugness evaporated when I discovered that rather than buying day returns from Hull to London I had in fact booked day returns from London to Hull. Idiot me. I put my mistake down to the early hour and undue haste. The tickets are non refundable, and must be used with an, ahem, senior railcard, However, if you are old, live in London and have a desire to spend a day in Hull then it is just possible that I could sort you out.

iPod Classic Blast from the Past

I got out my old iPod Classic today. It still works, and it is still only half full.

And it is the only way that I can listen to some of my music. For example, take the album “Futurenow” from Go West. Good stuff. I bought it ages ago.

Unfortunately I didn’t actually “buy” it though. I got it from Apple iTunes, loaded a copy onto my iPod and got on with my life.

And then, for some reason, the licencing arrangements seem to have changed. Although Apple Music thinks I’ve got the album it presently only provides access to two tracks. Very annoying.

I can probably do a music match thing to add the missing music to my collection, but to do that I need to have the original files. And they are presently on my iPod and nowhere else. Very annoying. I’ve been looking at sneaky software that can pull the music files off an iPod, but so far I’ve not found anything that is guaranteed to work. Oh well.

Fixing browser problems after Windows 10 Upgrade

I finally got the latest Windows 10 feature update on my PC today. I like it. The improvements to the downloads folder are worth the price of admission alone. You now get to see your more recent downloads (the one that you actually care about) instantly, rather than having to wait for the folder contents to laboriously update.

The only problem for me was that the upgrade broke my browser, which started complaining about network problems. I did a bit of searching and in the end I fixed this by turning off the “Automatically detect settings” option in the Proxy configuration above, which you can find in the Network Settings for your machine.