About Us

Bulletpoint StarImulus® is a technology focused design + interactive agency.

In addition to our client services we also have a few products in the works. Our office is always filled with chatter and this blog is an outlet for our creative energy, rants and ideas.

Podium

Stacks!
Imulus built a task management solution that finally works for teams. It's a life saver, learn more at usestacks.com.

Featured Project

Category: JavaScript

Jan5

Support Details on Rails

We here at Imulus have spread our wings a bit and decided to get into the Rails game. I have had a crush on Ruby for a long time, causing me to jump on the Rails bandwagon when version 1.0 was in beta. I fell off the wagon before Rails 2 came out, being consumed by development work that wasn’t on the web. When Rails 3 and then Rails 3.1 came out with great support for unobtrusive javascript as well as the asset pipeline, several of us started to get involved again.

We’ve been wanting to continue work on Support Details for some time now. Since it was in .NET sitting on top of a homegrown CMS that it really didn’t need to be coupled to, our frontend developers had trouble moving forward on it. As a lark, I decided to port over the site to Rails. The main functionality was done in a couple of hours and we managed to iron out most of the other main points in spare hours over the next few days. We decided to update some of our detection to be way more accurate, and that took a few more days, but we can now tell if you are on Windows 3.1 running NCSA Mosaic

We didn’t want to stop there though. We were very excited about using CoffeeScript and Sass in the new Rails 3.1 asset pipeline to create readable code that could generate our Javascript and CSS. Taylor and Casey jumped onto migrating the existing Javascript and CSS over to using CoffeeScript and Sass. After running through the asset pipeline which would combine and minify our Javascript and CSS we had significantly reduced our asset download size.

While that was a great first step, we wanted to go further and make Support Details even faster. We started by using Delayed Job to send e-mails on a background queue, rather than tying up the main web thread. Then we decided that we wanted to take advantage of a CDN and so we used the excellent Asset Sync gem to compile and deploy our assets to Amazon S3/Cloudfront when we pushed to Heroku. After all of these changes our initial page load time was cut by more that half.

But wait, there’s more. We’ve had many requests to localize Support Details for different languages. Thanks to the support of various friends of Imulus, we are pleased to offer Support Details in Japanese, Russian, Italian and Portuguese. We plan on adding more languages in the future, and if you want to help in translation please feel free to give us a holler and we can send you a list of phrases we need for the translation.

We have a lot more planned for Support Details, and we have some more great Rails applications in the pipeline which we should be releasing for your viewing pleasure in the near future.

Dec1

Powder: A Backbone-powered iPad webapp

Powder screenshot

Winter is upon us, and like many folks in Colorado we’re stoked to hit the mountains. Given the recent snowfall and our experimentation with HTML5 localStorage, it seemed natural to push it a bit further and do something fun.

Enter Powder, an HTML5 webapp for tracking the snow conditions at your favorite ski resorts.

Powder is an experiment using backbone.js to power an iPad webapp. On the client, Powder uses the browser’s native HTML5 localStorage mechanism to save the users’s preferences, the list of resorts the user chooses to track. On the server, Powder uses Sinatra to fetch and parse various snow/ski reports from http://onthesnow.com/ then serve it up as JSON to the browser.

The Stack

Powder is free and open source, hosted on GitHub. We’d love to have you join us in making Powder better. Feel free to fork the project and help us make a kickass iPad webapp.

Oct12

Using SublimeVideo HTML5 video with generated HTML

Recently we pushed a massive update to Stacks, our group task management solution. Part of this update was reworking the onboarding and help process for users — instead of using totally separate pages we moved to a simple lightbox solution that could be loaded on any page. This allowed us to show a lightbox whenever it was requested programmatically or by the user. For additional flexibility (and to save loading time) we made the lightbox ajax in whatever HTML content was needed. This process works great, but it did cause a few issues with our recently implemented HTML5 video script, SublimeVideo.

lightboxed

A few words about SublimeVideo

