Starbeamrainbowlabs

Stardust
Blog


Archive


Mailing List Articles Atom Feed Comments Atom Feed Twitter Reddit Facebook

Tag Cloud

3d 3d printing account algorithms android announcement architecture archives arduino artificial intelligence artix assembly async audio automation backups bash batch blender blog bookmarklet booting bug hunting c sharp c++ challenge chrome os cluster code codepen coding conundrums coding conundrums evolved command line compilers compiling compression conference conferences containerisation css dailyprogrammer data analysis debugging defining ai demystification distributed computing dns docker documentation downtime electronics email embedded systems encryption es6 features ethics event experiment external first impressions freeside future game github github gist gitlab graphics guide hardware hardware meetup holiday holidays html html5 html5 canvas infrastructure interfaces internet interoperability io.js jabber jam javascript js bin labs latex learning library linux lora low level lua maintenance manjaro minetest network networking nibriboard node.js open source operating systems optimisation outreach own your code pepperminty wiki performance phd photos php pixelbot portable privacy problem solving programming problems project projects prolog protocol protocols pseudo 3d python reddit redis reference release releases rendering research resource review rust searching secrets security series list server software sorting source code control statistics storage svg systemquery talks technical terminal textures thoughts three thing game three.js tool tutorial twitter ubuntu university update updates upgrade version control virtual reality virtualisation visual web website windows windows 10 worldeditadditions xmpp xslt

Arduino Runtime Exception List

Just yesterday I was at the Hardware Meetup at C4DI, and I (along with a few other people - thank you for helping :D) was attempting to fix a series of nasty runtime errors. All it gave me was a message in the serial monitor that an exception had occurred, an error code, and a raw stack dump. This wasn't very helpful at all. Even more unhelpful was the lack of help out there on how to decode this information.

I did, however, manage to find a page that contains a list of the different error codes and their meanings. It's not much, but it's a start. It helped us at least to work out what was wrong with it :-)

Arduino Exception Reference

The Visual Micro Logo

If you're running Windows, then Microsoft have created Visual Micro - a what looks like a perfectly brilliant debugger for the arduino. Apparently you can inspect variables, see the digital pin statuses, and get intellisense lovelyness :D Since I'm running linux, I can't get my hands on it - hopefully someone will build an alternative for linux and other OSes soon!

I also discovered a weird oddity with UDP Multicast in C#. I'm going to investigate further and write up another post that will (hopefully) follow this one.

Coding Conundrums Evolved 2: Binary Biomass

This post is part of a biweekly series of programming problems, targeted at those learning to program using C# at University. The problems will vary in difficulty - some will be rather easy, and some will be quite challenging! Don't worry if you can't solve a problem just yet - come back to it in a few months and it'll seem a lot easier than it did before.

Welcome back to Coding Conundrums Evolved, my take on Rob Miles' original Coding Conundrums series. Last time we built a translator for an alien language. As promised, you can find my solution to that problem here. The password to the archive is eyamporrean. In episode 2, some scientists have made an amazing discovery.

The ISS (Above: The ISS as seen from the Space Shuttle Atlantis when departing from the station.)

