Kohana: Buffering output on view and rendering it before in the source code

Sometimes you need to hack the order the source code is going to be rendered in a view:

– You want an extra piece of CSS that only aplies to that view, so you think it's not worth creating a single CSS file and including in your mashed file

– You need the same as above for javascript

– Your mind has not completely grasped the way to organize code in MVC  đŸ™‚



Here's a way to do it:


in your view you add something like this:

<?php View::start_buffer('head_end'); ?>
    ::-moz-selection {
        background: #b3d4fc;
        text-shadow: none;

<?php  View::end_buffer('head_end'); ?>


Then, by taking advantage of the wonderful cascading file system that Kohana gives you, you create a View.php class in your application folder that will need to extend the render() function (I'm just adding the relevant changes for this to work; you can have your own extra sauce):


class View extends Kohana_View
    static public $buffers = array();

    public static function start_buffer($buffer_name)
        self::$buffers[$buffer_name] = '';

    public static function end_buffer($buffer_name)
        self::$buffers[$buffer_name] = ob_get_clean();

    public function render($file = NULL)
        $rendered = parent::render($file);

        if (! empty(self::$buffers['head_end']))
            $rendered = str_replace('</head>', self::$buffers['head_end'] . '</head>', $rendered);
        return $rendered;



The buffer names are completely arbitrary, you can make them any way to want.

I leave up to you to improve the way each buffer will be mapped to different locations in the source code.

Drop me a line with your changes

mysql: Dumping single database table and restoring

Sometimes you need to dump a single table from a mysql table and restore it somewhere else. Here's what you need:


1. Dump the table (compress it so it will take shorter to transfer over the network)


mysqldump -h <HOST> -u <USERNAME> -p <DATABASE> <TABLE> | gzip > <DUMP_FILENAME>.gz


HOST is the hostname or IP address of the mysql server

USERNAME is a user with access to the database and table

DATABASE and TABLE are self explanatory

DUMP_FILE is the name you want for the file containing the compressed dump


2. Transfer the file where you need it to be, with "cp" or "scp"



cp <DUMP_FILENAME>.hz  folder/new_name

scp <DUMP_FILENAME>.hz  user@machine:folder



Linux: Some maintenance

Your linux distribution may run some maintenance jobs or checks daily and you may get things like the following in your email:


'<USERNAME>' is a member of the 'httpd' group in /etc/group but not in /etc/gshadow

The grpconv command creates gshadow from group and an optionally existing gshadow.


$ sudo grpconv



user 'jira': directory '/home/jira' does not exist

Simple create the folder and change its permissions:

$ sudo mkdir /home/jira
$ sudo chown jira:jira /home/jira -Rfv




  • IGlr