SublimeVideo is not video hosting platform like Wistia, Vimeo, or Ooyala, instead it’s just a javascript player that makes populating already-hosted videos incredibly easy. On most sites you simply include the javascript snippet provided by SublimeVideo and add a class to your video elements that calls the script, like so:

<video class="sublime zoom" width="1026" height="572" ⌉
preload="none">
	<source src="http://site.com/video.mp4"/>
	<source src="http://site.com/video.ogg"/>
</video>

This will immediately replace all of the video elements with a beautiful HTML5 player and Flash fallback for browsers that either, don’t support HTML5 video, or don’t support that particular video format. For most day-to-day scenarios this is perfect and is by far the easiest solution I’ve seen.

The Catch

SublimeVideo’s script works by looking at the source once loaded, grabbing all of the video elements, and then applying the player to those elements. However, with the Stacks lightbox solution the video elements are being loaded only after the lightbox gets ajaxed, therefore they aren’t available via the initial DOM load. This means that playing videos within the generated HTML won’t work. It also means the sublimevideo video lightbox won’t work either.

Basically SublimeVideo has two object states. First, when the script is loaded without video being detected and is waiting to be called. Second, once the object has been told there is video on the page to work with. See the states below:

object-instances

The Solution

In order to get the sublime video object to run we need to load it under a document.ready function, SublimeVideo supposedly has a sublimevideo.ready function that is more accurate than document.ready but it doesn’t seem to work. Instead, use the following method to load up the sublime object when no video lives on the page:

<script src="/link/to/sublimevideo.js"></script>
<script>
	$(document).ready(function() {
		sublimevideo.load();
	});
</script>

Then, when the lightbox (or generated HTML) appears you’ll need to associate each video with the sublimevideo object (remember, it doesn’t know these new video calls even exist):

<script>
	$('video.sublime').each(function(){
	    sublimevideo.prepare($(this).el);
	});
</script>

The above method will grab all the video elements with a class of ’sublime’ and push them to the sublimevideo object for preparation. That’s it, now the generated HTML will re-associate all videos and work with the player properly.

Sep21

ClickTime API Wrappers for Ruby and JavaScript

For a few internal projects at the Imulus office, we’ve been collecting timesheet data from the tracking software we use, ClickTime. Lucky for us, they offer an API with full access to all of our data. Unfortunately, however, it’s a SOAP API.

SOAP can be a bear, so we’ve rolled some code to help alleviate the pain of working with it:
a Ruby wrapper and a JavaScript wrapper. Both are open source, and we hope they make your life easier. Below are some examples of how to use them.

Ruby

The Ruby wrapper (ruby-clicktime) comes in the form of a single file with one class, ClickTime.

Requirements

ruby-clicktime uses Savon, so be sure to install that first:

$ gem install savon

Usage

The ClickTime class has two methods:

ClickTime#actions will return a list of all actions available to the ClickTime SOAP API

clicktime.actions  # un_sync_all, get_sync_id, set_sync_id, ...

ClickTime#exec will execute an API call and return a hash of results

clicktime.exec :api_action, {params}

Example

First, create an instance of the ClickTime class:

require 'clicktime'

clicktime = ClickTime.new :key => 'api-key', :password => 'password'

The GetEmployeeList and GetClientList API methods, as defined in the ClickTime API docs:

<GetEmployeeList xmlns="http://clicktime.com/webservices/2.2/">
	<UserID>string</UserID>
	<ActiveOnly>boolean</ActiveOnly>
</GetEmployeeList>

<GetClientList xmlns="http://clicktime.com/webservices/2.2/">
	<UserID>string</UserID>
</GetClientList>

To execute these queries, you would call the following:

employees = clicktime.exec :get_employee_list,
    {"UserID" => 'your-user-id', "ActiveOnly" => 'true'}
clients = clicktime.exec :get_client_list, {"UserID" => 'your-user-id'}

Notice the action is passed as a snake_case symbol from the list of available actions. (clicktime.actions to list them)

JavaScript

The JavaScript wrapper is a CommonJS module, ready for use in your Node.js project via npm.