The scientists on the Zirros orbital research station have managed to create a brand new species of tree (which they've decided to call the mikoko tree) in their lab that grows in precisely the same way every time, allowing the number of leaves on a tree to be predicted with accuracy months or even years in advance.

Upon hearing about this new discovery, the engineering department of Zirros immediately designed a biomass generators a that runs on the leaves of the mikoko tree, since they have been having issues with the station's solar panels recently.

A mikoko tree growing.

The mikoko starts with a single shoot, which splits into 2 every 9 days. Every time the shoot splits in two, all the previous joints grow a cluster of up to 3 leaves. A joint may not hold more than 3 leaves at once. Incredibly, the mikoko doesn't actually need any of its leaves to grow. It can perform all the photosynthesis it needs to in its branches, apparently. Furthermore, the shoots on the mikoko can be snipped off, at which point the tree ceases to grow any further. In this state it still produces the clusters of leaves every 9 days. The scientists have performed various experiments and come to the conclusion that a single leaf produces 1.5 energy credits when burnt in one of engineering's new biomass generators. The Zirros station, according to engineering, uss 56 energy credits per day.

It is anticipated that once the scientists' paper is released on the mikoko, every station / spaceship / colony within 25 light years will want to power themselves very own mikoko farm. Doing the calculation to work out how big of a tree is needed for each installation is boring and time consuming, and so you've been asked to write a program that will do the calculations needed to work it out automatically.

Given the number of energy credits a station uses per day, write a program that will calculate the day on which a mikoko tree should be snipped such that it will produce enough leaves to produce enough energy to power the station in question. The following stations have already issued requests:

  • Zirros station: 56 credits per day
  • Spaceship Iveinya: 12 credits per day
  • Mining station Kira 4: 304 credits per day
  • Spaceship Aheya: 2 credits per day

Helpful Hints

  • It might help to draw it out on a whiteboard first. Make sure you've got your head around the problem before you start writing code.
  • Don't be afraid to ask questions in the comments if there's something you don't understand! I'll be happy to help you.
  • Make sure that you manually test your program to make sure that it gives the correct output. While your program might work with one input, it might not with another.

Challenge

The scientists have also found that you can plant 5 leaves together, and a new mikoko shoot will grow after 3 days. Alter your program so that it takes this into account when reporting the day that the mikoko trees should be snipped. Make your program also report the days on which leaves should be taken from the existing tree(s) and planted to create new trees.

As per last time, my solution can be found here, and the password will be released with the next challenge.

Update: The next post has been released! Find it here: Fiddly Fuel. The last post was Alien Encounter

I now have a public website status page!

My new status page! Just recently Uptime Robot (the awesome service that I use to monitor my server's uptime) have released a new feature: Public status pages! Status pages appear to be free (for now), so I've gone and set one up. Now all of you can see what's up with my website if it's down.

They even allow you to point a (sub)domain at it too. I did this too, so you can visit my status page at status.starbeamrainbowlabs.com.

Chaikin Curves in C#: An alternative curve generation algorithm

A chaikin curve, increasing in order each frame.

A little while ago I was curious to know if there were any other ways to generate a smooth curve other than with a Bezier Curve. Turns out the answer is yes, and it comes in the form of a Chaikin Curve, which was invented in 1974 by a lecturer in America by the name of George Chaikin. A few days (and a lot of debugging) later, I found myself with a Chaikin curve generator written in pure C♯ (I seem to have this fascination with implementing algorithms :P), so I thought I'd share it here.

Before I do though, I should briefly explain how Chaikin's algorithm actually works. It's actually quite simple. If you have a list of control points, and you were to draw a line through them all, you'd get this:

Some lines before the chaikin algorithm has been run.

The magic of the algorithm happens when you interpolate between your control points. If you build a new list of points that contains points that are ¼ and ¾ along each of the lines between the current control points and draw a line though them instead, then the line suddenly gets a lot smoother. This process can be repeated multiple times to further refine the curve, as is evidenced in the animation above.

This page is very helpful in understanding the algorithm if you're having trouble getting your head around it.

My implementation makes use of the PointF class in the System.Drawing namespace, and also has the ability to generate an SVG version of any generated curve, so that it can be inspected and debugged.

You can find my implementation here: Chaikin Generator - comments and improvements are welcome!

Instructions on how to use to use it are available in the README, and the class is fully documented with Intellisense comments, so it should feel fairly intuitive to use. I've tried to use patterns that are present in the rest of the .NET framework too, so you can probably even guess how to use it correctly.

Additionally, I 'm going to try put it up as a Nuget package, but currently I can't get Nuget to pack it currently on linux (when I do, you can expect a tutorial on here!)

Coding Conundrums Evolved 1: Alien Encounter

Banner image. (Banner generated with LC_ALL=C tr -c "[:lower:]" " " < /dev/urandom | dd cbs=$COLUMNS conv=unblock | GREP_COLOR="1;32" grep --color "[^ ]", adapted from here)

This post is part of a new biweekly series of programming problems, targeted at those learning to program using C# at University. The problems will vary in difficulty - some will be rather easy, and some will be quite challenging! Don't worry if you can't solve a problem just yet - come back to it in a few months and it'll seem a lot easier than it did before.

The year is 2258. Humans have established themselves as spacefarers and have made contact with several alien species. You are a member of the esteemed Captain Obanji's crew aboard the spaceship iveinya, on a mission to explore the galaxy! While out exploring, you and your crew discover a new species of intelligent life! You decide to call them the Outer Clockwise Eyamporreans (simply because it sounds cool).

Chief of Communications Officer Bramaar has been analysing the Eyamporreans' language. He has discovered that it is based on the english alphabet (abcdefghijklmnopqrstuvwxyz) managed to work out that he can use a simple substitution cipher to translate the Eyamporreans' language into English. He has also worked out what each letter in their language corresponds to in english:

a b c d e f g h i j k l m n o p q r s t u v w x y z
i u c r a v j w m d q o n b f p l y e t s k z g x h

(abcdefghijklmnopqrstuvwxyz / iucravjwmdqonbfplyetskzgxh)

Unfortunately, he has been having a spot of bother whilst writing an automatic translator for the language. This is where you come in. Given a single line of Eyamporrean through the standard input, translate it into English and output the result. See if you can translate the following alien communications back into english:

jyaatmbje, etyibja cyaitsyae!

za zfsor omqa tf zaocfna xfs tf fsy poibat.

rf xfs wika ibx yfcqat vsao? fsy epicacyvt me ysbbmbj fst.

Helpful Hints

  • The input will only contain the lowercase letters of the alphabet, spaces, and possibly punctuation such as ! and ?.
  • You should pass any characters such as whitespace and punctuation that your program doesn't understand straight through your translator.
  • It never hurts to do a quick .ToLower() call on all the input your program receives, just in case.

Challenge

Officer Bramaar and Captain Obanji are impressed with your work. Using your translator, they have been able to understand the Eyamporreans' messages and ascertain their intentions. Now, they would like to send a message back.

Alter your program so that you can not only translate Eyamporrean messages into english, but also translate English into Eyamporrean.

See if you can translate these messages into Eyamporrean:

hello eyamporreans! we come in peace.

we represent the planet earth.

do you require assistance?

The solution to this puzzle can be found here. The password to the archive will be released along with next week's challenge.

Update: The next post has been released! Find it here: Binary Biomass

Arduino quick reference guide

The arduino logo

This post was going to be about how I connected my robot to a WiFi network and controlled it wirelessly, but I've been having some issues with getting that to work :-( Since I wanted to make a post anyway, I thought I'd post about a quick reference guide I found instead :-)

An arduino quick reference guide.

(Download as: png, svg | Original source)

I found this decided to print it out and laminate it. It's been really useful - I'm really glad I decided to print it out now. It was originally made by a guy called Mark Liffiton. You can find its Github repository here. The version I have posted here is tweaked very slightly to have colour on the reset button, which the original doesn't have.

Next I'm going to attempt to find a similar sort of thing for the esp8266 (upon which the Wemos D1 R2 is based) API, because I'm constantly having to look up various functions all over the place and it wastes a lot of time :-)

