• Find leaked JS globals

    It can sometimes be easy to inadvertently leak variables / functions into the global scope in your client side javascript - this one-liner will report all non-browser global keys and their values on the page - just paste into your chrome console.

    keys(window).filter(function(key){ return ["location","document","window","external","chrome","top","lastpass_iter","lastpass_f"].indexOf(key) == -1;}).forEach(function(key){console.log(key, window[key]);});


  • CDN Failover

    For most sites you want to get the benefits of a CDN, but it is still a single point of failure. I came across this pattern recently though that allows you to fail over to a local file if the CDN library doesn’t load. Would probably have to take a different approach with CSS libraries though.

    <!-- try to download from CDN -->
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
    <!-- if failed, switch to local copy -->
    <script>window.jQuery || document.write('<script src="local_server_path/jquery.min.js"></script>')</script>

    Something I hope to explore more very soon is webpack, which might make this trick obsolete.

    Update: It took me a while to find where I had originally found this idea, but I came across it again. Credit: http://minime.stephan-brumme.com/. They also have examples for several other popular client-side js libraries.


  • Backup all MSSQL user databases

    At my previous job we had several projects where we worked with MSSQL express, maybe with multiple databases. Here is a quick script to just backup all user (non-system) databases on the system, quickly and easily. It could probably be improved a bit, maybe better naming for the backups, but as a quick backup-all-the-things it works great.

    Read more