Monthly Archives: February 2015

Creating Reusable Angular Providers

Last night at the AngularJS meetup, I talked with AJ and Joe Eames about how to make a reusable providers. They didn’t know exactly but I finally figured it out so I thought I’d share.

See this plunker demo.

Basically, I wanted to make a provider similar to ngResource that could simplify data resolution. I wanted to make it reusable so I put it into its own module.

It had to be a provider so that I could inject it into my main app’s .config() function. Services and factories cannot be injected into .config(). The Angular docs have¬†a helpful table to explain that.

I needed the provider available in .config() so I could define my routes there and use the provider for the resolve objects.

So my provider needs to rely on $http and $route. The problem is that those are not defined at the .config() phase of a module. So I couldn’t define any provider functions that rely on those.

That is where the concept of $get comes in with providers. $get is processed by $injector.invoke() which allows $get to be a function with a dependency. Usually you see an array like this:

this.$get = ['$http', '$route', function($http, $route) { ...
    return this; // or any other object

So in .config() my provider can’t do anything with $http or $route, but it can queue up tasks that will be handled by $http and $route later. In my case when a route was fired.

So when I write a controller that relies on ApiProvider I access it as Api instead of ApiProvider. And the controller will receive the object returned by this.$get() so the provider is guaranteed to have those dependencies by then.

That was probably hard to follow but hopefully that helps someone.

Harder, Better, Faster, Stronger lodash v3

Try out lodash v3’s performance improvements and tons of new methods with easy upgrade path


lodash is a utility library delivering consistency, customization, performance & extras. It is also one the most dependent upon NPM packages.1 After a complete overhaul (over 800 commits since it has been bumped to v3.0.0-pre2), version 3 boosts increased performance and a whole lot of new features.

There is a lodash-migrate package that assists with migrating code from older lodash versions to the latest release.

Read more from the source: Gajus

Tagging content effectively

It seems like most people don’t understand tags very well. I’m not the best at tagging content effectively, but below¬†are some great principles.

  • The goals of effective content tagging:
    • Allow users to see the subject matter of the post before reading the body (Right Intel doesn’t facilitate this)
    • Allow users and editors to browse and search for content (In Right Intel you can search on the intel tab, email edit screen and story edit screen)
    • Allow search engines to properly index content (Not applicable in Right Intel)
    • Function like an index in the back of a book
  • Some principles of effective tagging
    • A tag should be specific yet likely to be used again
    • A good tag should be short, usually a word or two
    • Use between 2 and 4 tags per article
    • Consider that a tag may be a word that does not appear in the content
    • Use plurals only when appropriate
    • Use only letters, numbers, and spaces
    • Think about what text people might search for
    • Revise and merge your tags periodically
    • Codify tagging guidelines for all editors

Sources: The Next Web, Zemanta, NPR

And ironically, this post is not a great example of tagging because the subject matter is unusual for my blog. :)

Coding Horror: The God Login

A must read: Jeff Atwood researches and explains how to make your sign in and register process a smooth user experience


Jeff Atwood of Coding Horror writes:

And one of the coolest things my college professor Mr. Pausch ever taught me was to ask this question:

What’s the God algorithm for this?

Well, when sorting a list, obviously God wouldn’t bother with a stupid Bubble Sort or Quick Sort or Shell Sort like us mere mortals, God would just immediately place the items in the correct order. Bam. One step. The ultimate lower bound on computation, O(1). Not just fixed time, either, but literally one instantaneous step, because you’re freakin’ God.

This kind of blew my mind at the time.

So when we set out to build a login dialog for Discourse, I went back to what I learned in my Algorithms class and asked myself:

How would God build this login dialog?

Read more from the source:

Hands on course to learn ES6

With Traceur compiler and React’s JSX, now’s the time to learn ES6


Grow your expert full-stack JavaScript skills with tagtree screencast videos and tutorials.

With the advent of ES6, JavaScript has been launched into a proper modern language allowing us to develop elegant code. With a bunch of features that caters for OOP, better scope handling, alleviation of callback hell, and much more, you can’t afford to wait before skilling up and making it part of your projects.

Read more from the source: