Category Archives: Viget

A Google Analytics Dashboard for Front-End Developers

Say you’re a front-end developer who is building a great new website. As you plan out your platform and resources, you probably have some questions about how people are using the existing website so you can prioritize important features and make sure your new site works well for everyone. Data like common devices and screen sizes are very useful for this and can be collected by most analytics platforms, including Google Analytics. Data from Google Analytics is useful after launch, as well: with the proper setup, you can track data like page load times, JavaScript errors, and common input methods.

read more

Get Lazy with Custom Enumerators

Ruby 2.0 added the ability to create custom enumerators and they are bad ass. I tend to group lazy evaluation with things like pattern matching and currying – super cool but not directly applicable to our day-to-day work. I recently had the chance to use a custom enumerator to clean up some hairy business logic, though, and I thought I’d share.

Some background: our client had originally requested the ability to select two related places to display at the bottom of a given place detail page, one of the primary pages in our app. Over time, they found that content editors were not always diligent about selecting these related places, often choosing only one or none. They requested that two related places always display, using the following logic:

  1. If the place has published, associated places, use those;
  2. Otherwise, if there are nearby places, use those;
  3. Otherwise, use the most recently updated places.

Straightforward enough. An early, naïve approach:

def associated_places
    (associated_place_1 if associated_place_1.try(:published?)),
    (associated_place_2 if associated_place_2.try(:published?)),

But if a place does have two associated places, we don’t want to perform the expensive call to nearby_places, and similarly, if it has nearby places, we’d like to avoid calling recently_updated_places. We also don’t want to litter the method with conditional logic. This is a perfect opportunity to build a custom enumerator:

def associated_places do |y|
    y << associated_place_1 if associated_place_1.try(:published?)
    y << associated_place_2 if associated_place_2.try(:published?)
    nearby_places.each { |place| y << place }
    recently_updated_places.each { |place| y << place }

read more

Naming My Tech Values

When you think about technology, what matters to you? Not to your company, or to the industry, and certainly not to the media. But to you, as an individual who works and builds on the web—what do you value?

In its current state, the web is overflowing with ideas. Everyone has a voice and the collective conversation is loud, noisy, and often conflicting. Filtering it, identifying the ideas worth believing, is the ultimate challenge. For me, doing so requires naming what I value and what I don't.

read more