We all have that guy who tweets too much about a certain topic we dislike. Or all those hardcore seasonal fans of the current NFL sensation. Or those annoying spotify/rdio links you’re never going to click!
I’ve been waiting for a while for mainstream Twitter clients to allow keyword or pattern based filtering, and when I realized people were starting to tweet about the 49ers the night before the game, I decided to finally address it myself.
The technique I’m going to describe consists in setting up a proxy to the Twitter API that lives in our computer, powered by Node.JS, that filters back responses based on arbitrary rules we setup. Not only does this give us the flexibility of using JavaScript, but it also means it will work with any Twitter client that leverages the API transparently. Yes, this includes the Twitter website!
if ( comments_open() ) { ?>Following my article A String is not an Error, I want to bring attention to an issue that similarly applies to JavaScript in general, but has special relevance in the Node.JS environment.
The problem boils down to the usage of {} as a data-structure where the keys are supplied by untrusted user input, and the mechanisms that are normally used to assert whether a key exists.
Consider the example of a simple blog created with Express. We decide to store blog posts in memory in a {}, indexed by the blog post slug. For example, this blog post would be posts['an-object-is-not-a-hash'].
I decided to write a little article to discourage an unfortunately common pattern in Node.JS modules (and browser JavaScript, to a lesser extent) that can boil down to these two examples:
// A:
function myFunction () {
if (somethingWrong) {
throw 'This is my error'
}
return allGood;
}
and
// B: async Node.JS-style callback with signature `fn(err, …)`
function myFunction (callback) {
doSomethingAsync(function () {
// …
if (somethingWrong) {
callback('This is my error')
} else {
callback(null, …);
}
});
}
In both cases, passing a string instead of an error results in reduced interoperability between modules. It breaks contracts with APIs that might be performing instanceof Error checks, or that want to know more about the error.
So here it is, the long awaited redesign! A few months ago I decided I wanted to re-focus my website on my writing and projects, so I reached out to my friend, the genius Rogie King, with some ideas.
Some of the new features that I’m excited about:
- Clearly defined post types: article, code snippet, video, photo and quote.
- Cool dynamic filtering and Twitter-like pagination. (#hash and pushState to come soon)
- Projects page that highlights my past and present work
- CSS3 animated sidebar with links to social networks & bio
- Commenting through DisqUS customized to my needs