JavaScript destructuring with rename not logical?

To destructure a member variable from an object and rename it at the same time, the code looks like:

const { property: myprop } = { property: 'hello' }

Now that to me is back to front.  I would think it more logical to do it this way

const { myprop: property } = { property: 'hello' }

Why? Well because the direction of assignment is preserved in the second example, that is lhs is given the value from the rhs, or for example it logically equates to this

const { myprop = property } = { property: 'hello' }

it also matches normal property assignment where its lhs: rhs.

const o = { myprop: 'hello' }

But in JavaScript it actually works like this, which I think is just weird.

const { property >=> myprop } = { property: 'hello' }
Posted in JavaScript, Uncategorized | Tagged | Leave a comment

Chrome: How to step into code not available in debugger?

It’s been a while, but I am back!

Came across a situation today where I wanted to step through some javascript code that had been installed by a third party (in this case, a puppeteer script) so there was no source code available in the Sources tab to set a breakpoint in.

I used the following trick to allow me to step through the code.  First I turned on break on exception, and ticked pause on caught exceptions, then entered the following into the console…

try { undefined.a; } catch(e) { somethingWantToStepInto(); }

The undefined.a triggers an exception, which is caught and can be stepped into, so I can step through the code in the catch.  There may be another way to achieve this I don’t know, but thought this was a neat trick.



Posted in Chrome, debugging, JavaScript, Uncategorized | Leave a comment

Don’t like npm!!

Every time I have to use npm I find myself hating it.  I hate the general direction software development seems to be headed, with loads and loads of bloat.

An example of this taken to an extreme is the new Microsoft Cordova Multiplatform Template project.  When the project is created, before being built, it contains 10,000 files.  10,000!!!

Worse still, after building, that count goes up to 30,000 files!!!  I am sorry, but that is just ridiculous.  An empty built application template is 30,000 files and 167 MB in size.

Worse still, if you try and delete the project it fails, because windows explorer can’t handle the path length.  Sigh.

What is this shit?  It’s a joke is what it is.

Posted in Cordova, JavaScript, windows, Windows 10 | Leave a comment

Idea: Low Emission Zones & Engine Control Units

The idea is that a car’s ECU would know (triggered by GPS or NFC communication) when it is in a low emission zone and to automatically alter its driving parameters to reduce emissions while within the low emission zone.

Posted in Driving, Emissions, Uncategorized | Leave a comment

Find what is setting a global variable in javascript

Having identified an unknown global variable in your JavaScript application, how should you go about finding what is setting it?

