Coffeescript, EaselJS, and Greensock

by adrian on November 4, 2012

I started a new job a couple of weeks back with Blake Education making kids educational games. They have a nice framework under development for their HTML5 game development that automagically looks after a lot of things, like tying together Coffeescript, EaselJS, and Greensock. It’s nice working with their framework, but since I hadn’t used any of these techs, I wanted to start exploring them outside the framework to get a better understanding of they all play together.

It took a little bit of noodling to understand how they fit together. For future reference, here’s some simple code that has all three playing nice.


<!DOCTYPE html>
    <meta charset="UTF-8">
    <title>Easel 101</title>
      body { margin: 0px; padding: 10px; }
      #canvas { background: #CCC; }
    <script src="./js/lib/easeljs.js"></script>
    <script src="./js/lib/TweenMax.js"></script>
    <script src="./js/easel01.js"></script>
  <body onLoad="init();">
    <canvas id="canvas" width="700" height="40"></canvas>

Coffeescript with EaselJS and Greensock

class window.Test
  constructor: ->
    @stage = new createjs.Stage(document.getElementById 'canvas')
    @circle = {x: 10, y: 20, r: 10}, 2, {delay: 2, x: 500, y: 20, ease: Elastic.easeOut})
    createjs.Ticker.addListener @
  drawCircle: =>
    circle = new createjs.Shape()'#606').drawCircle(@circle.x, @circle.y, @circle.r)
  tick: ->
window.init = ->
  new Test()


Short post. Here’s the situation:

class Product < ActiveRecord::Base
  has_many :costs, :dependent => :destroy
  has_many :suppliers, :through => :costs

And I needed to find all Products that had no Suppliers entered. Not as easy as I thought. And I couldn’t find a native way to do it in Rails, so I ended up with raw SQL outer join. Here’s what worked:

Product.joins("LEFT OUTER JOIN costs ON = costs.product_id").where(costs: {id: nil})

Hope that saves someone some head scratching…


Serialized data and Rails validations

June 1, 2012

Today I went back to improve test coverage on an older app and fixed something that had eluded me the first time around. I was using RSpec and Factory Girl, and had user input which was serialized into arrays. I wanted the user to be able to enter data in a form, have the user […]

Read the full article →

RSpec tesing to_param

May 22, 2012

I’m working on improving test coverage on some of my legacy apps and adding new tests in all sort of places I missed the first time around. One thing I found quirky was testing the to_param method. I wanted to test the to_param method for a permalink: def to_param "#{self.permalink}" end So I wrote up […]

Read the full article →

Using Kapeli Dash to view class instance methods

May 18, 2012

Dash, by one man software shop Kapeli, is a nice little documentation browser and snippet manager for OSX. You can quickly look up methods by typing the method name in the little search field. But one thing that had me stumped for a bit was listing all available class instance┬ámethods. Now this software is very […]

Read the full article →

OSX, pushd, popd, and cd -

May 16, 2012

When I first started on this path I was a Windows user. Since my main interest was Rails, and the best Rails tools were all Mac based, I swapped over to Mac. One thing this has led to is that in addition to learning all the required web dev stuff, I also had to learn […]

Read the full article →

Ruby array uniq

May 13, 2012

Quick post tonight, cause it’s Sunday and late. Used a new standard object method today, and it’s kind of cute. Array#uniq returns a new array containing only the distinct members of an array – dropping any duplicate members. a = [’a', ‘b’, ‘c’, ‘d’, ‘d’, ‘e’, ‘f’, ‘g’, ‘g’, ‘g’, ‘h’]   puts a.to_s # […]

Read the full article →

Ruby environmental global variables

May 12, 2012

Came across this little snippet today $*[0] After a bit of digging, I found out it means almost the same as ARGV[0] I say almost because, while I can’t find a practical difference, they are actually different types of objects. [Desktop]$ irb 1.9.3-p125 :001 > defined? $* => "global-variable" 1.9.3-p125 :002 > defined? ARGV => […]

Read the full article →

Tinkerbin, like JSfiddle with SASS, HAML, and Coffeescript

May 11, 2012

I came across tinkerbin yesterday. It’s kind of a simplified version of JSfiddle. Simplified as in a simpler interface. Kind of as in, but it also supports SASS, HAML, and Coffeescript. SASS and HAML I totally get, though personally I don’t like HAML. But Coffeescript seems strange to me in this environment.┬áThere is no option […]

Read the full article →

Method chaining and DRY

May 10, 2012

One long time conceptual issue I have had is how to reconcile DRY (Don’t Repeat Yourself) with method chaining being a code smell. For instance, say I have a facebook credit transaction that stores an orderID and a user ID with the transaction record. When I do a transaction, I receive an AJAX message back […]

Read the full article →