Short Equity

Long dividends.

JavaScript, In My Opinion

I played Diablo 2 religiously in my formative years. Early in the plot you’ll meet Deckard Cain, an old man who pesters you to listen to what he has to say. The irony is not lost on me that in writing this, I’ll become JavaScript’s pestering old man. In the words of my spiritual predecessor: stay awhile and listen.

Despite being the most widely used programming language in the world, most people using it don’t have a clear understanding of how it works. Even worse, those who get it have a hard time teaching their secrets to in a way most people can quickly understand.

I don’t blame either group.

Gave up trying to understand monads for the same reason that nobody has been able to explain it to me in a way I can understand. On the other hand, I’ve never been able to explain to successfully explain to anyone how JavaScript works.

I’d like to share a few simple ideas that will change how you see JavaScript.

The ideas will explain clearly what makes JavaScript slow. With them, you will learn to recognize if the JavaScript you’re reading is slow and learn how to rewrite it to be fast. These ideas are applicable in JavaScript engines as old as the one Internet Explorer 6 uses and are valid today.

If you work with JavaScript, learn these ideas so you can finally enjoy working with this language.

The list is at the bottom of the post, if you don’t want to stay awhile and listen. *sigh*

Continue reading JavaScript, In My Opinion

Jackrabbit API


It’s tough to get started using RabbitMQ in Node.js. Almost every npm package exposed me to RabbitMQ’s raw complexity that seemed to know no bounds. Thankfully I was smart enough to realize I wasn’t smart enough to try using the powerful libraries. I needed something simpler.

Eventually found Jackrabbit, which markets itself as “RabbitMQ in Node.js without hating life“.

Jackrabbit hides RabbitMQ’s complexity behind a very beginner-friendly API, so it was an obvious choice to get started with. Today, I’m still happily using it 🙂

While I haven’t outgrown Jackrabbit yet, my needs are slightly more mature. Would love to hook into its event emitter so I can get some insight from (or just log) what Jackrabbit is doing.

Unfortunately there’s no public documentation of Jackrabbit’s API, so I’m writing this blog post to document my notes and serve as a starting point for other beginners.

Continue reading Jackrabbit API

Senior Crime

Japan is such an interesting place.

Due to its long life expectancy (27%+ of its population is over 65), many seniors have resorted to a very unusual tactic to get state-sponsored care: going to prison.

Neither the government nor the private sector has established an effective rehabilitation program for seniors, and the costs to keep them in prison are rising fast. Expenses associated with elder care helped push annual medical costs at correctional facilities past 6 billion yen (more than $50 million) in 2015, an 80 percent increase from a decade before.

At some facilities, being a correctional officer has come to resemble being a nursing-home attendant. Satomi Kezuka, a veteran officer at Tochigi Women’s Prison, about 60 miles north of Tokyo, says her duties now include dealing with incontinence.

Continue reading Senior Crime

Have You Tried Turning It Off and Again?

If your app has never experienced memory issues, is it really in production?

An Erlang-Inspired Node.js project I deployed at work runs out of memory randomly. It maintains a relatively flat memory usage profile at about 10% of the server’s RAM, but it will suddenly spike to 1.5x ~ 2x RAM.

Excessive Memory Usage on Heroku
Dotted line is my allowed memory usage. Definitely not the way I hoped to start the weekend 🙁

Thankfully Heroku is flexible enough to tolerate spikes under 2x of the allotted RAM so in most cases the app continues to do its job and the worst that happens is I get notified about it. Despite its ability to elegantly recover from crashes, my pride felt like it was being curb-stomped whenever Slack notified me the server ran out of memory again.

slack memory alert
Redacted so much it looks like a CIA release

After determining to redeem my self-respect by fixing the issue, I quickly realized I had no idea where to begin!

Continue reading Have You Tried Turning It Off and Again?

Erlang-Inspired Node.js

Despite the unshakable feeling that I’m a terrible programmer, I’ve end up going on some very experimental journeys writing code that reflects the way I think about software.

Unintentionally, though it makes sense in retrospect, my experiments in JavaScript have leveraged one another, reinforcing each other’s usefulness in my mind and building more confidence in the experiments.

While it’s probably not the best first experiment to discuss, I’d like to write about my most-recent one: a module that helps me write Erlang-inspired code for Node.js.

Continue reading Erlang-Inspired Node.js

My First Command Line Utility

I feel like a teenager who just discovered he has super-powers!

Angel showing off his wings
Image Source: Pop Mythology

Last year we gave our production servers the ability to send notifications to Slack and it’s been so helpful! Each one comes with all the relevant data, sometimes with a link to an admin page where you can fix the problem. It’s been truly empowering to deal with many types of problems without needing to write code.

One of the notifications is for a problem we can’t fix without input from our customers, so we needed to move the data from Slack to a Google Spreadsheet we could share with them.

Quickly discarding the idea creating an endpoint that gave me a CSV-formatted version of the data, I settled on copying the text straight from Slack (it was already there for the copy-pasting so don’t judge me) to a file and writing a program to process the Markdown-formatted data from Slack to generate the CSV.

The formatting program itself is nothing special, so straightforward I didn’t need to import a single library to make it work, but you wouldn’t believe how much more useful the program got after a tiny change at the beginning and the end of the code.

Continue reading My First Command Line Utility

How To Gracefully Shut Down Express.js

What happens when you try to shut down an Express.js server while a user is connected to it?

var app = require('express')();

app.get('/', function( req, res ){
  // respond after 10s
  setTimeout( function(){ 
    res.send( 'all done!' ); 
  }, 10000 );

app.listen( 5000 );

This is a simple express server that waits ten seconds before sending a response to a user.

Let’s find out what happens when I connect to it and shut the server down before it responds to me.

Continue reading How To Gracefully Shut Down Express.js