I'm a Floridian web engineer who planted his roots in Paris. Some of my favorite past-times are analyzing and optimizing development processes, building solid APIs, mentoring junior devs, and long walks on the beach.

Make Backspace Reverse Chrome History 02-03-2011

Where's the love?

Can Nodejs be Used to Make a Website? 01-11-2011

Derp. Yes. So this week I got the chance to play around with nodejs. I was using expressjs, sequelizejs and some other libraries all via npm. It was all very familiar feeling coming from a rails background. npm works pretty much like ruby's gem package manager.

Expressjs

Expressjs has a boat load of features that you would come to expect from any web framework. It comes with a templating system. Currently, it supports haml, ejs, jade, and jQuery templates. Personally, I'm a pretty big fan of haml and because of which jade also seems pretty nice. It deals with routing by associating a path to http request verbs. This is pretty standard if you've ever used something like sinatra. Here is an example:

  app.get('/', function(req, res){
    you gotta do some stuff here
  });

It also offers a pretty straight-forward way of configuring your application:

  app.configure('development', function(){
      // executed for 'development' only
  });

Sequelizejs

Sequelizejs is a nice orm library. I have a few minor complaints about it. For one, the query data is manipulated via a callback. So for instance, the following is not kosher:

people = Person.findAll({where: "name = 'Francis' or name = 'Jeff'"});
people[0].some_cool_method();

instead you would do the following:

Person.findAll({where: "name = 'Francis' or name = 'Jeff'"},function(people){ people[0].some_cool_method(); });

I suppose this is fine if your'e happy doing things this way but I for one, do not appreciate being forced to work within the constraints of a callback.

In the end, there's definately enough features to go around for anyone who would actually want to make an entire application in javascript. For anyone who wouldn't want to make an entire app in javascript, at least playing around with nodejs is a way to hone your skills in working with it. I've found that working with nodejs has done at least that.

Coming soon: Should nodejs be used to make a website?

Tags: nodejs

Rails 3 Routing: Use match in a Block 12-19-2010

I was trying to set up an easy route that would let me use the following url: "posts/tags/:tagname". As I was playing around I realized that you can use match inside of a block. More importantly you can also give it a path name so that it can be easily referred to. Here is what I did:


  resources :posts do
    collection do
      get 'display'
      match ":name", :to => "posts#tags", :as => 'by_tag_name'
    end
  end

This is nice because in my code I can now call:

=linkto name, bytagnameposts_path(:name => name)

Tags: routes Rails

Finding out if data has changed Rails uses changed? 12-14-2010

Unfortunately, tainted? doesn't seem to work for activerecord objects.

Tags: Rails

Javascript Should Have a groups_of Function 12-04-2010

I forget why, but there was a certain point in time where I thought that javascript should have a getgroupsof function. So here is a quick and easy implementation that will roll through an array and grab elements in groups of n. Anywho, now you can enjoy countless hours of grabbing things, n at a time, yippeee!

function get_group_of(limit,array){
    group = Array();
    while(limit-- > 0){ 
        if(value = array.shift()){
            group.push(value);
        }
    }
    return group.length > 0? group: false;
}

stuff = new Array();
for(i=0; i<1000; i++){ stuff.push(i); }
final_group=Array();

while(group=get_group_of(3,stuff)){
    for(letter in group){
        final_group.push(letter);
    }
    final_group.push('===next group====');
}
console.log(final_group)
Tags: javascript