Mailing List Articles Atom Feed Comments Atom Feed Twitter Reddit Facebook

Tag Cloud

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

Thing list for 3 Thing Game!

The thing list for 3 thing game has just been released!

Find it here.

In case you can't read the list there, the list is as follows:

Tower, Beaver, Brain, Seagull, plane, Polo, Wombat, Harmonica, Pastie, Spam Fritter, Waifu, Shop, Pasta, Apocalypse, Pirate, Haunted, Really large gun, Struggle, Tentacles, Elephant, MLG, Skeleton, Parrot, Mayhem, Heist, Mountain Dew, Rhythm, Wristwatch, Rubber, Cauldron, Jacket, Doritos, Puzzler, stealth, Cat, Kit-Kat, Crimping, Undersea, Grunting, Zeus, Flesh Eating, Spell, Cool Spot, Potato, Clock, Boiler Suit, Pineapple, Space, Ocean Liner, Robot, Boots, Alien, Rainbow, Frantic, Drainpipe, Pig, Puzzle, Mushroom, Dressing Up, Hand grenade, Gong, Ninja, Steroids, Potion, Dilemma, Zombie, Bones, Graveyard, planets, Cube, Wand, Electric, Warlock, Jellyfish , Vampire, German, Paint, Nerds, Circles, Bus, Tunnel, Cupcakes, System, Broomstick, Party, Lazer, Sci-Fi, Panic, Skull, Ethical, Voxel, Plot, Locked, Robotic, Pixies, Unity, Spacecraft, Inventor, kettle, Balloon, Topdown, Ghost, Satan, Nuke, Nose, University , Banjo, Fingers, petril, Panini, Green, Flying Fish, Banana, Gems, Anti-aircraft gun, Android, Falling, Snakes, Combat, Goat, instakill, Chickens, Communism, Tribal, of Doom, Downstairs, Wolf, Umbrella, Maggot, Ship, Time, Weapon, Football, wizard, Cheesebot, Hunting, Grave, Slippery, Endoscope, Meme, Cheese, Yeti, Bat, Beard, Trousers, Attack, Witch, Assassin, Pension, Pea, Web, Triangles, Spider

Binary Searching

We had our first Algorithms lecture on wednesday. We were introduced to two main things: complexity and binary searching. Why it is called binary searching, I do not know (leave a comment below if you do!). The following diagram I created explains it better than I could in words:

Binary Search Algorithm

I have implementated the 'binary search' algorithm in Javascript (should work in Node.JS too), PHP, and Python 3 (not tested in Python 2).

Javascript (editable version here):

 * @summary Binary Search Implementation.
 * @description Takes a sorted array and the target number to find as input.
 * @author Starbeamrainbowlabs
 * @param arr {array} - The *sorted* array to search.
 * @param target {number} - The number to search array for.
 * @returns {number} - The index at which the target was found.
function binarysearch(arr, target)
    console.log("searching", arr, "to find", target, ".");
    var start = 0,
        end = arr.length,
        midpoint = Math.floor((end + start) / 2);

    do {
        console.log("midpoint:", midpoint, "start:", start, "end:", end);
        if(arr[midpoint] !== target)
            console.log("at", midpoint, "we found", arr[midpoint], ", the target is", target);
            if(arr[midpoint] > target)
                console.log("number found was larger than midpoint - searching bottom half");
                end = midpoint;
                console.log("number found was smaller than midpoint - searching top half");
                start = midpoint;
            midpoint = Math.floor((end + start) / 2);
            console.log("new start/end/midpoint:", start, "/", end, "/", midpoint);
    } while(arr[midpoint] !== target);
    console.log("found", target, "at position", midpoint);
    return midpoint;

The javascript can be tested with code like this:

//utility function to make generating random number easier
function rand(min, max)
    if(min > max)
        throw new Error("min was greater than max");
    return Math.floor(Math.random()*(max-min))+min;

var tosearch = [];
for(var i = 0; i < 10; i++)
    tosearch.push(rand(0, 25));
tosearch.sort(function(a, b) { return a - b;});
var tofind = tosearch[rand(0, tosearch.length - 1)];
console.log("result:", binarysearch(tosearch, tofind));


