FirePHP and Codeigniter 2

Working on a Codeigniter 2 Project right now I decided to give FirePHP a spin since it was pointed out to me for being somewhere around the next best thing to sliced bread for PHP Debugging… or something like that. It really seems nice so far I have to say!

Looking for some Codeigniter library but only finding a CI 1.7 one I decided to try to just drop in the provided code from the FirePHP site and guess what it just works. Download the FirePHPCore, currently 0.3.2, and unpack FirePHP.class.php to the Codeigniter application/libraries folder (I also renamed it to firephp.php as well). Now the library can be loaded either via adding it to the autoload.php as

$autoload['libraries'] = array('firephp');

or just load it when needed via

$this->load->library('firephp');

I prefer to autoload since I only load it in my development autoload.php anyway. Having different configs for development and production is as easy as setting up a directory structure like the following and just drop the configs in the environment folders.

Codeigniter Config Directory

Now it is time to install both Firebug and the Firefox FirePHP Plugin for Firefox 8+. Currently the latest FirePHP needs to be installed via the link since the one provided as stable via Addons is not working with Firebug 1.9. Get the latest from the FirePHP site or you will get an error.

Thats it! Now logging a message is as easy as

$this->firephp->log("FirePHP is working!");

FirePHP Log

Shrtr - Heroku, Redis, Node

Heroku provides node.js hosting for some time now and I didn’t have time to check it out, so yesterday I took some time and decided to write a quick app to check it out. You can find it as Shrtr its a URL shortener using Redis in the backend. So for anybody interested code is available on Github.

Clean configuration defaults via Object.create in Node.js

While recently coming back to clean up some Node.js module code I was looking for a nicer way to handle configuration of an object besides doing something like this to handle both configuration options and defaults.

var MyModule = function(opts){
  this.foo = opts.foo || 1;
  this.bar = opts.bar || 2;
  // the list goes on
}

In my opinion this code is not really readable, and defaults are not as obvious as I would like them to be. So I decided to let myself get inspired from jQuery which provides a nice way to handle settings and defaults in plugins, via $.extend(defaults, options) so my first Idea was to simple create an extend function in node, but since I would have to extend Object to make this as clean as possible I was looking for a way to handle this natively, and this is where Object.create comes in handy.

Object.create allows creating of an object based on some prototype as well as some default values, which is exactly what I was looking for. Do to the way Object.create handles properties the options need to be prepared before merging them in the configuration, which is finally bound to this.

var MyModule = function(opts){
  // some default values 
  var defaults = { foo: 1, bar: 2 };

  // prepare the options for Object.create
  var options = {};
  for(var i in opts){
    options[i] = { 
      value: opts[i], 
      enumerable: true, 
      writeable: true, 
      configurable: true } 
    };
  }

  // let Object.create merge the options with the defaults
  var config = Object.create(defaults, options);

  // bind to this
  for(var o in config){
    this[o] = config[o];
  }
}

Any suggestions for a different cleaner handling of configuration options are highly welcome.

EDIT: Fixed extra level of nesting in options thanks to Sami Samhuri

Filmspieler

Some time ago, me and a good friend of mine, Sebastian Weber decided to take up podcasting. At the time he was still working for PCGames, a german games magazine, and so there was not really the opportunity to do so. But now the time has come and we are now booth working together on recording out new Podcast “Filmspieler”. To get the “Film” part going, another really good friend of mine, Florian Negwer is contributing.

So whats this all about? It really is a project born from our love towards movies, games, and especially talking about those. We are not focusing on news but the stuff we are currently excited about even if it is older already.

All 3 of us are really excited to get this going, our first episode is currently out and we hope to continue in a 2 week rhythm, while writing articles on the webpage as well in between.

We’d love some feedback so check it out at “Filmspieler”.

BEWARE: Everything is in german.

Todo.txt syntax highlighter for Vim

As mentioned before I am a big fan of Gina Trapanis’ Todo.txt a command line todo list manager completely based around a bash script to manage a txt file. I already wrote a highlighter plus some basic commands as a plugin for TextMate which I now started to port for Vim. Currently the syntax highlight is working, the commands will follow. Stay tuned!

Scroll to top