Alasdair Morrison - Glasgow Based Web UI & Mobile Software Developer

Download My CV

  1. Speed up/slow down HTML5 video

    I often use a tool called Enounce Myspeed to change the speed of Flash videos, it works very well and allows me to watch videos at any speed I want. This is often useful to watch tutorials at double speed to see if its worth watching and then slow it down to half speed when I need to focus on how something was done.

    The problem is youtube randomly displays video in Html5, even although I have disabled the Html5 beta test.

    This was rather annoying as I have become so used to playing video in double speed that going back to the normal speed seems rather slow.

    So after a few google searches and trial and error I managed to make my own chrome bookmark which will allow me to pick the playback speed of the html5 video. just create a new chrome bookmark with the following in the url box:

    javascript:(function() { var videoNumber=prompt("Which video number (0 to x)","0"); var playbackSpeed=prompt("Playback speed?","2.0"); document.getElementsByTagName("video")[videoNumber].playbackRate=playbackSpeed;})();
    

    Give it a title such as “Change video speed” and add it to the chrome bookmarks bar.

    Now anytime you are on a site with html5 video, you can easily change the playback speed by entering which video and what speed you want it to play at.

    Sadly it doesn’t work on iOS since the playbackRate isn’t supported, but hopefully one day, I will test on android later on (hopefully chrome for android will support it).

    Good programming sites that this will work with include: http://channel9.msdn.com/

    On iphone there is a great app for speeding up videos on the device and from youtube called SpeedUpTv: http://mix1009.com/en/?page_id=84

    2012/03/19

  2. Loop Wisely in Java

    The following list is from the google I/O talk in 2008 called “Dalvik Virtual Machine Internals” its a list of ways to loop over a set of objects in order from most to least efficient:

    (1) for (int i = initializer; i >=0; i--) //hard to loop backwards (2) int limit = calculate_limit(); for (int i= 0; i< limit; i++) (3) Type[] array = get_array(); for (Type obj : array) (4) for (int i =0; i< array.length; i++) //gets array.length everytime (5) for (int i=0; i < this.var; i++) //has to calculate what this.var is (6) for (int i=0; i < obj.size(); i++) //even worse calls function each time (7) Iterable list = get_list(); for (Type obj : list) //generic object based iterators slow!

    The first 3 are in the same territory of efficiency, avoid 7 if possible.

    This is mainly advice to help battery life but could potentially help Java SE code too.

    Another piece of advice he gives is to avoid memory allocation as much as possible, especially in loops!

    2012/03/01

  3. Interpreters101

    While watching "Google I/O 2008 - Dalvik Virtual Machine Internals" (http://www.youtube.com/watch?v=ptjedOZEXPM) they demonstrated a great example of how a simple bytecode interpreter is implemented. Since I am fascinated by the inner workings of compilers and VM/interpreters I thought I would share the example here for anyone else that is interested.

    The first example is the simplest version, a simple for loop that loops over each byte and depending on the value of each byte it will execute a different command, this version is very portable as it doesn't use any low level assembly code, so this example can be compiled for many different platforms.


    /*
    Google I/O 2008 - Dalvik Virtual Machine Internals
    Interpreters 101, toy interpreter
    This is a simple toy bytecode interpreter
    */
    #include <cstdio>
    static void interpreter(const char* stringOfBytecode);
    int main(int argc, char *argv[]) {
    interpreter("abcbbbbde");
    }
    static void interpreter(const char* stringOfBytecode) {
    for (;;) {
    switch (*(stringOfBytecode++)) {
    case 'a': printf("Hell"); break;
    case 'b': printf("o"); break;
    case 'c': printf(" w"); break;
    case 'd': printf("rld!\n"); break;
    case 'e': return;
    }
    }
    }

    The next example whos a much more efficient implementation: the gcc way! It removes a number of the branches required in the last example, so right after executing the op code code it can go staright into the enxt opcode! Rather than the first example where it had to branch to the end then to the next for loop iteration etc. So it is alot more efficient!


    /*
    The gcc way
    */
    #define DISPATCH() \
    { goto *op_table[*((stringOfBytecode)++) - 'a']; }
    static void interpreter_the_gcc_way(const char* stringOfBytecode) {
    static void* op_table[] = {
    &&op_a, &&op_b, &&op_c, &&op_d, &&op_e
    };
    DISPATCH();
    op_a: printf("Hell"); DISPATCH();
    op_b: printf("o"); DISPATCH();
    op_c: printf(" w"); DISPATCH();
    op_d: printf("rld!\n"); DISPATCH();
    op_e: return;
    }

    There is also an assembly example which is even more efficient, since there are still come cases where humans can write more efficient assembly than compilers.

    2012/03/01

  4. Simple XML in Java

    For a new project I needed to parse a prewritten xml file and extract information, instead of going to the bother of setting up a c++ xml library I decided to try out Java’s built in class library for xml parsing.

    First you will need to include the standard xml packages that we will use for simple xml loading:

    import javax.xml.parsers.*;
    import org.w3c.dom.*;
    import java.io.*;
    

    Next we want to open an xml document to read from:

    DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
    Document doc = docBuilder.parse(new File("filename.xml"));
    doc.getDocumentElement().normalize();
    

    Next you will probably want to get all elements with a certain tag name, you can do this like so: NodeList packageList = doc.getElementsByTagName(“package”); //get all package elements

    Now simply loop over all the package elemetns it found:

    for (int i = 0; i < packageList.getLength(); i++) {...}
    

    Inside each package are subnodes so I would like to loop over them too (inside the loop above): Node resNode = packageList.item(i); NodeList packageDetails = resNode.getChildNodes(); for (int ii = 0; ii < packageDetails.getLength(); ii++) { ..}

    Now I would like to print out only the nodes called name inside the package, so first check if the current node in the loop is called name: if (detailNode.getNodeName().equals("name")) {...}

    Now that we know this is the name node lets print the contents of the contents: System.out.println("Name of package:"+detailNode.getTextContent());

    Very simple indeed, although this is a simple example its amazing the information you can use from xml files using this simple method!

    2012/02/02

  5. Free fonts on the web

    Best free front websites!
    Recently I have been looking for more interesting fonts for a couple of projects I am working on, the default fonts get old very quickly, even for very quick programmer art I like to have a font which blends with the theme of the game or website. In general I find typography very hard, i'm not a natural artist/designer, my main goal is to hack together graphics which look very pleasing to the eye but with the hope that an artist would eventually redo in order to give the wow factor. I'm really interested in learning about typography and how to make pleasant looking titles and GUI elements for games and websites so hopefully I will have some typography tutorial summaries on this blog very soon!


    This post will be updated as I find
    Anyway, here is the list of free font sites that I have come across which offer very nice looking fonts for the even better looking price of free!

    • Font Squirrel: http://www.fontsquirrel.com/ - Found this through a nettuts+ tutorial and thought it looks like an excellent resource.
    • Font leech: http://fontleech.com/  - Another great looking font website which I will have to take a closer look into

    In fact while browsing for similar sites I found this excellent blog post on the top font sites which contains quality fonts for absolutely nothing, check it out!

    2011/10/26

A Mac PDF Text To speech application for quick reading of PDF files, ideal for quickly taking notes on academic and technical papers which ProductivePDF reads the text aloud at high speeds. Too slow at reading? Find your mind wandering when reading boring documents? Find it hard taking notes? This application is for you!

6 1

Javascript implementation of the 39dll network library for GMHtml5

6 3

6502 Assembler written in python (based on asm6 by olimar)

4 0

Enigma function approval process, fork to contribute to enigma!

4 0

Example and API of Making Blogger Posts in Python

3 0

EnigmaJS html5 game development tool

2 1

Clang plugin which aims to allow dynamic instrumentation of functions with a low CPU overhead

2 1

Provides various functions to clean up Game maker games so they are able to compile with ENIGMA

1 0

Syncs Google Documents to Confluence Wiki Pages, allowing the data to be searchable on your wiki while easily editable in google docs.

1 0

Gameboy Disassembler - Convert assembled code back into Z80 assembly code

1 0