I've recently been messing about with Microsoft's Azure platform; and I already think it's brilliant. I didn't expect the support for Linux Virtual Machines to be quite so good. Literally with just a few clicks I created a Linux box on the cloud (I went for Ubuntu), I can't really see it getting much easier. I suppose I should have known when I recently saw that Microsoft's CEO Satya Nadella had presented this:
Anyway, the first thing that I did with Azure was test my Linux VM out by copying over my C webserver code and compiling it. Everything went perfectly. But I quickly realised that it would be useful to be able to leave my code running in another terminal session when I disconnected from the console. That's where I tried out GNU Screen which allowed me to start my program in a session and leave it running after I had disconnected. GNU Screen is a nice simple solution, which means that I can keep my code simple. I like this :-) And at the same time I noticed a couple of bugs in the webserver code which I had not spotted before, so I was able to fix them too.
It's great to think that I can write some C code on my MacBook; cross-compile and test it on a small router running OpenWrt, then move it to the Azure platform without any worries. This is one reason why I still like programming in C (and Linux).
Next I decided to copy my H2D2 server across to Azure (of course). Again, everything worked perfectly. So I'm currently testing H2D2 on the cloud, let's see how stable it is. I also took the opportunity to tidy up the html, to make it look more presentable as well:
For some reason it came out in grey. I don't really know why.
Since I'm expecting to see a few crashes, I have used a simple shell script like this one which will restart my server program when something goes wrong.
Originally, I started with the most basic type of VM on offer, with a shared core. But then I did an upgrade to an 8-core machine, which gave a noticeable performance boost (as you'd expect). It was nice to see that Azure can upgrade your VM really easily, yet again it was all done with a couple of clicks (and a reboot of the VM). But now, to save CPU I've gone back to the shared core again which will be less of a drain on my account.
Whilst messing about with my own programming language, I've been getting it to display output in the browser, which all looks very retro because it's text only.
So I decided that it would be nice to prettify things a little bit, without going to very much trouble. It would also be nice to be able to do things like clear the screen, or move the cursor around. But I didn't want to invent my own protocol, I thought that it would be much better to just use an existing thing.
For that reason, I thought it might be handy just to use ANSI escape sequences. Whilst that would still look all very retro (use of these codes goes way back to the 1970s), it would bring some new capabilities to the table, like colour and very simple graphics. It should even allow very basic animations. Of course, this isn't what I have designed H2D2 for; but it's a nice way to test the language.
But with my version, it doesn't matter where the output comes from, the code just deals with drawing it onto the page. It means that the library can deal with any text containing ANSI escape codes. It even allows more than one 'console' to appear on the same webpage. I have also included support for extended colour codes, meaning that RGB values can be used. It's possible to turn scrolling on or off, and you can keep appending more text when you like.
Anyway, it worked a treat when I plugged it back into my H2D2 demo. Here's some hurriedly hacked together example output:
I've had my iPhone for quite a few years now. It's an iPhone 3GS and for a long time I have not had a compelling reason to change it. But these days I find myself stuck on iOS 6 when lots of Apps now require iOS 7 or later. So I'm getting left out in the cold. It's time to do something about that.
But on the old iPhone I also can't do things like set up a personal wifi hotspot. I can do connection sharing over bluetooth or by a cable, but I find that type of connection is not well supported on non-Apple devices. So I can't use the internet access from my phone on my Andriod tablet (although it works fine with the iPad).
The old iPhone does seem slower than it used to, so getting a new phone with a faster processor would be good too. And it will also be nice to get a better camera. So I've decided to try out one of these phones: Motorola G (the 4G version).
I like the idea of the SD card slot for extra storage and for the price it seems a very good spec. It's a shame there is no way to connect an HDMI cable, but I can live without that. But I was finding it hard to justify the cost of another Apple phone, when I've been quite satisfied with the Android OS recently. I used to feel that the Apple phones were better quality (both in terms of hardware and software). But things have moved on.
After a few days of use, I am very impressed with the Moto G. The only problem I have found so far is with the Android KitKat OS itself. There is a serious bug with the stock e-mail App which has now gone unfixed for nearly a year. That's pretty bad. I'm surprised to see it classified as Priority: small when the effect is that e-mails are deleted from the server when you have told it not to.
So I cannot use the standard e-mail App, and at the moment I'll use the K-9 App instead. It's a shame, because in previous releases of Android the e-mail App was working fine. Even so, I am pretty happy with my choice of phone. I've even started reading some pages on Android development - although it was mainly out of idle curiosity. But you never know...
Since I wrote this blog post,
I have been looking for a better demo program to show what I can do with
my H2D2 programming language. I needed something more interesting than
"hello world" ... and which didn't involve drawing the Mandelbrot set.
I started trawling through the Rosetta Code
website for inspiration and came across this
sphere drawing program
in C. I guess it's a simple ray tracing algorithm really. It seemed like a
So I set about porting it from C to H2D2, which was an interesting experience.
Interesting because H2D2 is not very forgiving when you make mistakes - since I have
not (yet) made the compiler error messages very user friendly. So it makes you reason
things out very carefully in your head, rather than rely on the compiler to spot
problems with your code.
I have managed to get it to work though, and the resulting H2D2 example program
shows a few of the language features (like a function call and arrays for example).
However, it also highlights a few things I should work on, like creating a
syntactic shortcut for assigning values to an array. Anyway, I can now create
output like this:
But to show it in action, I made this recording,
which shows it off in realtime in the browser:
Anyway, I am really pleased that it works so well. I can go back to fiddling around with the language now.
Now that my experimental programming language, H2D2, includes the all important server part, I thought that I'd better record an example of the traditional 'Hello World' program:
Although these programs are very trivial, it shows that I can now do H2D2 programming from my browser. It's the server part which compiles the source into bytecode and then executes the program in timeslices. So the actual code is running inside the server and we're just seeing the output in the browser (alongside the source code of course). Since I recorded this in a coffee shop before work this morning, the H2D2 server was running locally inside Xcode on my Mac, for convenience. But I would be able to do the same thing even if the server was running elsewhere, like on my TP-Link router.
UPDATE: one of the "better code examples" I mention above can now be seen here.
It’s been many years since I’ve regularly read a computer magazine. But I miss those days really, I’ve
not got anything against reading computer magazines, but I’ve not seen anything in
a long time that catches my interest. But it’s nice to read something and then say to yourself “umm, I’d like to try that out for myself”.
Well, I suppose I do casually read the MSDN Magazine in electronic format, but I’m doing that because it’s part of my work, not because I’m doing it for fun. And I do still read articles on Dr Dobbs.
Anyway, after seeing the Linux Voice magazine mentioned on the Raspberry Pi blog some time ago, I have been reading every issue. This is something that I choose to read for fun, and I continue to look forward to each issue coming out.
But reading this magazine has resulted in me trying out lots of different distros. I have seen that there is a lot more stuff out there that I haven’t tried yet. So my old laptop has taken a bit of a hammering because I keep flattening it and reinstalling something else.
But … for a while, this may have changed. Because I’ve tried Elementary OS. I am very impressed. For me, it hits the right balance between looking really nice, and not hogging all my CPU cycles to achieve it. I can still run it on slightly older hardware and it works fine.
After installing, and without very much hassle, I found myself watching BBC iPlayer in Chromium, listening to music in the Spotify Linux client and writing some notes in the ReText markdown editor. But I was also enjoying the experience. I spend all day switching Operating Systems (every day I use Mac OS, Linux, Windows, iOS and Andriod), but after a few hours on Elementary OS I was thinking to myself “yeah, I reckon I could use this all day”.
So Elementary OS is the first one that I don’t really want to uninstall. I’m comfortable with it. I hope that feeling lasts. I have an old Desktop PC sitting around, I may install it there too.
So recently, several of the different things I have been messing about with have come together. This was always in the back of my mind,
but I didn't really know how long it was going to take. Recently, I have been working on:
- building my own webserver (dweb)
- cross-compiling for Linux on a TP-Link router (with OpenWrt)
- ...and my own experimental programming language (H2D2)
Now I have bean able to bring all that together, what it means is that I can run
H2D2 programs on my little TP-Link router. At the moment, I'm doing it through
jQuery Ajax calls. So the programs are sent to the router with an HTTP POST from an ajax request, the router runs the program remotely and then returns the output back to the browser. Nice.
Here is a screenshot showing it all in action:
Woo-hoo... it works! Oh, and apologies for the partial ASCII Mandelbrot,
I really can’t help it.
The next experiment will probably be to do what H2D2 was actually designed for,
namely to run a program partially on the router and then finish off the same
program instance on some other platform. Then, I should be able to bounce a
single program between the router, a Raspberry Pi and a desktop, which will
be a neat trick.
I blogged before about building a Raspberry Pi music player by numbers thingy and I said that I’d mention some more details about the software used. I did write up the notes, but then forgot to post it on the blog, so here goes, better late than never…
I had already mentioned the USB Message Board linux driver and the MP3 player that I used. The USB Message Board also requires the libusb-1.0-dev package to be installed, like this:
sudo apt-get install libusb-1.0-0-dev
But before I got that far, I needed an OS … and I wanted a version that wouldn’t corrupt the filesystem on the SD card if I just switched the power off at the mains. I have ended up running something called IPE - Industrial Perennial Environment of which I’m using the R1 edition, which is based on Raspbian. It seems to work a treat: I don’t need to worry about clean shutdowns, the filesystem runs in read-only mode. The R2 version of IPE looks even better, but for the time being I’ve stuck with the Raspbian derived version which is more familiar to me.
It goes without saying, that the webserver I used to provide the web-based API was my own dweb lightweight webserver which seems to have done the job very well.
I also wanted the Raspberry Pi to offer its own WiFi hotspot, for which I followed these instructions. After that I also followed this advice and disabled ifplugd for the wireless lan.
So … putting those things together and with a simple C program, I have:
- a version of Raspbian which can be powered off without a safe shutdown
- a Raspberry Pi which operates a WiFi hotspot with a DHCP server
- an MP3 player which shows the track number on an LED display
- a web based user interface and API
Normally, I just use Safari on my iPhone to call up a song over WiFi, but I added a numeric keypad as a backup, in case of WiFi interference or other problems. I’m sure that I could really go to town and make a much more complicated wireless MP3 player out of this … but what I have just seems to work perfectly, so at the moment I’m leaving it well alone.
Recently, I have taken to writing a lot of notes in markdown syntax. When doing this on Andriod, I have had a lot of success with Writeily. I recently used it to take notes for three days straight and it worked brilliantly! I have naturally used markdown-type syntax for many years, so it is no trouble for me to take notes in this way. I find that when using a tablet to take notes, it’s much easier to use this type of syntax rather than try to highlight bits of text with my finger and select formatting options. That’s just too fiddly, and I end up losing concentration.
I am planning on using Pandoc to convert the resulting text file into something else. So, if I wanted to convert my markdown notes (contained in a .txt file) into a word document, I would be using a command like this:
pandoc -f markdown_github test.txt -t docx -o test.docx
...which should leave me with a nicely formatted Word file. Doing that, I should be able to take notes without needing to go back over them and re-format them later. I also find that it's easier to remain consistent this way. All the headings look the same, etc. I reckon it’s a pretty cool way to take notes, and if you’re a programmer, and used to following a particular syntax, you won’t find it hard to do.
I've bought myself a new watch, one of these Casio MP-PCGM1-6 ones:
I've decided that I'm one of those people who really does think that the digital watch is a pretty neat idea.
But you need to be careful. The first one I ordered was from one of the Amazon shops and when it arrived I was pretty sure it was a fake. It was very poor quality, the plastic was rubbish and the printing on the dial didn't look right. It just arrived in a jiffy bag with no other packaging. But I was able to get a refund. This time, I ordered from a jeweller, and there's no doubt this is the real deal. It also came in a proper Casio box. Don't settle for a poor quality digital watch...