Installation

In your project:

$ npm install clicktime

And in your script:

var ClickTime = require('clicktime');

Example

First, create an instance of the ClickTime object:

var clicktime = new ClickTime({
  key: 'your-api-key',
  password: 'your-api-password'
});

The GetEmployeeList API method, as defined in the ClickTime API docs:

<GetEmployeeList xmlns="http://clicktime.com/webservices/2.2/">
  <UserID>string</UserID>
  <ActiveOnly>boolean</ActiveOnly>
</GetEmployeeList>

To execute this query you would call the following:

clicktime.exec('GetEmployeeList', {
    UserID: 'some-user-id',
    ActiveOnly: true
  }, function(response){ // your callback function
    console.log(response);
  }
);

Reference

Source code:
ruby-clicktime on GitHub
node-clicktime on GitHub

ClickTime SOAP API Documentation:
http://app.clicktime.com/documentation/webservices/2_2/WebServicesDocumentation_2_2.asp

Jun18

CoffeeScript: Namespaces, Modules and Inheritance

First, some JavaScript background.

Skip to the good stuff

Here at Imulus, we like to namespace our JavaScript by wrapping our classes in static modules. We accomplish this by simply creating an object literal with a variety of members: classes (constructors), constants, variables and static methods.

Here is a pared down example of a simple module:

var Application = {           // the module, a static wrapper

 FXSPEED : 500,               // a constant (sort of)

 user : {                     // a nested static object
   id : 123
 },

 toggle : function(){ ... },  // a static method

 Interface : function(){      // a class

   this.initialize = function(){
     this.active = true;
     this.build();
     return this;
   }

   this.build = function(){
     ...
   }

   this.doSomething = function(){
     return "did something";
   }

   return this.initialize();
 }  

}

The benefits of this technique are obvious; it allows us to have loosely-coupled, modular code that is nicely organized, available without instantiation and protects the global namespace from pollution.

Application.active // true

Application.user.id // 123

var interface = new Application.Interface()
interface.doSomething() // 'did something'

In reality, however, one mammoth object literal in a single file is a lousy way to structure your code. Instead, what we do is organize module members into separate files in a logical fashion, å la Ruby. The module and all of its static members exist in a single file named after the module, and all of the module’s classes exist in a directory named after the module with each class file named after itself without the namespace. By using this structure, files are much easier to find because the naming convention mirrors the the module namespace.

The directory structure ends up looking like this:

|-- scripts
    |-- application.js
    |-- application
        |-- controller.js
        |-- data.js
        |-- interface.js

And the module above would be structured like this:

// scripts/application.js
// creates the wrapper module and contains all static members

var Application = Application || {
  FXSPEED : 500,
  user : {
    id : 123
  },
 toggle : function(){ ... },
}
// scripts/application/interface.js

Application.Interface = function(){
  this.initialize = function(){
    this.active = true;
    this.build();
    return this;
  }

  this.build = function(){
    ...
  }

  this.doSomething = function(){
    return "did something";
  }

  return this.initialize();
}
// scripts/application/controller.js

Application.Controller = function(){
  ...
}

You get the picture. This probably looks familiar to a Rubyist. Here’s the analog:

|-- lib
    |-- application.rb
    |-- application
        |-- interface.rb
# application.rb

module Application
 FXSPEED : 500,             

 def self.user
  { 'id' => 123 }
 end

 def self.toggle
  ...
 end
end
# application/interface.rb

module Application
  class Interface

    attr_accessor :active

    def initialize
      @active = true
      build
    end

    def build
      ...
    end

    def do_something
      'did something'
    end
  end
end

Snakes on a Train

By now it’s probably evident how much we obsess over code structure, organization and namespacing. While experimenting with CoffeeScript, this has been an ongoing concern.

This is the example from the CoffeeScript demo page:

class Animal
  constructor: (@name) ->

  move: (meters) ->
    alert @name + " moved " + meters + "m."

class Snake extends Animal
  move: ->
    alert "Slithering..."
    super 5

