Self-signed certs with secure WebSockets in Node.js

First generate your self-signed certs:

Then create your httpsServer from an express app using node’s built-in https server:

Then setup your websocket server (ironically this will use the same port as the http server, I didn’t know this but I guess protocols can share ports? — this had me going for awhile).

Now browse to server and accept the self-signed cert in Chrome. Then websockets should now work isnide the browser.

Open a chrome devtools console and type:

Fibonacci generator using EcmaScript 6 (es6)

I took my first stab at the --harmony flag on node 11 to play with generators.

Thanks to this video:

Here’s a simple example of using an ES6 generator to generate the first 10 numbers in the Fibonnaci sequence:

What wasn’t clear to me before watching this video by Netflix UI Architect Jafar Husain was that a generator returns an “iterator”….and on that iterator you call “.next()” to get the next yield. A generator can yield infinite times, so in this case we loop over the call 10 times to get the first 10 numbers.

Example of $resource in Angular.js with update and save using a resolver.

I had some issues trying to understand how to use a resolver (for edit view) and $resource to do both a POST (save) and a PUT (update) method call to an API.

Here is an example plurk:

Here is the route, the edit path uses a resolver to pass ‘thing’ object/promise back to the edit.html view before the page loads — this is to prepopulate the form:

Renaming JavaScript Objects

As you can see the object’s property of ‘baz’ is updated in both foo object and bar object (a copy or reference to foo).

Javascript Error: submit is not a function

Took me a google search to find this one, but for some reason one of my forms was not submitting using javascript.

The reason was the statement “formObj.submit();” in the javascript was colliding (resulting in ambiguity within the browser) with the form button, which was also named “submit”.


Change the name of the button to “login” or something else more reflective of it’s functionality instead of “submit”.