String replace helper for Dust.js

Recently, I’ve been learning about the LinkedIn fork of Dust – a client-side templating solution. Dust allows you to create helpers, which are functions that can be called from within a rendering template. They help separate presentation from logic, which is always a good practice.

Today we created a String Replace helper, which seems like it might be pretty useful for others, so I thought I’d share it.

Following is an example of the template in use. In this example, the replace helper will replace all instances of a period character with a hyphen in the given message string, and then it will write the trimmed result.

Usage example:

{@replace str="{message}" search="." replace="-" trim="true" /}

Here is the GitHub Gist string Replace Helper for Dust

Meet IIFE – the quintessential JavaScript closure

js-icon2If you want to call yourself a JavaScript bad-ass, then there is at least one little code pattern you should know by heart: the Immediately Invoked Function Expression (IIFE). This pattern defines a function that is executed immediately and it looks like this:

(function () {
    alert("Hello world, I'm an IIFE!");

This is an important pattern primarily because it provides a closure for initialization code, which allows you to keep temporary variables out of the global scope. That is to say, it encloses code in a function that acts as a scope wrapper or sandbox and that is executed immediately after it’s created. I find it easier to remember this pattern by breaking it down into the following steps…

Testing is the engineering rigor of software development

Developers love to use tortured metaphors when trying to explain what it is they do to family members, spouses, and other non-techies. We frequently resort to bridge building and other “hard” engineering disciplines. All these metaphors fall down quickly, though, when you start trying to push them too hard. It turns out that software development is not like many of the “hard” engineering disciplines in lots of important ways.


Compared to “hard” engineering, the software development world is at about the same place the bridge builders where when the common strategy was to build a bridge and then roll something heavy over it. If it stayed up, it was a good bridge. If not, well, time to go back to the drawing board. Over the past few thousand years, engineers have developed mathematics and physics they can use for a structural solution without having to build it to see what it does. We don’t have anything like that in software, and perhaps never will because software is in fact very different. For a deep-dive exploration of the comparison between software “engineering” and regular engineering, What is Software Design, written by Jack Reeves in C++ Journal in 1992, is a classic. Even though it was written almost two decades ago, it is still remarkably accurate. He painted a gloomy picture in this comparison, but the thing that was missing in 1992 was a strong testing ethos for software.

Track technical debt and pay it back quickly

If you find yourself having to choose between “doing it right” and “doing it quick” it’s often appealing to “do it quick” on the understanding that you’ll come back and fix it later. When you make this promise, you really mean it, but the next iteration usually brings new problems and you become focused on them. This sort of deferred work is known as technical debt and it is not your friend. Specifically, Martin Fowler calls this deliberate technical debt in his taxonomy of technical debt, which should not be confused with inadvertent technical debt.


Technical debt is like a loan: You benefit from it in the short-term, but you have to pay interest on it until it is fully paid off. Shortcuts in the code make it harder to add features or refactor. They’re breeding grounds for defects and brittle test cases. The longer you leave it, the worse it gets. By the time you get around to undertaking the original fix there may be a whole stack of not-quite-right design choices layered on top of the original problem making the code much harder to refactor and correct. In fact, it is often only when things have got so bad that you must fix it, that you actually do go back to fix it. And by then it is often so hard to fix that you really can’t afford the time or the risk.

From the Dictionary of Obscure Sorrows:


n. the realization that each random passerby is living a life as vivid and complex as your own—populated with their own ambitions, friends, routines, worries and inherited craziness—an epic story that continues invisibly around you like an anthill sprawling deep underground, with elaborate passageways to thousands of other lives that you’ll never know existed, in which you might appear only once, as an extra sipping coffee in the background, as a blur of traffic passing on the highway, as a lighted window at dusk.

Note to self: Those extras in the background of my movie are the stars of their own. I should look deeper.

Before you clock in this morning and get yourself lost in the game again, take a pause and watch this video. You’ve probably seen it already, but it won’t hurt to watch again. Within it, I found the most profoundly arresting statement I’ve ever heard.

The only appropriate response is gratefulness.

It helps me to remember that whenever I’m feeling afraid or angry – defeated, hopeless, ignorant, arrogant, impatient, ashamed, depressed, desperate, bitter, bored, dominated, judged, controlled, lost, resentful…self-absorbed…or any other such glove with which I slap the face of God.

Start SimpleHTTPServer from any folder on a Mac

Here’s a simple command that will startup an HTTP server from any given folder on a Mac. Open Terminal, cd to change to the directory you wish to serve files from, and then execute the following command.

python -m SimpleHTTPServer 8000

This can be very handy for web development on a Mac; especially when using the Google Chrome web browser, which doesn’t allow you to run JavaScript from your filesystem. Even if you bypass Chrome’s restriction by starting it with the –allow-file-access-from-files parameter, there can be cases where a web server is still desired. For example, when using Cross-Origin Resource Sharing (CORS) for cross-domain Ajax, the browser needs to report its origin with an HTTP request. When served by the web server, Origin will report ‘http://localhost:8000′ rather than ‘null’ or ‘file://’ as shown below.

How to install Google Chrome on CentOS 6 or 7

You can install Google Chrome on CentOS 6.X using a handy script developed by Richard Lloyd. My installation was successful on CentOS 6.5 with just the following three commands:

$ wget
$ chmod u+x
$ ./

Richard’s script downloaded and installed the latest Google Chrome browser by picking libraries from a recently released distro and putting them in the /opt/google/chrome/lib directory. I was then able to run the Google Chrome browser via the ‘google-chrome’ command as a non-root user. Piece of cake; thanks, Richard.

Eclipse tip – format source code on save

Pressing CTRL + SHIFT + F in the Eclipse editor will automatically format source code according to the default or specific formatter preference settings. However, if team members do not format consistently before committing code, relevant changes can become difficult to identify amongst code style changes. One way to alleviate this problem is to force Eclipse (or any Eclipse-based IDE) to format source code automatically on Save. Here’s how…