Well one way is to watch for the variable being set as follows.  In this example, I look for something setting the ‘value’ global variable:

  var value;
  Object.defineProperty(window, 'value', {
    get: function(){ return value; },
    set: function(val) {
      value = val;
      debugger; // BOOM!

Just paste that into your debugger console, and run your code.  To find other global variables, just change ‘value’ to the name of the variable you are interested in.

Credit to :

Posted in Uncategorized | Leave a comment

iOS Safari correct viewport size

In our html5 application on iOS, in particular when running as a home screen icon, there was an annoying extra 20px of space at the bottom of the window that allowed the content to be scrolled up underneath the status bar. For a long time I could not figure out what was causing this and simply ignored it.

On re-visiting this issue today, I tracked it down the the viewport meta tag setting height = device-height. I tried removing this and letting it work it out for itself but that made matters worse (even more space).

In the end, I came up with the following code to specify a specific height based on the device height less 20 pixels for the status bar:

<meta id="viewport" name="viewport" content="width=device-width, height=device-height">
(function() {
    var iOS = !!navigator.platform.match(/(iPad|iPhone|iPod)/g);
    if (iOS) {
        var viewport = document.getElementById("viewport"),
            content = viewport.getAttribute("content").split(/[ ]*,[ ]*/);
        for (var i = 0; i < content.length; i++) {
            var nv = content[i].split(/[ ]*=[ ]*/);
            if (nv[0] === "height" && nv[1] === "device-height") {
                nv[1] = window.innerHeight - 20;
                content[i] = nv.join("=");
        viewport.setAttribute("content", content.join(","));
Posted in Uncategorized | Leave a comment

Game crash at startup? d3d9.dll faulting module? Windows 8.1 / KB3000850 installed?

Some games/applications of mine started crashing at startup at some point after a windows update (as I run these games/apps infrequently its had to tell which particular update caused the issue).

I first experienced this with a program called Sourcetree after an update to Sourcetree it stopped loading. I tracked this down to an exception being thrown by d3d9.dll. I tried re-installing direct-x but all I got was a message saying it is already installed.

I searched for d3d9.dll on my disk to check what versions there were, comparing checksums, and the faulting one, was exactly the same checksum as the same version found under WinSxS which suggested to me that it was not a corruption issue.

I happened to try (cant remember why -probably was thinking along the lines of a permission issue) copying d3d9.dll into the application folder and lo and behold, the application now launches.

Fast forward several months, GTAV comes to PC finally. Install it, the launcher crashes at startup – bugger. After checking around for similar issues and not finding any solutions, I decide to try the d3d9.dll fix (can’t remember if I had already spotted the faulting module error or not) and lo and behold, GTAV launcher no longer crashes.

After a long and unfruitful support ticket with Rockstar who offered no help other than reinstall, reinstall again, reinstall with administrator, turn off your virus scanner blah blah despite being give very specific details about the problem (don’t you just hate stock responses) I did some more searching for the d3d9.dll problem.

I came across a post that referenced this problem, and a November update (timing is about right) that caused it. KB3000850

The advice seems to be to uninstall this update, but I have also seen comments from people saying they can’t uninstall it, and not sure I want to risk uninstalling it so many months later.

So I am left with my workaround, it works and now I know about it, it is quick to fix. No doubt at some point down the line I will come across a situation where this doesn’t solve the problem, but I will cross that bridge when I get to it. I don’t fancy re-installing the O/S just yet (it takes many weeks, even months to get all the software I use back on and configured).

So if you are experiencing this issue and d3d9.dll is the faulting module, try my workaround. The workaround is completely safe, just copy d3d9.dll from c:\windows\system32 to the folder where program that is crashing is installed. You can easily remove it again (or rename it) if it doesn’t solve the problem or causes other issues.

For reference (and google search) here are the faulting module details from event viewer for GTAVLauncher.exe

Faulting application name: GTAVLauncher.exe, version: 1.0.323.1, time stamp: 0x5527ed90
Faulting module name: d3d9.dll, version: 6.3.9600.17415, time stamp: 0x54505402
Exception code: 0xc0000005
Fault offset: 0x00000000000275aa
Faulting process ID: 0x616c
Faulting application start time: 0x01d077079e400e6c
Faulting application path: C:\GAMES\SteamLibrary\steamapps\common\Grand Theft Auto V\GTAVLauncher.exe
Faulting module path: C:\Windows\SYSTEM32\d3d9.dll
Report ID: de2a7d70-e2fa-11e4-826e-d8cb8a18af95

Posted in d3d9.dll, Direct X, Windows 8.1 | Leave a comment

HOWTO: Generate a javascript stack trace

(new Error(‘oops’)).stack

Posted in Uncategorized | Leave a comment

showModalDialog replacement

Ok, so this is not a drop-in replacement for showModalDialog, because it does not block javascript, and does require some code changes.  I wrote it to demonstrate that we don’t really need showModalDialog, we can achieve the use case (prevent interaction with the page while prompting for something else) without needing to block.

Update: Code now available on GitHub:

Here is the code:-

NOTE, due to WordPress crapyness, I can no longer show html source code, use this Github link to see the full source code

function showModalDialog(url, args, options) {
    options = options || {};
    return new Promise(function(fullfil, fail) {
        var cover = $('<'+'div>')
        var content = $('<'+'div>')
            .css({ width : options.width||'50%',
                  height: options.height||'50%',
                  left: options.left||'25%',
                  display: 'none'
        var iframe = $('<'+'iframe>').appendTo(content).attr("src", url)
            .on("load", function() {
                content.css({ display: 'block' });
        var close = function () {
        showModalDialog.dialogArguments = args;
        showModalDialog.returnValue = function(v) {
        showModalDialog.cancel = function() {

And here is an example usage: (actual source code)

showModalDialog('dialog1.html', { arr: [ 'my', 'args' ] }, { width: '50%', height: '50%' }).then(function(returnValue) {
    alert('dialog returned ' + JSON.stringify(returnValue));
    // rest of your code

And the dialog HTML:- (actual source code)

<h1>A sample dialog</h1>
<p>Hello World</p>
<p>This dialog returns 'hello'</p>
<h2>Dialog Arguments</h2>
<+div id="args"></div>
<button onclick="complete('hello')">Close</button>
function complete(v) {
args.textContent = JSON.stringify(parent.showModalDialog.dialogArguments);
Posted in Uncategorized | 4 Comments

Is Linux Secure? — Answer: NO

I find it amusing that probably the single most critical security flaw in the history of the internet (heartbleed) does not affect Windows!  

Amusing because for a long time the Linux camp has claimed how ‘secure’ it is compared to Windows, attributing open source as opposed to closed source as a major factor in that (flaws are found and fixed quickly by the community so the theory goes), yet this bug was introduced over 2 years ago, and has been affecting Linux servers on the internet for a full 2 years, before it was fixed.

  • Linux is NOT secure (there can be no disputing that fact at the moment, possibly one of the most insecure of the 3 major OSs).
  • Open Source does not guarantee security or quick fixes.

Perhaps the Linux vs OSX vs Windows security debate can finally be put to bed.  The plain and simple fact of the matter is, that each have their vulnerabilities, non of them are totally secure, and you should keep changing your passwords regularly and apply security updates regularly.

Posted in Uncategorized | Tagged , , , , | Leave a comment