C Code Connundrum

if (tokenOffset + 1 >= MAX_TOKEN_LENGTH)

I’m writing some text decoding stuff at the moment. The piece of code above is a bit of C that I’ve written to make sure than I don’t write over the end of my token array. If the tokenOffset gets larger then the length of the array the condition is true and I will stop writing into it. One of the joys of C is that you have to worry about this kind of thing, otherwise you can overwrite memory and have all kinds of bad things happen. However, the code above is not as efficient as it might be. Any ideas why?

…sound of crickets….

Well, every time the code runs it will have to work out tokenOffset+1, because tokenOffset is a variable. However, look what happens if I do this:

if (tokenOffset >= MAX_TOKEN_LENGTH-1)

The logic is the same, but now I’m subtracting the value 1 from MAX_TOKEN_LENGTH, which is a constant containing the length of the buffer. Since this is fixed at compile time the compiler will just drop the reduced value into the code, so the program now performs no calculations when the test is made. This is the kind of thing that you used to have to fret about, back in the day when every processor cycle was precious. Such fun.

Incidentally, you might be wondering why I have one less character in my text buffer than I think. This is because in C a character string array contains a null character (a character with the code of 0) which marks the end of the string. This character has the lovely name of “terminator”. This does mean that a 50 character array can only actually hold 49 characters, because the last one is the terminator. Another way to solve this problem is to make the array one bigger when you create it, to leave room for Arnold.

PythonIsh now running on Connected Little Boxes

I’ve just spent the day playing with PythonIsh. It’s a tiny language that I’m adding to my Connected Little Boxes. It originated in the Hull Pixelbot, but now I want use it to make it easy to program all my different devices. Today it actually worked properly for the first time, which is nice.

The idea is that you can write tiny bits of code that run in response to events on devices. You can save program files in the device and one program can load in another. You can also enter a new program while an existing one is running. And, as you can see above, the device can host a website where you can enter code. You can also edit code online and send it to a device over MQTT.

It will be out soon on GitHub.

Tip Tripping

They have barges down on the river

Went to the rubbish tip. An affair of badly chosen (massive roadworks) and implemented (turned wrong way) routing. But the tip is in a nice place, down by the river at the far side of a bridge not operated by a troll. Or at least I couldn’t see one.

Non-troll operated bridge

The tip is self-service, lots of labelled bins waiting for their particular type of rubbish. I really hope that they don’t tip all the bins into one big skip at the end of the day.

I’d taken the pass you are supposed to show when you want to throw things away but nobody asked me for it. Maybe next time. Looking at what’s in the garage, there will be a next time….

Shopping for 12 year old me

I love the list of people the magic brain is ideal for….

I got the two items above in Scarborough last week. They are the kind of things that 12 year old me would really have liked. The marked deck lets you work out what card your victims are holding by decoding tiny icons on the back. A stripper deck is one which has been filed down on the sides. The width at the top of each card is slightly different from the width at the bottom. If you put the chosen card in the deck upside down you can easily find it because it sticks out. You slide your fingers up the sides of the deck you can “strip” the inverted card out and look quite magical.

I actually did get a “Magic Brain” calculator when I was 12 and used it to sum up survey results. You add, subtract and multiply (but not divide) by using a metal stylus to move the vertical sliders up and down, changing the numbers displayed in the windows. If adding the value to the one displayed causes a carry you slide the value down and then loop around at the bottom to add the carry. For subtraction you dialled in one number, and then slid the numbers back up to subtract. It didn’t handle negative numbers very well….

Slightly older me thinks both these things are really rather wonderful. Scarborough has lots of little shops selling things like these for knock down prices. My magic brain only cost me a pound and the playing cards weren’t much more. Great fun.

Live Aid at 40

I didn’t get to see much of Live Aid back in 1985. I was working in Paris for a couple of weeks, teaching American students how to program the BBC Micro. Skills which I’m sure they found useful when they got back to the ‘states. The flat I was staying in didn’t have a telly, so I only saw bits and bobs in bars and whatnot when we went out. We watched some of the concert last night, when the BBC reprised the show. I really enjoyed it. Random observations:

  • Leather trousers were big in 1985, which must have been lovely in the heat of Wembley stadium in July.

  • It was interesting to watch the camera operators waving around enormous broadcast cameras to get close ups of the performers. This must have been quite ground (and back) breaking for the time.

  • Apparently Queen spent three days honing their 16 minute set. It really showed. Freddy Mercury was a genius.

  • You could pay your donations in a Giro bank account at you local post office. Imagine that.

  • The had the famous actor (and Hull University Honorary Doctor - I was at the ceremony) John Hurt on and asked him his favourite band. He gave a very diplomatic answer which was fortuitously (for him) cut short by the next band starting up. America had Jack Nicholson. And Bette Midler.

  • Nobody in the crowd was holding up a phone to record the show. I wonder why that was?

