Strange Symphonies The whole is greater than the sum of its parts

7Feb/090

Making FirePHP Accessible to Every PHP Page

I heart FireBug. I loved FireBug so much, I even made a simple Ruby on Rails plugin to log to FireBug, called FireBug Logger.

It was rudimentary, but it did its job. Lucky for me, a similar project exists in the PHP world, appropriately labelled FirePHP.

FirePHP

FirePHP is bit fancier, in that it can format the output that is sent to the FireBug console. But because of this feature, it requires to be installed as a Firefox extension.

This post will not discuss on the benefits of using FirePHP, or how to install it. There are lots more material available out there on that.

Making FirePHP Easily Accessible

Sadly to get FirePHP available to every PHP script, you are required to call the code to load FirePHP (fb.php). But this is not necessarily true.

In your php.ini, there is an option called auto_prepend_file which will automatically include a PHP file before executing the requested PHP file.

So with this can call load FirePHP prior to any execution, and thus making it accessible via any script that is executed.

Lets enable the auto_prepend_file and give it a value to another PHP file.

auto_prepend_file = /Users/aizat/src/firephp/firephp.php

Don't forget to restart your Apache, else your changes won't be applied!

Now inside /Users/aizat/src/firephp/firephp.php, I will require the main FirePHP library like so:

<?php

require_once('lib/FirePHPCore/fb.php');

if (php_sapi_name() != 'cli' &amp;&amp; ini_get('output_buffering') == false) {
    ob_start();
}?>

Make sure that the require_once on line 3 points to the location of the fb.php.
require_once('lib/FirePHPCore/fb.php');

Testing

Now lets test it with a very simple file. Create a php file and dump this inside:

<?php
fb("auto_prepend_file successfully worked!", FirePHP::LOG);
?>

Open the file in your web browser, and it should load successfully!

There you have it, easy debugging without manually requiring the FirePHP libraries, and accessible in all PHP files. What more do you want?

7Feb/090

Bookmarking Directories in Bash

Well not in the same sense as bookmarking in your web browsers. But what it does do is make it easy to jump to the many directories that you may commonly visit.

[block:important]I'm no pro at bash, but this is a simple solution I came up with and thought others may benefit from it.[/block]

Some directories I would may occasionally visit:

  • /opt/local/lib/ruby/gems/1.8/gems/
  • /Users/aizat/src/projectA
  • /User/aizat/src/companyB/projectC
  • /User/aizat/src/companyB/projectD

I may use the bash expansion ~/ to easily go to my home directory, but I'm still rather limited in what I can access.

So here is a simple gem you can place in either your ~/.bashrc, or ~/.bash_profile
[block:file]

function bookmark {
  case "$1" in
    projectA)  pushd /Users/aizat/src/projectA ;;
    projectC)  pushd /Users/aizat/src/companyB/projectC ;;
    projectD)  pushd /Users/aizat/src/companyB/projectD ;;
    gems)      pushd /opt/local/lib/ruby/gems/1.8/gems ;;
    *)           echo "forgot something?" ;;
  esac
}

[/block]

Replace as required with your own directories, but don't remove the line with the asterisk!

Before you start using the function, you have to either start a new bash session, terminal, or execute source ~/.bash_profile. Which ever fancies you.

So in your bash session, try it out.
[block:terminal]
bookmark projectA
bookmark gems
bookmark projectC
bookmark projectB
[/block]

Now you can easily jump directories in convenience! But wait, oops! Did you accidently go to the wrong project? Want to easily go back to your previous directory? No problem. Since we used pushd, its as easy as a popd away!

Don't forget tab completion, so you don't have to type the code bookmark command!

[block:important]Know something even more convenient? Do share![/block]

Tagged as: No Comments
6Feb/090

Conveniently Resizing mvim to Fullscreen and Halfscreen

While doing development on my MacBook, thanks to its widescreen I like to keep two terminals open side by side, or two mvim (thats vim for Mac OS X), or some combination of the two. Whatever it is, its two windows side by side.

Rather than continually manually resizing the window myself, which can be a chore I have created a two simple functions to do it for me.

Plug this into your ~/.gvimrc [image16x16:file]:
[block:file]
function Fullscreen()
set columns=187
endfunction
command! Fullscreen :call Fullscreen()

function Halfscreen()
set columns=87
endfunction
command! Halfscreen :call Halfscreen()
[/block]

Now with mvim all fired, up just enter :Fullscreen or :Halfscreen, and BAM! Don't forget to use tab completion so you don't have to type the whole command!

Defaulting to Halfscreen on Open

When I open up mvim, I want it to be Halfscreen by default.

Lucky for me, it is as simple as putting this in to my ~/.gvimrc [image16x16:file]:
[block:file]set columns=87[/block]

[block:important]This is all on the default resolution of 1280x800[/block]