//utility function
function logstr($str) { echo("$str\n"); }

 * @summary Binary Search Implementation.
 * @description Takes a sorted array and the target number to find as input.
 * @author Starbeamrainbowlabs
 * @param arr {array} - The *sorted* array to search.
 * @param target {number} - The number to search array for.
 * @returns {number} - The index at which the target was found.
function binarysearch($arr, $target)
    logstr("searching [" . implode(", ", $arr) . "] to find " . $target . ".");
    $start = 0;
    $end = count($arr);
    $midpoint = floor(($end + $start) / 2);

    do {
        logstr("midpoint: " . $midpoint . " start: " . $start . " end: " . $end);
        if($arr[$midpoint] != $target)
            logstr("at " . $midpoint . " we found " . $arr[$midpoint] . ", the target is " . $target);
            if($arr[$midpoint] > $target)
                logstr("number found was larger than midpoint - searching bottom half");
                $end = $midpoint;
                logstr("number found was smaller than midpoint - searching top half");
                $start = $midpoint;
            $midpoint = floor(($end + $start) / 2);
            logstr("new start/end/midpoint: " . $start . "/" . $end . "/" . $midpoint);
    } while($arr[$midpoint] != $target);
    logstr("found " . $target . " at position " . $midpoint);
    return $midpoint;

The PHP version can be tested with this code:

$tosearch = [];
for($i = 0; $i < 10; $i++)
    $tosearch[] = rand(0, 25);

$tofind = $tosearch[array_rand($tosearch)];
logstr("result: " . binarysearch($tosearch, $tofind));

And finally the Python 3 version:

#!/usr/bin/env python
import math;
import random;

" @summary Binary Search Implementation.
" @description Takes a sorted list and the target number to find as input.
" @author Starbeamrainbowlabs
" @param tosearch {list} - The *sorted* list to search.
" @param target {number} - The number to search list for.
" @returns {number} - The index at which the target was found.
def binarysearch(tosearch, target):
    print("searching [" + ", ".join(map(str, tosearch)) + "] to find " + str(target) + ".");
    start = 0;
    end = len(tosearch);
    midpoint = int(math.floor((end + start) / 2));

    while True:
        print("midpoint: " + str(midpoint) + " start: " + str(start) + " end: " + str(end));
        if tosearch[midpoint] != target:
            print("at " + str(midpoint) + " we found " + str(tosearch[midpoint]) + ", the target is " + str(target));
            if tosearch[midpoint] > target:
                print("number found was larger than midpoint - searching bottom half");
                end = midpoint;
                print("number found was smaller than midpoint - searching top half");
                start = midpoint;

            midpoint = int(math.floor((end + start) / 2));
            print("new start/end/midpoint: " + str(start) + "/" + str(end) + "/" + str(midpoint));


    print("found " + str(target) + " at position " + str(midpoint));
    return midpoint;

The python code can be tested with something like this:

tosearch = [];
for i in range(50):
    tosearch.append(random.randrange(0, 75));

tofind = random.choice(tosearch);

print("result: " + str(binarysearch(tosearch, tofind)));

That's a lot of code for one blog post.....

Useful hidden chrome:// pages

Since I have a chromebook, I was browsing the list hidden internal pages over at chrome://about/ the other day to see if they had added any new ones. To my delight I found that they had - this post will be about the interesting ones.

Note: Some of the chrome:// pages mentioned will not be available in the desktop version of chrome.

Keyboard layout

A sample of the chrome://keyboardoverlay/ chrome internal page. May differ depending on device

Can't remember that keyboard shortcut? No problem - just visit chrome://keyboardoverlay/. This is the internal page that gets shown when you hit CTRL+ALT+/ in Chrome OS. It is even interactive, showing you the keyboard shortcuts associated with any combination of the Ctrl, Shift, and Alt keys on your keyboard.

Battery Information


Chrome OS keeps a log of your battery's percentage charge, and processor frequency data over at chrome://power/ - even when you don't have that tab open. It doesn't remember this data over a restart, though. You can show and hide 3 sections: Battery Charge, Idle State Data, and Frequency State Data.