Retro Hi-Fi Fun

..plus some contemporary media…

In these hot summer days it is important to stay cool, keep hydrated and avoid making any rash purchases of vintage Hi-Fi systems…..

Oh well. In my defence I saw it a shop window for sale at a lovely low price and it works a treat. The tape deck doesn’t have Dolby but it sounds fine and the CD player has room for 5 CDs. It’s going in my office so that I can avoid hearing tracks that magically change to different versions, pause for no good reason and suddenly come from someone else’s favourites. .

Robot Rugby - now with added ball

We need to slow the ball down, it kept rolling into the same corner.

Just a quiet Hardware Meetup this evening. Probably because I forgot to send out the email telling people about it….

Oh well, sorry folks. The next one will be in two weeks on the 23rd July. I’ll make sure to give you plenty of notice. Simon came along with kit of parts to make a remote controlled ice-cream jingle machine, along with a beautifully made clock driver box. I’d brought 4 robots and a couple of golden balls that we are going to use for robot rugby. I got all the robots working and programmable from the internet. It turns out that my phone makes a very workable WiFi connection.

Next time we’ll hopefully have some tracking action too.

Go See Pride and Prejudice in Scarborough

As everybode kno I consider myself a very cultured person. I’ve watched most of the Marvel movies and I know the numbers and pilots of all the Thunderbird craft. Last night I went to the theatre to further burnish my cultural credentials. We saw Pride and Prejudice at the Stephen Joseph Theatre in Scarborough.

I did a bit of due diligence before we set out and, after discovering that the story does not include any aliens, car chases, superheroes or “14 minutes to save the earth” moments, I took the precaution of ordering beer and ice-cream for the interval. At least that way I would have something to look forward to during the evening.

As it turned out I needn’t have bothered (although the beer and ice-cream was very nice). The play was awesome. The production was enthusiastically acted and imaginatively staged. The best thing about the way it was done is that it was definitely not the “Lizzy and Darcy Show”.(showing knowledge of the actual plot - go me).

All of the accompanying characters were very well rounded out and you got an understanding of how difficult it was to make your way through those times if you had made the mistake of being born without any money to your name. Lots of great lines from the book made it onto the stage, and the casting was inspired, including a few of the actors “doubling up” on characters which worked incredibly well.

If you think that classic literature, or plays aren’t your thing you really should go along to see the play and have your mind changed. It won’t cost you much more than going to see the latest superhero reboot (which will be on telly soon anyway) and you can order beer and ice-cream for half time. Win win.

More Naval Battles at Scarborough

Coming under heavy bombardment..

A while back I wrote about the Naval Battles that they stage at Peasholm Park in Scarborough. We went back there today and I took some more pictures. Fun fact, the camera I used this time was actually older than the one I used in 2009…

The bad guys get their cumuppance

Aircraft carrier

Sending in air support

The boats have people in them steering.

If you get the chance you should go along. The battles take place every Monday, Thursday and Saturday at 3:00pm and are preceded by a musical performance. It’s great fun and you can buy ice creams. And wine. Find out more here.

Play Star Wars Unlock

You should play Star Wars Unlock. There are three games in the package and all are different and fun. The games last around an hour or so. It works best if you get a bunch of friends round and have a go together. You’ll need the game plus a phone or tablet for the program element which adds a lot to the atmosphere (authentic Star Wars music, plus appropriate classical pieces). Unlock do lots of other games, but the Star Wars themed ones are especially impressive and fit well into the Star Wars universe.

You can only play the games once, but then you pass the box on for someone else to have a go. That’s how we got to play with this one….

More Photowalk pictures

Analogue Wonderland must have been very busy over the last few days, processing the films from the 40 photowalks that took place last Saturday. We got the rest of our pictures back today, which is much more quickly than I expected. Pretty much all of them have come out, which is very pleasing

I’d not used Kodak Pro Image 100 before, but I’m a convert now. Very nice grain and lovely colours. And on offer at the moment..

Traction Engine Fun

