Skip to main content


No, Don't Move to Canada

The 2016 presidential election year is upon us Americans. As the parties narrow on a candidate, it feels as though the atmosphere manages to get even more polarized. Eventually we start hearing the stories from friends and family, to even celebrities, stating “If [candidate I hate] get’s elected, I’m moving to Canada!”. We then all laugh once candidate X is elected (especially if we were a fan) as said person(s) don’t move to Canada.
Even though we know most people are not literally serious when they state this, I feel it highlights a bigger issue that we don’t talk about enough. Simply put, we place way too much importance on who holds the U.S. Presidential office. When we say “I’m moving to Canada”, we’re essentially saying that the fight is over, there is no hope, even though we don’t actually pack up our bags and move. Which indirectly is stating, that there’s nothing we can do as an individual or community. That out of all the issues America faces, no non-profit, grassroots organ…
Recent posts

Changing Password Requirements with SailsJS and Passport

Cross post from my employer's development blog:

If you perform an installation of [Passport][passport] with [SailsJS][sails] using the [Sails Passport Auth Generator][sails-generate-auth] you get several files in your app already configured for you. If you then use passport-local, you will already have a complexity requirement on the password. It defaults to requiring 8 characters minimum, letters, numbers, and symbols.

What if you want to change this requirement? In the generated model file `Passport.js`, you should see a line that says `provider   : { type: 'alphanumericdashed' },` and `password    : { type: 'string', minLength: 6 }`. The minLength is an easy and obvious change. What about the complexity requirement though? This stumped me for a bit. There doesn’t seem to be any mention of these keywords or providers on the Passport official site, nor anything in the [Passport-local repository][passport…

Moving to Babel 6 on the Server

Cross post from my employer's development blog:

Decided it was time to upgrade my server-side code to run on Babel 6. Below is a synopsis of all the issues I ran into and resolved while upgrading my 0.11.3 SailsJS server to run with Babel 6 transpilation.

The upgrade to Babel 6 itself is easily achieved in Sails by upgrading the `sails-hook-babel` package.

### Missing preset
`couldn't find preset "stage-0" relative to directory`
Just because a preset is on the official Babel preset page, doesn’t mean that Babel comes with it. Simple fix by installing the [package][1] from npm. Read more [here][2].

### Need strict mode everywhere
`Block-scoped declarations (let, const, function, class) not yet supported outside strict mode`
I didn’t have to worry about this before, and I don’t feel like …

IE Caches a Lot

Cross post from my employer's development blog:

In developing a page, I decided to do things a bit differently on the server. By doing an explicit check on the HTTP request headers, I can detect server-side if a request to the server is coming via XHR (Ajax) or a standard page load. I can then serve different content based on the request type. So, I can use the same URL for retrieving the initial HTML page and the raw JSON data associated with that page. Express makes this pretty easy:
if (req.xhr){      return res.json(await this.usersData());    }    else {      return res.view('users', await this.usersData());    }
I’m not sure if it’s technically more RESTful than having separate URL routes for data and HTML, but it felt like it made sense. The URL is referring to the same data, and based on a header, I want to determine how it is represented, but the data doesn’t change so why should the URL? This also makes it possible to d…

Quick Setup Using JSPM

Cross post from my employer's development blog:
Want to use JSPM rather than Bower for running the example? Follow these steps. This is basically a duplicate of the [Getting Started tutorial][tutorial] on the [ website][website] but using a really simple JSPM setup. This is a very crude guide where I list everything I had to do to get things running.

Create an empty project folder npm install Copy server code verbatim from the Getting Started guide jspm install Hit enter for all the prompts from JSPM

We’re going to modify the client side code a little bit. We have native support for ES6 compiling with JSPM/Babel so we can import the Deepstream client directly:

import deepstream from ''; let ds = deepstream( 'localhost:6020' ).login();

let record = ds.record.getRecord( 'someUser' );

let input = document.querySelector( 'inp…

Multiple Instruction Arrow Functions in ES6

Cross post from my employer's development blog:
Recently, I had a bit of JavaScript code that was a small series of map and reduce functions. To keep things nice and tight, I of course wanted to use single line arrow functions as much as possible. Implicit returns, no brackets, no ‘function’ syntax. I had one reduce() call though where my logic was this:
arr.reduce((list2, b) => {          if (list2.indexOf(b) === -1){            list2.push(b);          }          return list2;        }, []);
High level: only add item b from array arr to a new array if it doesn’t already exist in the new array. Simple duplicate removal for the original array. This works, and is probably the easiest to understand, but doesn’t make for the best grouping along with other calls on the same array. How could I modify this a bit so that I could use a bracketless arrow function with an implicit return?
arr.reduce((list2, b) =>          ((…

Debugging MapReduce in Javascript

Cross post from my employer's development blog:
With single line arrow functions in ES6, it’s getting easier and cleaner to use JS’s native and Array.prototype.reduce() functions for molding our data. I recently decided to go the MapReduce route for a project to filter some data upfront. Inevitably, I ran into some issues with my logic and wasn’t getting what I expected. Thing is, there doesn’t seem to be a simple way to add debugging to a chain of map() and reduce() calls, particularly if you’re using single line arrow functions.
     let behaviors = track.metrics        .reduce((list1, m) => list1.concat(m.behaviors), [])        .reduce((list2, b) =>          ((list2.indexOf(b) === -1 && list2.push(b)) || 1) && list2        , [])        .map(bId => json.behaviors[bId]);
Here I need to take multiple arrays of id’s, flatten them, remove duplicates, then map in their respective obje…