Have you found a handy reference sheet? Post about it in the comments below!

Client certificates and HTTPS: A deep dive into the world of certificates

Recently I've been checking out client side certificates in order to secure access to various secret parts of this website. In order to do this, I found myself learning more than I ever thought I would about certificates and certification authorities, so I thought I'd share it here.

Before I get into how client side certificates work, I should start at the beginning. In order to serve pages over HTTPS, a web server must have both a private key and a certificate. The private key does the encryption, and the certificate verifies the identity of the web server (so you know you're connecting to the real thing and not a fake).

The certificate is signed by a Certification Authority. A certification authority (CA) is an organisation that has a Root Certificate, which is a certificate that's explicitly trusted by your operating system and browser. If a chain of valid certificates can be made from the web server's certificate back to a trusted root certificate, then we know that the web server's certificate can be trusted. Since a picture is worth 1000 words, here's a diagram describing the above:

A diagram of the hierarchy of a CA.

The web server isn't the only one who can have a certificate. The client can also have a certificate, and the web server can choose whether or not it likes the certificate that the client presents based on which certificates it can be linked back to in the signed certificate chain.

This presents some interesting possibilities. We can create our own certification authority and use it to issue client certificates. Then we can tell our web server that it should only accept clients certificates that can be linked back to our own certification authority.

For the certificate creation process, I can recommend tinyca2 (direct apt install link), which should be available in the repositories of most linux distributions. It's got a great GUI that makes the process relatively painless - this tutorial is pretty good at explaining it, although you'll need to read it more than once to understand everything. XCA is pretty good too, although a tad more complex. Once you've created your CA and certificates, come back here.

The Nginx logo.

Next up is configuring our web server. I'm using Nginx in this tutorial (that's the web server that's currently behind this website!), but there are guides elsewhere for Apache 2, Lighttpd, Hiawatha (For Hiawatha it's the RequiredCA configuration directive in the manual!), and probably others too!

