The Boy Scout Rule

I am reading a book titled "Clean Code". It was written by Robert C. Martin (aka Uncle Bob).
The goal of this book is to explain his method of writing clean code with concrete examples. It is very well written.

One thing I like about reading books like these is that they put words on things that I do or think. They express them in a way I did not think about.

Ruby/God/Dash and undead processes.

I have a god script that starts a process that I want to run.

My god config file contained: do |w| = "foobar"
  w.start = "rails runner 'SomeClass.SomeMethod'"

When god starts this, it starts TWO processes:

    sh -c rails runner "SomeClass.SomeMethod"

    rails runner "SomeClass.SomeMethod"

Send email with attachment from Ubuntu CLI

With the help of google, I've found a way to easily send an email that contains an attachment from the command line.

Usage: mail.attach "Here is your file" /tmp/somefile.txt

Create a file called mail.attach (or whatever you want) in your ~/bin/ folder and put this in it:


usage() {
    echo "Usage $0 SUBJECT TO FILE FROM"

if [ "$SUBJECT" = "" ]; then
    exit 1
if [ "$TO" = "" ]; then
    exit 1
if [ "$FILE" = "" ]; then

Je me suis désabonné de l'annuaire Pages Jaunes (un petit geste pour l'environnement)

Aujourd'hui, j'ai demander de ne plus recevoir d'annuaire de pages jaunes. J'utilise internet et l'application Pages Jaunes sur mon iPhone de toutes façon.

Faite-le vous aussi!

Removing extra whitespaces on bunch of PHP files using Ack-grep and Emacs

As a follow up to my own post on Indentations: Tabs vs. Spaces, I wanted to cleanup a number of files that contained a lot of extra and useless whitespaces that were getting on my nerves.

I did not want to spend too much time on this so, here is what I did.

First, here is what I have in my .emacs files that is needed for this to work:

(require 'whitespace)
(setq-default global-whitespace-mode t)
(setq-default whitespace-modes (quote (php-mode c-mode)))

Command cache-clear needs a higher bootstrap level to run

I created a new VMWare appliance for the project that I am working on. I deployed the project and created the DB and all that and when I was trying to access the site, it told me the site was offline. I decided to install DRUSH and clear the cache and see if I can find more information about this problem.

Once I installed drush, I got this error:

[roychri@p1695vm drupal]$ drush cc
Command cache-clear needs a higher bootstrap level to run - you will need invoke drush from a more functional[error]
Drupal environment to run this command.

... how the internet works

This is a great post about how the internet works. MUST READ :)

Because it is capable of describing the location of something anywhere in the world from anywhere in the world. It’s the foundation of the web. You can think of it like GPS coordinates for knowledge and information.

Install pear without network (no internet access/offline)

I was faced with a problem. I wanted to use drush on a server that had no internet access. Well, I could connect to it but it could not (for security reasons) connect to the outside world.

Drush requires PEAR's Console_Table and that in turns requires PEAR, obviously.

First I downloaded all the PEAR packages that I needed from my desktop and then I uploaded them to the server using SFTP. I could also have used a USB key if I had physical access to the server but that as not my case.

The files that I downloaded were the .tgz files that I found here:

Using Drush without json_decode/json_encode enabled.

Did you know that drush requires json support to be enabled in php?

Well, I did not until today.

Fatal error: Call to undefined function json_encode() in /home/drush/includes/ on line 380
Drush command terminated abnormally due to an unrecoverable error.
Error: Call to undefined function json_encode() in /home/drush/includes/, line 380

If you have root or if your in good terms with your sysadmin, the good solution would be to enable json to your php. Either recompile php or install json using pecl or using your distribution's package manager (yum, rpm, apt, whatever).

Well, I did not have root on that machine so here is what I did.
First I installed pear's Services_JSON package.
Second, I created a file called json.php with the following content found here:

if ( !function_exists('json_decode') ){
    function json_decode($content, $assoc=false){
                require_once 'Services/JSON.php';
                if ( $assoc ){
                    $json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
        } else {
                    $json = new Services_JSON;
        return $json->decode($content);

if ( !function_exists('json_encode') ){
    function json_encode($content){
                require_once 'Services/JSON.php';
                $json = new Services_JSON;
        return $json->encode($content);

Then I created a /.drush/ folder in my home directory and I created a file called php.ini inside that folder.

mkdir ~/.drush
emacs ~/.drush/php.ini

You can use vi if your one of those :)

I put the following inside the file:


where /path/to/ is the real path of where I put the json.php file above.

That was all and now I could use drush!

Help! Something is broken...

When you have access to a unix server and someone asks for help and you do not know about all the possible log files that exists, here is a command that will show you ALL opened file for append or write.

ulimit -n 9999 # In case there is more than 1024 files!
tail -vF $(/usr/bin/lsof -n | egrep -i '[[:digit:]]+(u|w).*reg' | awk '{print $9}')

Thanks Marius! :)

Syndicate content