Using Gomix to share a JavaScript example with npm dependencies

Websites like JSBin and CodePen allow folks to share examples of front-end code.

Chill the Lion, the Most Hearted Codepen of 2015

You can see the source code right next to the running page, and make edits that show up as you go. Super useful.

These websites let you load bundled libraries, like jQuery or React. However, many libraries expect users to install the library via npm, and don’t distribute bundled versions of themselves. That means they’re incompatible with these online editors.

So what do you do if you want to share JavaScript code that has npm dependencies?

Gomix is an online code editor from Fog Creek Software that came out today. It is totally rad and solves this problem.

For example, I created of a ProseMirror editor in the browser. You can see the code here. If you wanted to use this boilerplate, you can fork it (“remix” in Gomix’s vocab) to create a copy in your account and go wild.

In Gomix, you edit in one window while your example displays in another.

I also made a basic Webpack setup, which is a starting point for any JS code you want to share that has npm dependencies, or if you want to use JavaScript modules in your example code.

This is made possible by the fact that Gomix is basically a nice text editor for a Node.js server that will install npm dependencies for you. I’m using Webpack and Webpack Dev Server to bundle JavaScript modules and serve them out.

Have fun!

Make your phone vibrate

When you touch your screen on this webpage your phone will vibrate.

This page was made possible by the Web Vibration API.

I like “let”

The let statement in JavaScript is a new way to declare a variable. It has block scope rather than function scope, which avoids problems that the function scope of var has. I heard Rick Waldron of TC39 say that function scope is basically a bug, so the introduction of let is basically a bug fix. 🙂

The const statement is similar to let, but also creates an “immutable binding.” That means the variable can’t be reassigned, and increment and decrement operators can’t be applied to the variable. const x = 3; x = 5; throws a TypeError exception, and so does const x = 3; x++;.

Const is not an immutable variable though, contrary to its semantics. const x = [3]; x.push(4); is error-free code, and results in x = [3,4].

I like and use the let statement. I don’t use const because the effort to keep its utility in my head outweighs its functional benefits while I’m writing code.

Choosing keyboard shortcuts for websites

Keyboard shortcuts give users fast methods to interact with an application. Native apps like Microsoft Word have shortcuts for nearly every editor command. This lets the user focus on authoring text rather than shifting their focus to navigating an involved File menu.

If the web is the application platform of the future, websites should also offer keyboard shortcuts for efficiency. However, you can’t pick just any shortcuts.

For example, a few weeks ago a bug was reported in ProseMirror, an in-browser text editor. Normally when a Mac user is editing text, pressing Option+Right moves the cursor right by one word. Pressing this shortcut in ProseMirror was not doing this, because Option+Right was internally bound to custom, two-step shortcuts. For example, pressing Option+Right then * in ProseMirror would wrap the text selection in a bullet list. Oh crap!

This bug has been fixed 🎉 but gives you a feel for the rocky terrain of keyboard shortcuts on the web.

Use familiar shortcuts

Google, Twitter and Facebook provide some common shortcuts. It’s likely your users will try these shortcuts on your site too.

If your website is a list of items (like emails in GMail or tweets in Twitter), pressing Up and Down arrow may navigate the user’s focus through the list. The browser default of scrolling up and down the screen is ignored, replaced by a behavior similar to the default in spirit but with more awareness of user context. The keys J and K often navigate up and down as well, which is a shortcut borrowed from the Vim text editor.

The Enter key may expand the view of a selected item (like opening an email).

The / key (forward slash) may focus the user’s text cursor in the site search (Also from Vim). Update: Eevee told me the / key opens Find in Page in Firefox, so keep that in mind while deciding whether to use this shortcut.

Make Shortcuts Discoverable

If your website offers keyboard shortcuts, your users will want to know what they are. Provide a link somewhere in your application to see a list of them, like under a menu. Users should not have to try key combinations to find shortcuts like a game of bobbing for apples. Shortcuts should be discoverable.’s keyboard shortcut help modal

Pressing the ? key (question mark) is a common shortcut to bring up a list of available shortcuts.

Keep in mind that screen readers used by those with impaired vision override almost every single key shortcut. If a shortcut is critical to navigate your website consider placing them under modifier keys.

Using modifier keys

You may want to create multi-key shortcuts that include modifier keys (e.g. the Control, Command or Alt key).

If your website includes text input fields, you may want shortcuts on modifier key combinations so can trigger a shortcut while focused in an input field. If your website has a save command, you may want the familiar shortcut Command+S/Control+S to trigger this save command, rather than the browser default of saving the HTML of the current webpage to your computer.

A user’s operating system and web browser have built-in shortcuts which are bound to various modifier and key combinations. Here is a list of operating system and browser keyboard shortcuts. Are your OS/browser shortcuts not listed? Let me know and I’ll give you edit access.

With this list you can make informed decisions about what keyboard shortcuts to choose.

Most operating system behaviors cannot be prevented. e.g. Pressing Command+Tab on a Mac to switch between apps, and can’t be disabled.