Configuring Nginx to accept client certificates signed by our CA is actually fairly straight forward, despite the lack of information on the internet currently. I'm going to assume that you've already got a working Nginx webserver online that supports HTTPS (or you haven't try checking out this and this and this) To do this, grab a copy of your root CA's certificate (excluding the private key of course) and upload it to your server. Then, open up your Nginx configuration file in your favourite text editor (I use sudo nano) and add the following lines to your http block:

ssl_client_certificate  /path/to/your/root/certificate.pem;
ssl_verify_client               on;
ssl_verify_depth                2;

Let's go through these one at a time. The ssl_client_certificate directive tells Nginx where to find our root certificate, which it should use to verify the certificate of connecting clients. ssl_verify_client tells Nginx that it should perform verification of all clients connecting via HTTPS, and that nobody is allowed to connect unless they have a certificate signed by the above root CA. Finally, the ssl_verify_depth parameter instructs Nginx that if a client's certificate isn't directly signed by our root CA then it should follow the certificate chain down to a depth of 2.

Once done, you should only be able to connect to your webserver if you have an appropriate certificate installed in your browser. This is nice and all, but what if we only want to apply this to a single subdomain? Or even a single folder? This presents a problem: Nginx only supports client certificates on everything, or nothing at all.

Thankfully, there's a workaround. First, change ssl_verify_client from on to optional, and then the following to the server or location block you want to verify certificates for:

if ($ssl_client_verify != SUCCESS) {
    return 403;
}

I've found through trial and error that the whitespace is important. If it doesn't work, double check it and try again! The above snippet simply checks to see if the user has connected with a valid certificate, and will send an HTTP 403 error if they haven't.

That concludes this tutorial. Did it work for you? Did you find it useful Did you read this far? Comment below!

Sources

Pocketblock: Simple encryption tutorials

The Pocketblock logo.

Recently I found a project that aims to explain cryptography and encryption in a simple fashion through this Ars Technica article. The repository is called Pocketblock and is being created by an insanely clever guy called Justin Troutman. Initially the repository didn't have anything in it (which was confusing to say the least), but now that the first guide of sorts has been released I'd like to take the time to recommend it here.

The first article explains an encryption algorithm called 'Pockenacci', an encryption algorithm that is from the same family as AES. It's a great start to what I hope will be an awesome series! If you're interested in encryption or interested in getting into encryption, you should certainly go and check it out.

My robot works!

The Hull Pixelbot 2.0!

I went to the hardware meetup again today. For the last 2 times I've either managed to forget or I've been on holiday (probably both...), but I remembered this time around and I decided to go. I'm glad I did, because, with Rob's help I fixed my robot! It is now trundling around on the floor quite happily :D

The problem was that I assumed that the digital pin numbers on the wemos D1 R2 were the same as the GPIO pin numbers, which isn't the case apparently. Here's a table:

Digital GPIO
D0 GPIO 16
D1 GPIO 5
D2 GPIO 4
D3 GPIO 0
D4 GPIO 2
D5 GPIO 14
D6 GPIO 12
D7 GPIO 13
D8 GPIO 15

(Table from wemos.cc)

Very odd numbering. It's rather frustrating actually! Anyway, there seemed to be quite a lot more people there this time as compared to last time - it looks like the idea is taking off, which I'm very glad about :-)

