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

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.

Nginx forward all requests to https

Since listening to Mike West and reading his posts I finally decided to really move all my stuff hosted on my own server to SSL. Certs are really not that expensive anymore (about 9$ per Year) and getting more IPs for my server was easier than expected (Whats up with IPv4 depletion aye?).

Since I want everything reachable with all the old links I decided to forward pretty much everything to the ssl host, to do this via Nginx the following little config should work, so I wanted to share since it was not as easy as expected to actually get everything running nicely. It forwards in this case http://example.com http://www.example.com https://www.example.com all to https://example.com.

https://gist.github.com/1337018.js

To make sure the clients will only use SSL from now on the server serving SSL should furthermore have ” add_header Strict-Transport-Security “max-age=31556926; includeSubdomains”; ” somewhere in the config.

Thats it… now to move over more stuff.

Hermes allows google to index the parcel tracking?

While waiting for my iPhone 4s today I received a message about my tracking status and so I was checking the Hermes tracking page. When it told me the status of my packet I was curious when it will arrive so I decided to google for that, and was kind of surprised what showed up…

why_hermes_one.png

Oh well so It seems like google is indexing the Hermes tracking system, you can even click it and view the links for another persons’ packages….

why_hermes_two.png

It’s actually not a big deal, I’m just confused why Hermes would allow google to index this. It’s not really useful for anybody and even though it is publicly available information feels kind of weird to have another persons delivery as the first google result.

Use a different single template per category in WordPress

In a recent WordPress project the posts are displayed on different pages differentiated by category instead of type. In this case different designs are loaded based on categories as well, since the theme needs to match the design of the current page. WordPress does not provide a build in mechanism to do this, it only does for post types.

The solution is rather simple, use the single.php file to first check the category and load the matching template. Since in my development environment the categories might match to different IDs than in the deployed instance it’s more practical to match by name instead of ID. Importantly first the category ID needs identification by name, and is stored to load the matching template, since matching via the $post variable can only be achieved via ID not name or slug. For anybody interested I put example code up on github.

https://gist.github.com/1272148.js