The 'Battery Charge' section gives you a graph of how your battery discharged over time, obviously enough. It also shows you a graph of the charge / discharge rate in watts along with appropriate moving averages - useful if you are trying to save power on your chromebook and want to see if turning your wifi off extends your chromebook's life.

The 'Frequency State Data' section is not so useful (to me), but it shows the amount o f time your processor has spent running at different frequencies.

The graphs don't update live from what I can tell though, which would have been a nice feature to have.

Advanced Wifi Information

Chrome OS keeps some interesting information about the wifi networks that are in range and in your preferred list at (chrome://network/)[chrome://network/]. It displays the recent wifi related log entries, along with the MAC address, SSID, signal strength, security type, and more - useful if you want to debug your wifi connection.

Like chrome://power/, this page does not auto refresh either, but it does offer a convenient ?refresh= query string parameter to sutomatically refresh the page every so many seconds.

Other Pages Worthy of Note

THese other pages are also worth checking out, but didn't make it into the top 3:

  • chrome://net-internals/ - Shows everything you every wanted to know abou tthe network interactions that are going under the hood, and probably a whole lot of extra information that you probably don't care about too....
  • chrome://system/ - Holds a ton of informationo about your device, and the version of Chrom(ium) OS running.
  • chrome://gpu/ - Tells you what Chrome (OS) is using your GPU for, and what patches it has applied due to bugs in your GPU.
  • chrome://memory-redirect/ - Displays advanced memory information for each chrome process that is running.
  • chrome://imageburner/ - Houses Chrome OSes revcovery media creator.


I have included the most interesting chrome:// pages in this post. Some of them are only available on Chrome OS. All pages were found using Chrome OS 38 beta. If you find any more that are worthy of note, please leave a comment below.

Three Thing Game!

This is just a quick post to announce that I will be taking part in Hull University's Three Thing Game!

Three Thing Game is a game jam where you get virtual cash to buy 3 'things' at the auction of things, and then you make a game in 24 hours that includes those three things. It is organised by Rob Miles.

In other news I have been rather busy over the last few weeks, so there wasn't a post last Wednesday. It should be up sometime soon.

First Impressions: C♯

I will be learning C♯ over the next year or so, and since I am almost a week into learning it, I thought that I would post my first impressions here on this blog.

C♯ is a compiled language developed by Microsoft that looks a little bit javascript, and a little bit like Rust (If you haven't heard of rust yet, I have written up a first impressions post here). Like rust, it has a type system, so you can't set a variable with the type int to a string. This type system is not a confusing, though, since it only has a single type for strings (rust has two - one that you can change and one that you can't) and you can convert between the different types quite easily (e.g. int.Parse() converts a string to an int).

The brackets syntax is almost identical to that of Javascript, except C♯ has classes and namespacees too (I don't really know what those do yet). Indentation also seems to be fairly important, which is perfectly fine by me since it improves the readability of your code.

Looking around on the internet, it seems that C♯ is tied in with Visual Studio quite closely. This might cause problems in the future, because I don't really want ot install visual studio (express) on my computer because of it's file size (the installer alone is > 600MB!). Hopefully I can continue to use the csc C♯ compiler I found in the .NET 4.0 folder on my computer as my code becomes more complex.

All in all C♯ looks like a good introductory language to the world of compiled programming. The syntax is straight forward and easy to understand so far, and it is kind of similar to Javascript, which eases the learning process considerably.


Today marks the release of a larger project that I have been doing, called Imaanvas. It has been in the works for months and is meant to be a web based version of a program called MSW Logo, which is now called FMS Logo. It has a few tweaks, though, to make it slightly easier to use. It was orignally written for a year 5 class in a primary school.

It also does not come with all the commands present in Logo, so if you find that a command is missing please comment below and I will try to add it for you as soon as I have some spare time. (You can also write the command yourself, and I can add it that way, but will probaby need the original source code for that - gulp is used to compact the code - send me an email if you want the code)

Immanvas is a horribly complex piece of code - so if you encounter any bugs (which is likely), please either leave a comment below, or send me an email. Remember to be descriptive about the bug that you have found, otherwise I won't be able to track it down and fix it! Also remember that Imaanavs is meant for modern browsers, so if Imaanvas doesn't work in your browser, try upgrading it to it's latest version.

This post is late since essential maintenance work had to be carried out to try and reduce the amount of spam that is being posted.

Rust: First Impressions

You may have heard of Mozilla's Rust - a fairly new language developed by Mozilla for their new rendering engine, Servo. Recently, I took a look at Rust, and this post contains my thoughts.

Please note that I am looking at Rust (a compiled language) from the prespective of an interpreted language programmer, since I have not actually learnt any other compiled languages yet.

To start off with, Rust code appears fairly easy to read, and is loosely based on other languages that I already know, such as Javascript. You can quickly get the gist of a piece of Rust code just by reading it through, even without the comments.

The compiler is easy to use for beginners, and also quite helpful when you make mistakes, although some of the error messages are definitely not friendly to a new Rust programmer. I personally got totally confused by the finer points of Rust's type system, and the compiler was most certainly not helpful when it came to sorting the problems out.

The ability to set a variable equal to the output of a complex expression is also nice - allowing you to do this:

fn main() {
    let x = 2u;

    let y = match x {
        0 => "x is zero!",
        1 => "x is one!",
        2 => "x is two!",
        3 => "x is three!",
        4 => "x is four!",
        5 => "x is five!",
        _ => "x is larger than five!"

    println!("{}", y);

Rust has some nice language constructs too - the match statement above is an example is this. It looks so much better than the traditional switch statement, and is more flexable as well.

The problem with Rust, though, is that it doesn't really have very many different tutorials and guides out there for new programmers, especially those coming from an interpreted language background, like me. This will sort itself out though, in time. The language itself is also changing frequently, which makes keeping a tutorial updated a considerable amount of work. This also make the language more difficult to learn, since you can't be sure whether the tutorial you are reading is up to date or not. This problem will also gradually disappear on it's own as the language stabilises though.

To conclude, Rust looks like a promising new language that I will resume learning at some point in the future, perhaps when I have more experience with compiled languages (and type systems!), and when rust has stabilised a little more. At the moment Rust does not feel stable enough and mature enough for me to easily learn it.

Tutorial: Javascript Promises: There and Back Again in Half the Time

If you are familiar with javascript, the chances are that you have found this post. I found it to be a great introduction to promises in javascript, but I also found the post to be rather long and not good as a reference. This post, however is an attempt to condense the information found in the tutorial from html5rocks (Update! HTML5 Rocks has been turned into the Google Developers Web Fundamentals) into a nice neat package that is not only useful as a tutorial, but also useful as a reference.

The Problem and the Solution

When performing asynchronous tasks in javascript, you usually have to use callbacks and event listeners. This can quickly get unwieldy and difficult to understand. Promises were invented to rectify this problem. They allow you to chain function calls asynchronously - which generally cleans up your code and makes it easier to read:

function get(url)
    return new Promise(function(resolve, reject) { //important!
        var ajax = new XMLHttpRequest();
        ajax.onload = function() {
            if(ajax.status >= 200 && ajax.status < 300)
                resolve(ajax.response); //return the response

The important bit is the returning of a promise instead of actually performing the action requested. When creating a promise, a function is taken as the only argument. This function is then called with 2 arguments: a function that should be called upon success (usually called resolve()), and a function that should be called upon failure (usually called reject()).

Any number of asynchronous actions can be performed before either resolve() or reject() are called, but I would adivse that you put one async call in each promisified function.

The resolve() and reject() functions take a single argument: the value that should be passed onto the next function in the chain.

and then....

Once a promise has been returned, an API is exposed that allows you to chain functions together in a long string through the function then():

//                         then() adds a function to the chain
//                                        |--------v
get("").then(function(response) {
    //we got a response :D"Got response", response);
}, function(error) {
    //something went wrong :(
    console.error("Something went wrong:", error);

then() takes a pair of functions as it's arguments. The first function is called upon success (and passed the value that was passed to resolve()), and the second (optional) function is called upon failure (and passed the value that was passed to reject()).


The best part of javascript promises is the ability to chain then() as many times as you like:

get("").then(function(text) {
    return text.split("\n");
}).then(function(lines) {
    lines.forEach(function(url) {
        get(url).then(function(response) {
            console.log("got", url, "with text", response);

Infinite chaining

The problem with the above is that lots of ajax calls a being made at once. If you used this in your next big web app, it could bring your server down having all the requests being sent out at once.

There is, however, a solution to this too. We can process each value in an array one at a time using Array.reduce():

get("").then(function(text) {
    return text.split("\n");
}).then(function(lines) {
    lines.reduce(function(sequence, url) {
        return squence.then(function() {
            return get(url);
        }).then(function(response) {
  "got", response);
    }, function() { return new Promise(function(resolve) { resolve(); }); });

In this way, a new promise is created that resolves straight away (you can also use the Promise.resolve function is a shortcut here, but some implementations - especially Node.JS based ones - don't support this), and a promise for each url are then tacked onto the end of it. These are then called in a row - once th eprevious ajax request has completed, the next one will be sent. This can also be helpful when you are fetching content from a list of urls and you want them to be kept in order.


Promises are cool - they let you simplify complex asynchronous code. You can chain them with then() as many times as you like - and you can use Array.reduce() to chain calls that iterate over each value in an array.

So there you have it! A short tutorial on javascript promises. If you do not understand anything in this tutorial, please leave a comment below and I will try to answer your question.

Found a mistake? Leave a comment below.

Terminal Reference Sheet

While browsing my stackedit markdown documents, I found a reference sheet for the linux terminal. While originally posted on novitiate, I thought that it might be of use to someone on this website too. The reference sheet was originally designed for the raspberry pi, but it works for other bash like shells too :)

You can find it below.

Basic Linux Terminal Reference Sheet

Command Function
ls List the contents of the current directory
cd orange Change the current directory to the sub-folder orange
cd .. Change the current directory to the parent folder
cd ~ Change the current directory to your home folder
rm banana.txt Delete the file banana.txt
rmdir pineapple Delete the directory pineapple, but only if it is empty
rm -rf mango Delete the directory mango, even if it has files and folders inside it
mkdir cheese Create a new folder called cheese
mv Rename to
cp bread.7z cherry.7z Copy bread.7z to cherry.7z
mv cabbage oranges/tangerines Move the folder cabbage to the folder tangerines inside the folder oranges
sudo command Execute command as the root (administrator) user
sudo apt-get update Update the package list
sudo apt-get upgrade Update the currently installed packages
sudo apt-get install foo Install the package foo
rpi-update Update the Raspberry Pi's firmware1
raspi-config Start the Raspberry Pi configuration utility
nano apple.txt Edit the file apple.txt in the nano command line text editor
exit Exit the terminal
sudo shutdown -h now Shutdown
sudo reboot Restart
top View a list of processes using your CPU most intensively
CTRL + C Keyboard shortcut to exit most programs
CTRL + Z Keyboard shortcut to suspend the currently active process and return focus to the terminal
fg Resume the currently suspended process
jobs Display a list of jobs attached to the current terminal
bg 2 Put the job with the id 2 into the background2
disown 2 Disown the job with the id 2 so that it will not be terminated when the terminal is terminated2
help | less Pipe the output of the command help into the command less, which lets you scroll through large amounts of output with the arrow keys (press q to quit).
cat cakes.log | View the contents ofcakes.log. Tip: add lessto pipe it intoless` so that you can browse the file with the arrow keys.
man less Display the manual page about the command less
help less Display some basic help about the command less
ssh pi@ Connect to the device at the IP with the username pi and start a remote terminal session

Links to other useful lists

If you have any other commands or links to useful lists / references, please leave a comment below.

Have you found a cool bash reference? Post a comment below and I will consider adding it to the list.

  1. This needs installing first. See this page: 

  2. Note that to specify job #1, you type the command on it's own without the job id. 

Behind the Parallax Stars

Unfortunately I have been busy, so I have been unable to write this post up until now. Anyway, welcome to the second technical post on this blog. This time, we will be looking behind the Parallax Stars.

The FPS and rendering time graphs are drawn by a slightly modified version of stats.js, by mrdoob. It's original github repository can be found here, and the slightly modified version can be found here. The modifications I made allow both the FPS graph and the rendering time graphs to be displayed at once.

The interesting code that makes the stars work is found in stars.js. The function is a constructor that returns an containing everything needed to make the stars appear and animate. = function() { = [];

    for (var i = 0; i < this.number; i++)
    {[i] = new star();

    if(this.depthsort == true)
function star()
    this.z = Math.random()*(0.7) + 0.3;

    this.x  = rand(canvas.width);
    this.y  = rand(canvas.height);
    this.radius = Math.floor(this.z * 7);

    var r, g;
    r = rand(200, 255);
    g = rand(200, g - 20);

    this.colour = "rgb(" + r + ", " + g + ", " + 0 + ");"

    this.speed = this.z * 3;

The build() function contains some setup code that populates an array with stars, which are constructed by a different function, star(). Each star is assigned an x, y, and z co-ordinate. The x and y co-ordinates determine it's position on the screen. and the z co-ordinate determines it's size and speed. The stars are also given a colour too. The function rand() is a small utility function I sometimes use for generating random numbers:

// rand(256) returns a whole number between or equal to 0 and 255
// rand(100,201) returns a whole number between or equal to 100 and 200
// rand() returns a decimal between or equal to 0 and less than 1
function rand()
    // takes 0-2 arguments (numbers)
    var args = arguments, num;
    if (args[0] && !args[1]) { 
        num = Math.floor(Math.random()*(args[0]));
    } else if (args[0] && args[1]) {
        num = Math.floor(Math.random()*(args[1]-args[0])) + args[0];
    } else {
        num = Math.random();
    return num;

The array that hold all the stars is also depth sorted before we start and on each frame to keep the stars in order since stars are leaving the screen and new one coming onto the screen on every frame. The standard array .sort() function is used, along with a custom sort function:

function depthsort(a,b) {
    if(a.z < b.z)
        return -1;
    if(a.z > b.z)
        return 1;
        return 0;

The updates that happen every frame are split into two different functions. step() deals with incrementing co-ordinates and keeping the depth sorting up to date, and render() takes the current state and renders it on the canvas.

this.step = function() {
    for (var i = 0; i < - 1; i ++)
    {[i].x +=[i].speed;

        if([i].x > canvas.width +[i].radius + 1)
  [i].x = new star();
  [i].x =[i].radius - 1;

            if(this.depthsort == true)

The array holds all of the stars. For each star, it's x value is incremented by it's speed. If this moves the star off the screen, we replace it with a new star that starts off at the left hand side. The stars are then depth sorted again to keep all the further away stars behind the stars that are (supposed to be) closer to the front.

this.render = function() {
    context.clearRect(0, 0, canvas.width, canvas.height);

    for (var i = 0; i < - 1; i ++)
        context.globalAlpha = 1;
        context.globalCompositeOperation = "destination-out";

        context.arc([i].x,[i].y,[i].radius, 0, Math.PI*2, true);

        context.globalAlpha =[i].z;
        context.globalCompositeOperation = "source-over";

        context.fillStyle =[i].colour;

        context.arc([i].x,[i].y,[i].radius, 0, Math.PI*2, true);

To start off the rendering, the canvas is cleared. After that, For each star, a hole in the canvas is cleared with the destination-out drawing mode. The reason for this is that the z co-ordinate is also used as an alpha value for each star to make it dimmer the further away it is. This gives a slightly more realistic 3d appearance. After clearing a hole, the drawing mode is rest to the default (source-over), and the alpha and fill colours are set up according to the star's current z co-ordinates and colour respectively. Then the star is drawn. Since when this script was written we did not have a canvas drawing function to draw an ellpise, the context.arc([i].x,[i].y,[i].radius, 0, Math.PI*2, true); code is used to draw circles via context.beginPath() and context.fill().

Finally, One nice neat update() function is provided that calls render() and step() in sequence:

this.update = function() {

That concludes this technical post! If you have any questions, please post them below and I will try my best to answer them.

Art by Mythdael