Skip to main content

Posts

Opal - Ruby to JavaScript compiler

So I just found out about the Opal Ruby to JavaScript compiler and I am very intrigued. http://opalrb.org/ So for a few years now, the Ruby community has been encouraged to use CoffeeScript as a JavaScript "alternative" ( http://coffeescript.org/ ) but for some reason, as an avid JavaScript programmer, it never appealed to me. CoffeeScript offers a small amount of syntactic sugar on top of JavaScript, but it never seemed worth the learning curve for me to take it on. I don't actually mind JS's brackets (as they let you know where things begin and end cleanly) and significant white space in a programming language has always seemed like a bad idea too (it's bad enough that a misplaced semicolon can stop a program from running properly, but try searching for an extra white space character you can't even see!). Opal on the other hand, is actually Ruby compiled to JavaScript (not Ruby/Python-ish syntax). It looks, feels, and even smells like Ruby because it i...

Checking performance in EaselJS apps

So one of the great things about EaselJS  is the fact that you can create Flash like games in JavaScript. I have been doing so on www.activememory.com for the last couple of years. Unfortunately, it came to our attention that on some systems, the games ran rather slowly. According to their own docs, they admit that the time between ticks might be greater than specified because of CPU load ( http://www.createjs.com/Docs/EaselJS/classes/Ticker.html#method_setInterval ). So, is there any way we can track the actual time between ticks on a real system? Fortunately, yes, we can. On each element that uses the ticker, you can set up an addEventListener and set the method you want to fire on that interval. createjs.Ticker.addEventListener('tick', tickListener); In the method itself you will want a few instance (or global) variables this.previousFrameTime this.totalFrames this.totalFrameTimes as well as a local variable currentFrameTime On each tick, we get the cu...

Our git workflow

In my current gig in ABC Active Memory ( https://activememory.com/ ) we have put together a git workflow which works really well for us, so I decided I would write about it here so that others could benefit. The things you need to have in place though are Continuous Deployment ( http://en.wikipedia.org/wiki/Continuous_delivery ), Test Driven Development ( http://en.wikipedia.org/wiki/Test-driven_development ), Agile ( http://en.wikipedia.org/wiki/Agile_software_development ) and the desire to keep releasing small independent incremental features without any one of them blocking each other. Branches So the key is branches (obviously). We have 2 main branches which are shared by everyone, and every new feature takes place in a feature branch.  Our 2 shared branches are  acceptance master Feature branch When we start a new feature, we do all the work in our feature branch which we cut from  master . Our feature branches are named by ticket number (i.e...

IE console.log(). It works, except when it doesn't...

So I made an interesting discovery today. console.log() in IE9 only works when the console is open! As a web developer, and especially a JavaScript developer, the most useful tool in your arsenal is console.log() . And while you should (for the most part) remove any console.log() calls from your code as soon as you have finished debugging, sometimes your library code might contain it, or other times if you are writing a framework for an intermediary to use, you might leave a couple of messages for your intermediaries using console.log() . console.log() first made an appearance in Firefox's Firebug (or at least that is when I first noticed it) and has been in most major browsers, including Internet Explorer since version 8. Whilst developing, I have happily had my console open so I can debug things. Anyways, fast forward to the current app I am working on. I am lucky enough to be working on a project that uses HTML5 canvas and the project I am working on is used by a game...

Screen scraping with Nokogiri

So a few months ago I put together a side project at  http://www.myrecipesavour.com/  . Basically, the site allows you to put in the URL of a cooking recipe page and will then parse the recipe for your collection. So it turns out, reading data from another site is very easy with Nokogiri. The source code is available here  https://github.com/abreckner/MyRecipeSavour There is a lot I am going to cover in the next few posts based on this code base (like Devise and Heroku), but for now we are focussed on this file  https://github.com/abreckner/MyRecipeSavour/blob/master/app/models/site.rb So we are going to look at the add_recipe method. First we need to require a few packages require 'open-uri' require 'rubygems' require 'nokogiri' Unfortunately, I haven't yet figured out a heuristic for separating a recipe web page into a recipe's components (Title, Ingredients, Instructions, Amounts, etc...) but as a workaround, I maintain a catalo...

How DRY is too DRY?

One of the earliest development principles we learn as programmers is Do not Repeat Yourself or DRY for short. Copy and Paste are supposedly your worst enemies. Rather than rely on copy and paste, you create functions and subroutines and call them from your code so you don't have to reimplement it continuously. It also has the added advantage that if you need to make a change to that subroutine, you only need to make that change once. (Note: I realize that functions and subroutines are different entities, but for the purpose of this article they are interchangeable). Sometimes you come across 2 pieces of functionality which are very similar, so instead of copying and pasting, you merely instantiate your function/subroutine with different variables to factor out/handle the differences, even where the core functionality is the same. For example, you might have a Customer object and a Vendor object. Both customers and vendors have addresses and you need to send mail to them both...