Browsers also limit what shortcuts can be disabled. Command+1 in Mac Chrome switches the user to the first tab. This can be overridden, but not in Safari. See what shortcuts can be disabled in your browser in this demo, which tries to prevent the default behavior when any key is pressede.

Respect user intent

It is up to you to decide what shortcuts to offer users, and whether to override browser shortcuts.

Lea Verou makes an interesting case for overriding browser defaults. Her argument is that if your websites has tabs, overriding the browser shortcuts for switching between tabs is useful, and avoids hard-to-remember shortcuts like Control+Alt+1. She says,

the browser environment is merely a host, like your OS. The focus is the web app. When you’re working in a web app and you press a keyboard shortcut, chances are you’re looking to interact with that app, not with the browser Chrome.

These choices are up to you, but they are user experience questions which I don’t have answers for. Make informed decisions and consider what the user intends to do when they press a shortcut, and how your application reacts to it.

There are some shortcuts that should just work. Take the ProseMirror bug I mentioned before. When a Mac user is entering text, pressing Option+Right moves their text cursor right by one word. I’d expect this to work when I’m typing into a text field on a website, so a shortcut shouldn’t override it while I’m typing.

Expect edge-cases in international contexts

Operating systems around the world have made hard choices in the last 30 years to make the QWERTY keyboard work across different languages. This can lead to unexpected behavior, for example Polish users could not enter the Ś character into Medium’s editor, and saw their document getting saved instead. Medium fixed this bug 🎉 and if you get a bug like this, you should respect user intent too!

Now close this tab in your browser (Command+W/Control+W) and go add shortcuts to your website!

Pad, an online note-taking app

I like writing and I mainly do it in private. Just in the month of July I’ve created 83 “notes” in my Evernote account, which I use in a lot of different contexts. I note-take in meetings at work, I write Dear Diary-style personal entries, and throw notable educational videos (the note here was “always get the bigger pizza?”). Evernote has basically been my life’s junk drawer.

There’s two main things Evernote does well: It syncs all my content to *~the cloud~* so I can access it at work, home and the in-between, and it works while I’m in the subway, syncing when I have service again.

This has been a lovely relationship with an app until Evernote decided to change their subscription model, limiting users that don’t pay (including yours truly) to use on two devices. 😑

I will leave the Evernote for Pad, an in-browser note editor I made earlier this week. It is a work in progress (you can’t even delete a “note” yet!), but it is marginally usable now. Try it out, but don’t count on it until I release version 1.0.

Pad is free now and will always be free for any use. It’s free as in free software available on Github, as well as free as in you don’t owe me anything.

I’m going to steal two things from Evernote, their best features: syncing to the cloud and offline use.

Currently data is stored in your web browser, indefinitely, unless you clear your “Local Storage.” I will never get access to your data since it is “local.” There’s no remote server that Pad relies on for saving your data. We can try to save data to arbitrary data stores (e.g. Amazon S3 or in your Github Gists). If your data is in a private place in *~the cloud~* then you could use Pad on any of your devices 😎

Pad could work offline too, through the magic of which Progressive Web Apps.

How OJ won

I binge-watched the entirety of ESPN’s new documentary series on O.J. Simpson over Fourth of July weekend. It is eight hours long and it is stunning.

As an 8 year-old during the O.J. murder trial in 1994-95, I had no idea what was going on. My attention was probably on beating Super Metroid. I didn’t know O.J. held the single season rushing yards record, that he was a major black icon of the 70s and 80s, or the details of his trial, so this is a good history lesson.

The central tension in the murder case is that the evidence that proved he was guilty beyond any doubt, yet he is acquitted. They found Nicole Simpson’s blood in O.J.’s white bronco. O.J. owned the shoes that matched bloody footprints at the crime scene, of which there were only 200 pairs made. How could the jury have acquitted him?

Other factors made for an involved case. O.J. assembled a legal “Dream Team” which included Johnny Cochran and Robert Kardashian, costing him $50k a day. During the trial, the D.A. was clever enough to have O.J. to try on the bloody glove found in his backyard. It didn’t fit. The cop who found that bloody glove? He turned out to be a racist bigot, leading the public to suspect a conspiracy with racial motivations were behind the case.

It seems like a poorly executed prosecution on top of sloppy police work. But then you hear one of the juror’s from the predominantly black jury explain her decision: this was her own payback for Rodney King, a victim of police brutality in L.A. a few years earlier. Cops get off all the time for using excessive force against and killing innocent black persons. She wanted to make sure that a black man would win in the trial of the century. As a member of a group endlessly oppressed by this criminal justice system, why would she vote any other way?

Obligatory New Blog Statement of Intention

Oh man I just fired up a new web log. That means one thing: a statement of my plans and inspirations for this here digital notebook must be set. Unlike New Years resolutions I will actually keep to these tenets. So here we go:

  1. Keep it 💯
  2. Blog Every Day™
  3. Always be on the lookout for Hot New Widgets to keep my readers interested and engaged