JS1K

Posted February 3rd, 2012 by guidone with No Comments

A little amarcord here: who remembers the “demos”? Those little masterpieces for Amiga competing for the smallest size combined with the most awesome graphical effect?

Well, they’re back, this time using just 1026 bytes of JavaScript and the canvas object. Check this out: http://js1k.com/.

A Javascript manager and build tool

Posted January 31st, 2012 by guidone with No Comments

I was playing around with Jake last days and I came up with an idea for a tool to create a piece of code to handle seamlessly the the various JavaScript libraries in a HTML page with NodeJS and the check/compress/build procedure to release the whole package in production.

I’m still working on the idea, probably it will end up in something with a little bit of conventions for the structure of the files, but these are the key points I really need for this tool:

  • Be able to work with AMD modules and simple JavaScript files at the same time (without converting them to AMD module format)
  • Full support to AMD and module dependencies
  • A unique file to define which JS files and modules to load for each page, used to render the page and build the release package for production (no more manually updating of the build script)
  • Paths mapping for easily switch JavaScript library version (or to point the static resource to a CDN)
  • Check the files against JSHint before building (damn comma in array!)

Tiny little JavaScript polling object

Posted December 10th, 2011 by guidone with 3 Comments

Few days I came across this situation where I had to check, at predefined interval, against a remote server for some conditions. So just for not having the setTimeout and setInterval ids hanging around my code, I wrapped everyting in a small JavaScript object Poller.

It’s pretty simple: just configure any number of intervals, a callback in case of success, a callback in case of failure, and the function that checks the server

var poller = new Poller();
poller
   .intervals([1000,5000,10000])
   .checkback(function(callback) {
      // could be anything asynchronous
      $.getJSON('/is/server/ready',function(response) {
         if (response.ready)
            callback(true);
         else callback(false);
         }
      })
   .callback(function() {
      // checkback succeded and the end of one interval
      // stops the poller and callback
      console.log('Ok')
      })
   .failback(function() {
      // after the third attempt, exits calling the failback
      // function
      console.log('Failed');
      })
   .start(); // start the process

Each callback(), failback(), checkback() run in the Poller context, means that this operator points to the Poller instance.
A bunch of additional methods are available like: start(), stop(), restart(), next().

To do: implement Deferred pattern for the method that checks the server

Update: Update with a GitHub repository and support for deferred/promise.

  • Categories

  • Tags

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 2 other subscribers

  • Twitter

    Flickr Stream