If you're in the Hull area and interested in hardware, you should seriously consider coming along. There's a page on meetup.com that contains the details of the next meetup, but the general rule of thumb is that it happens at C4DI every first and third Thursday of every month at 6pm - 8pm.

Before I forget, I'm going to end this post off by posting the modified version of Rob's hull pixelbot dance code that works on the Wemos:


(Git Repo, Raw)

The lost post: Embedding commit hashes in C♯ binaries

I seem to remember that I've started to write this post no less than 3 times, and I've managed to lose the source each and every time. If you're reading this it means that I've managed to complete it this time :D

Imagine you've got a confused client on the phone, asking why the newest feature X in your program doesn't work. You ask them whether they have the latest version of your program installed... and they say that they don't know. Version numbers and changelogs to the rescue! Except.... that last release was rather rushed and you forgot to finish updating the changelog. This is just one scenario in which embedding the latest commit hash into your program is useful.

You could embed the short hash (the first 7 characters) into the version string, for example v3.6.1-375ae31. Then you could compare it against the revision history to see exactly what your codebase looked like when your client's version was built.

For a while now I've wanted to do just this, and now I've finally figured out how to do it cross-platform. This post documents how I went about doing it, and how you can do it too.

The basic principle of the idea is to run a command that will output the latest commit hash to a file before the build starts, and then embed that file into the resulting binary. To achieve this, we need to go about it in 2 parts. Firstly, we need to fiddle with the project file to add an optional pre-build event. Open the project file (MyProject.csproj) in your favourite text editor (but preferably not your favourite IDE such as Visual Studio or MonoDevelop) and add this to the bottom, just before the closing </Project>:

<Target Name="BeforeBuild" BeforeTargets="Build">
    <Exec Command="git rev-parse HEAD &gt;git-hash.txt" WorkingDirectory="$(ProjectDir)" IgnoreExitCode="true" />
</Target>

If you don't use Git, then change git rev-parse HEAD &gt;git-hash.txt in the above to the equivalent command for your version control system. For SVN, this stackoverflow question looks like it'll do the job for Windows - for Linux you should go here.

Once done, the next step is to add the generated file as an embedded resource. We can't do this with the GUI easily here since the file in question hasn't been generated yet! Add the following to the bottom of the csproj file, again just before the </Project>:

<ItemGroup>
    <EmbeddedResource Include="git-hash.txt" />
</ItemGroup>

Remember to change the git-hash.txt to whatever you changed it to above.

Next, save it and reopen the solution in your IDE. The final step is to actually utilise the commit hash (or revision number in SVN) in your program. Since it's just an embedded file, you can simply find it with a bit of reflection, and read it in with a StreamReader. I've written a good tutorial on how to do that over on my Embedding files in C♯ binaries post.

Make sure that your program is prepared to handle junk instead of a commit hash - you can't predict the contents of the embedded file if Git (or SVN) isn't installed on the machine used to build your project. If you want to require that the commit hash (or revision number) is actually present, just remove the IgnoreExitCode="true" from the first snippet above.

Sources

Art by Mythdael