class Horse extends Animal
  move: ->
    alert "Galloping..."
    super 45

sam = new Snake "Sammy the Python"
tom = new Horse "Tommy the Palomino"

sam.move()
tom.move()

I love that Coffee has made dealing with prototypes much easier with the ‘class’ and ‘extends’ keywords. This is great, and by itself works like a charm for singular, somewhat global classes. However, for any application with a sizeable codebase this simply isn’t practical without ending up with insane class names.

The ideal solution would be to introduce a ‘module’ keyword similar to Ruby’s.

module Zoo
  class Animal
    constructor: (@name) ->

    move: (meters) ->
      alert @name + " moved " + meters + "m."

bob = new Zoo::Animal "Bob the Bird"
bob.move()

Other people agree. But there are a number of JS limitations that prevent this from being a viable solution in CoffeeScript.

The Really Good Stuff

By its own golden rule, CoffeeScript is: “It’s just JavaScript”. So, we can namespace our CoffeeScript classes in the same manner we organize our modules in vanilla JS.

Extending on the example above (ha-ha, get it?), I’ll demonstrate how to namespace your Coffee classes in a simple, elegant way.

Focusing only on the snakes for now, lets set up our basic classes.

class Animal
  constructor: (@name) ->

  move: (meters) ->
    console.log @name + " moved " + meters + "m."

class Snake extends Animal
  move: ->
    super 5

george = new Snake "George"
george.move() // George moved 5m

Now, we want to create ‘Forest’ and ‘Savanna’ modules that have a habitat and snakes of their own.

animal-diagram

Just like JavaScript, we could wrap all of the module members in an object literal:

Forest =
  habitat: "dense highland dotted with lakes and streams"
  Snake: class extends Snake
    move: ->
      super 10

george = new Forest.Snake "George"
george.move() // George moved 5m.

But we would run into the same problem when the codebase reaches any kind of scale: enormous, single-file object literals. So let’s introduce a new function for creating module members.

module = (name) ->
  global[name] = global[name] or {}

(Yes, I am aware that this is attaching the objects to the global namespace. This is what we want. It allows us to add members to the module later.)

Now we can use the ‘module’ function like this:

module 'Forest'

Forest.habitat = "dense highland dotted with lakes and streams"

Forest.Snake = class extends Snake
 move: ->
   super 10

george = new Forest.Snake "George"
george.move() // George moved 10m.

Pretty elegant, right? Additionally, by using the ‘module’ function we can now organize our code into multiple files:

module = (name) ->
  global[name] = global[name] or {}

# src/animals.coffee
class Animal
  constructor: (@name) ->

  move: (meters) ->
    console.log @name + " moved " + meters + "m."

class Snake extends Animal
  move: (meters) ->
    super meters

# src/forest/snake.coffee
module 'Forest'

Forest.habitat = "dense highland dotted with lakes and streams"

Forest.Snake = class extends Snake
  move: (meters)->
    @distance = meters || 5
    super @distance

# src/savanna/snake.coffee
module 'Savanna'

Savanna.habitat = "grassy woodland small or widely spaced trees"

Savanna.Snake = class extends Snake
  move: (meters)->
    @distance = meters || 10
    super @distance

george = new Forest.Snake "George"
george.move() // George moved 5m

scott = new Savanna.Snake "Scott"
scott.move() // Scott moved 10m

We can also extend standalone classes with module classes:

class Python extends Savanna.Snake
  constructor: ->
    super
    console.log "I am #{@name} the python."
    console.log "I live in the savanna,
    where it is #{Savanna.habitat}."

class Cobra extends Forest.Snake
  constructor: ->
    super
    console.log "I am #{@name} the cobra."
    console.log "I live in the Forest,
      where it is #{Forest.habitat}."

john = new Python "John"
// I am John the python.
// I live in the savanna,
// where it is grassy woodland small or widely spaced trees.

bruce = new Cobra "Bruce"
// I am Bruce the cobra.
// I live in the forest,
// where it is dense highland dotted with lakes and streams.