Alasdair Morrison - Glasgow Based Web UI & Mobile Software Developer

Download My CV

  1. Rules for Clean Javascript

    Rules for Clean Javascript 2017

    Create MORE functions (rather than large functions)

    • Helps with DRY

    • Easier to refactor

    Use Lodash rather than custom looping code (when you can)

    • Optimised for most common cases (much more optimised than underscore)

    • Peer-reviewed for bugs and performance

    • Creates more shareable code as long as both projects are using lodash

    Use a consistent code format throughout the whole project

    • Make it auto-format on save

    • Can use Standard or SemiStandard

    • Auto convert tabs to spaces (IDE plugin or automated task)

    • Auto remove any excess spaces at end of line (IDE plugin or automated task)

    • Benefit: Removes noise from Pull-Request reviews

    Use Longer names when possible (as long as they are more descriptive)

    • It’s better to have longer variable/function names than comments that explain the purpose of a variable (see: Clean Code)

    2017/07/30

  2. Magic Assert

    About Magic Assert

    The test framework Ava has introduced a very useful new feature that they call “Magic Assert”.

    It is basically a normal assert statement, but when the result is not expected it shows a nice diff explaining what it go and what it was expecting.

    Screenshot of Ava Magic Assert

    image alt text

    This is the main feature that pulls me towards using Ava instead of Mocha or Jest testing frameworks. However it got me wondering, why not have an assert library that is generic enough to work with all test runners. Similar to how Chai works seamlessly across these frameworks it would be great to have a “magic-assert” library that also works with the testing framework of your choice.

    Watch this space! 😉

    2017/03/08

  3. Automatically Format Javascript and HTML files on Save with Grunt

    Create the config

    The following jobs will require a config variable is set, so it knows where all your javascript files are located.

    var config = {
        all_js_src: ['./app/**/*.js']
    }
    

    Remove trailing whitespace on lines

    First I wanted to automatically make sure I haven’t left any trailling whitespace on any lines. This will remove them automatically and can run on file save.

            //
            // # Trim trailing whitespace on lines
            //  * needed as this is a warning in Sonar
            //
            trimtrailingspaces: {
                all: {
                    src: config.all_js_src,
                    options: {
                        filter: 'isFile',
                        encoding: 'utf8',
                        failIfTrimmed: false
                    }
                }
            },
    

    FixMyJS

    You will need to have created a .jshint file with your preferences in the root directory of your project.

            //
            // FixMyJS - Automatically fixes common JS Lint erorrs
            //
            fixmyjs: {
                options: {
                    config: '.jshintrc',
                    indentpref: 'spaces',
                    camelcase: false,
                    quotemark: true,
                    curly: true,
                    multivar: true,
                    asi: true,
                    eqeqeq: true,
                    ext: '.js'
                },
                all: {
                    files: [{
                        expand: true,
                        cwd: './',
                        src: config.all_js_src,
                        dest: './'
                    }]
                }
            },
    

    Make it beautiful

    This will sort out the styling of the code to make sure all your files are consistent.

            //
            // # Prettify Javascript files
            //
            'jsbeautifier': {
                files: config.all_js_src,
                options: {
                    js: {
                        jslintHappy: false
                    }
                }
            },
    

    Grunt Task

    Add this grunt task to your Gruntfile.js if you want all the tasks to run as one:

     //
        // # This task will run all the automated javascript code cleaning
        //
        grunt.registerTask('cleanjscode', [
            'trimtrailingspaces',
            'fixmyjs',
            'jsbeautifier'
        ]);
    

    Run on file Save

            //
            // # Watches files for changes and runs tasks based on the changed files
            //
            watch: {
                dashboardjs: {
                    files: config.all_js_src,
                    tasks: [
                        'cleanjscode'
                    ]
                },
    

    Git commit hooks

    If you want to automatically do this just before commiting you can add the following grunt task:

            //
            // # Pre Commit Git Hooks
            //
            githooks: {
                all: {
                    // Will run the jshint and test:unit tasks at every commit
                    'pre-commit': 'cleanjscode'
                }
            },
    

    2016/11/29

  4. Installing Apache mod_auth_openidc OpenID Authentication

    Purpose: I wanted to use OpenID Authentication to restrict access to a few directories on my apache server

    First download the installer from github

    wget https://github.com/pingidentity/mod_auth_openidc/releases/download/v1.8.7/libapache2-mod-auth-openidc_1.8.7-1ubuntu1.trusty.1_amd64.deb
    

    Install the package

    sudo dpkg -i libapache2-mod-auth-openidc_1.8.7-1ubuntu1.trusty.1_amd64.deb
    

    Install Dependencies

    sudo apt-get install -f
    

    Enable the module for apache

    sudo a2enmod auth_openidc
    

    Restart Apache

    service apache2 restart
    

    2016/02/07

  5. rarfile.RarUnknownError: Unknown exit code [1]: bsdtar: Unrecognized archive format Python

    So recently I have been trying to unrar files in python with limited success.

    After spending what felt like hours trying to track down the problem it was quite a simple fix.

    So if you get this error: rarfile.RarUnknownError: Unknown exit code [1]: bsdtar: Unrecognized archive format

    Then you just need to install the unrar executable like so:

    On Mac:

    brew install unrar

    On Ubuntu:

    apt-get install unrar

    Good luck!

    2015/03/04

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

Enigma function approval process, fork to contribute to enigma!

4 0

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

3 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

Automated testing for Enigma, tests compatibility with a large number of game maker projects

1 0

CodeOnTheGo is a mobile code editor which uses a touch interface to modify syntax elements

1 0