The weather wasn’t great when I arrived

Last week at the Hardware Meetup Simon mentioned that he had a friend who had a traction engine. Would I be interested in coming along next time they fire it up. I would. So today I went along to meet up with Rob, who had his machine ready to go when I arrived. I took along a couple of cameras (as you do) and tried to take some pictures. Some of them you will never see, because I left in the dark slide (the bit of the camera that protects the film from pesky outside light). However, the digital shots that I took came out OK. I

I also had a go at steering, then driving, then both at the same time. It was awesome. Thanks very much for inviting me folks.

There are some more pictures on Flickr.

Loading film with my eyes shut

I spent a chunk of today loading film into holders, ready for some photographic fun tomorrow. This involves putting all the elements into a bag and then shoving my hands through a pair of elasticated cuffs to keep the light out. Then, with my hands in the dark, I open a box of film, take out a sheet, put it into the holder and then close the dark slide. Then I take my hand out of the bag and let light in. Which is stupid. Fortunately I noticed in time and, since the film stays in a light tight bag most of the time, I think/hope I got away with it.

One of the problems that you have when doing all this is that you are working by touch. What you are looking at is irrelevant. I end up staring stupidly into space. Something which I’ve been told I do a lot of without my hands in a bag.

Anyhoo, today I tried something I should have tried a long time back. I closed my eyes. Suddenly everything made a lot more sense, and it was actually easier to load the sheets. I’m going to do this more in the future. There is no picture of of me doing any of this because it would, of course, turn out to be black.

Thunderbirds are Go - ish

Over the weekend I thought I’d show a young guest the joys of the Thunderbirds TV show. They were suitably impressed (or very polite). However, I wasn’t able to show the higher quality version with the better sound and pictures, even though I remember watching this just after I bought the TV series from Apple TV a few years ago. All that Apple TV serves up now is the original 4:3 version with the mono soundtrack.

I’ve had this before with digital media. An album that I bought will lose tracks, or they will change into different versions. Or a service will vanish leaving me with nothing for the money I spent with them. Such is modern life I suppose. In the meantime I’ve spent thirty quid on a Blu-Ray version of the show. Come the digital apocalypse at least I’ll still be able to watch the adventures of Scott and Virgil and the rest of International Rescue.

Big Malarkey Big Fun

Hull Makerspace Marble run was a big win

The Big Marlarkey is a Hull special. It’s a literary event for kids aged 0 -16 . Having acquired the entry requirements (three tickets and an 8 year old) we went along today. They had children’s authors, poo presentations, lots and lots of making, book hook a duck, music, VR, museum stuff and a chap selling crepes. Which were wonderful.

They also had Makerspace Hull there to who brought golf tee art, fun with circuits, MicroBit coding and a marble run whiteboard which was splendid. Much fun ensued, although things were slightly derailed when one of the party lost their Lilo and Stitch keyring. But, on enquiring at the organizer’s tent, we discovered that someone had found the item and handed it in. We’ve no idea who did this kind act, but we are eternally grateful to them. They transformed the event from “The one where I lost my keychain” to “The one where I had a great time and saw an amazing presentation from the author of “The Houdini Inheritance” (which I also got a signed copy of)”.

The event was super busy, the weather was great and I think there is a very good chance we will be along again next year.

Analogue Wonderland Big Film Photowalk

Victoria Dock in Hull

Went on a photowalk today. Never done one before. Tremendous fun. The idea is simple enough. A bunch of folks get together and walk around taking photographs and talking photography (and life in general). To make matters more interesting (and organised) this one was set up by Analogue Wonderland who appointed walk leaders for the various walks around the country and then did a special deal for film and processing. We were walking in Hull with Rob Wharton who gave out maps, film and chat as we wandered around.

Down near the deep. If you are wondering where the water has gone, the tide is out…

The weather was kind, the sky was interesting and the photo opportunities abundant. Including, in The Land of Green Ginger, the “Smallest Window in the World”. Probably. We each had two rolls of Kodak Pro Image 100, giving 72 shots in all. My first film went back to Analogue Wonderland for developing. The second stayed in the camera for finishing off later. If you are wondering how I’ve managed to include some of the walk pictures in this post, I’m using a piece of magic called “posting from the future”.

Hull Marina looking good

Humber Street Street Art

Anyhoo, It was great. We finished off at the Minerva Pub at the water’s edge for a well deserved (we thought) drink. You can see more of my photographs here.