Let your MySQL partition breathe

Today I noticed my MySQL partition was taking over 86 GB of the available 120 GB. So I got worried and I wrote this little script to tell me how much space each DB I have is taking:

function format($size) {
	$unit = 'B';
	$units = array(
		'GB' => 1024 * 1024 * 1024
		, 'MB' => 1024 * 1024
		, 'KB' => 1024

	foreach($units as $currentUnit => $value) {
		if ($size > 2 * $value) {
			$size /= $value;
			$unit = $currentUnit;
	return number_format($size, 1) . ' ' . $unit;

$settings = array(
	'host' => 'localhost'
	, 'user' => 'root'
	, 'password' => 'password'

$databases = array();

mysql_connect($settings['host'], $settings['user'], $settings['password']);

$result = mysql_query('show databases');
while($row = mysql_fetch_array($result)) {
	$databases[] = $row['Database'];

foreach($databases as $database) {
	$sizes[$database] = 0;

	$result = mysql_query('show table status');
	while($row = mysql_fetch_array($result)) {
		$sizes[$database] += $row['Data_length'] + $row['Index_length'];


foreach($sizes as $database => $size) {
	echo $database . ' = ' . format($size) . '<br />';

echo '<br />TOTAL: ' . format(array_sum($sizes));


When I ran it, I saw all my DBs where taking a total of 10.8 GB, much less than the 86 GB occupied in the partition. So it hit me, it has to be the binary logs, a set of files that store log events (more about them here). Indeed, if you would list the contents of /var/lib/mysql I would find a ton of .bin files, a lot of them as old as from 2007. Therefore, I realized I had to flush the logs.

In order to flush the binary logs, I logged in to the MySQL console as an administrator, and issued (if you are on a server with replication, you want to purge the binary logs instead):


After doing so, the MySQL partition is now taking a total of 12 GB. Much better!


New fun project: a C++ Web Framework

As a true programmer, I need fun projects to stay alive. Don’t get me wrong, my client work fulfills me, and eventhough I’ve been slacking lately in keeping up with its workload, CakePHP is also a lot of fun. However, true programmers are always looking for a fun project, one they can call their own. Meet CLAPP, a C++ MVC Web Framework.

I am not even close to finishing it, but so far I’m having LOTS of fun. What is amazing is that missing only the M in MVC (the database abstraction layer), CLAPP’s performance is already astonishing. Running as FastCGI, it outperforms the most basic PHP file by a ratio of 1000%. Amazing.

So what am I looking to gain from this? Nothing, just having fun going back to my absolute favourite language: C++. In the meantime, I get to play with speed comparisons, which gets particularly interesting as I enable more stuff in the framework. My ideal goal is to include a lot of the you-just-have-to-have-this kind of things available on real, serious frameworks such as CakePHP. This doesn’t mean that I will hereon start developing every web application in C++, that would just be dumb (if you are asking why, then that’s because you haven’t given CakePHP a try). It does mean, however, that I’ll be posting about CLAPP every now and then.

To calm your expectations, here’s a very, VERY small preview of the Dispatcher, which is directly attached to every controller:


#include <clapp/cgi_stream.h>
#include <clapp/controller.h>

namespace clapp {
	template <class C>
	class Dispatcher {
			void dispatch();

			CgiStreamFastCgi * cgiStream;
			CgiStream * cgiStream;

			void execute();

template <class C>
clapp::Dispatcher<C>::Dispatcher() {
	this->cgiStream = new CgiStreamFastCgi();
	this->cgiStream = new CgiStream();

template <class C>
clapp::Dispatcher<C>::~Dispatcher() {
	delete this->cgiStream;

template <class C>
void clapp::Dispatcher<C>::dispatch() {
	FCGX_Request request;

	FCGX_InitRequest(&request, 0, 0);

	while (FCGX_Accept_r(&request) == 0) {

template <class C>
void clapp::Dispatcher<C>::execute() {
	C *controller = NULL;

	try {
		controller = new C();


		delete controller;
	} catch(...) {
		if (controller != NULL) {
			delete controller;


As you can guess from the source code, CLAPP can produce FastCGIs and regular CGIs. It uses ClearSilver for its view / layout templates, the FastCGI development kit (when FastCGI mode is enabled), and GNU cgicc as a CGI / FastCGI input wrapper. More news coming soon!


Seven Things You Don’t Know About Me (MEME)

An interesting meme, I was tagged by Jeff Loiselle

  1. I once worked a full day serving beverages and hamburguers to a lot of people who were attending the agricultural exposition at La Rural. The issue was that out of every burger / soda we served, me and my friends would get one for ourselves. Not too productive.
  2. I can’t sleep without a fan. I’m not kidding. Even if it’s freezing, I would turn on the heat and still power on the fan. Just two days ago (I’m currently on vacations at a beach location south of BA), I had to buy a fan since the house I rent doesn’t have one.
  3. I spent almost two years helping out local Rock / Reggae bands, including Todos Tus Muertos & Actitud Maria Marta. I started there because I faxed the manager of AMM telling him if he wanted to build a website. I think this was 1996 or something. Needless to say it was an interesting experience.
  4. I don’t know how to drive, nor I can’t because of an eye condition. In reality, they would give me the license if I wanted to, but I firmly believe I would be a danger to other drivers (even in Argentina, where drivers suck big time.)
  5. I absolutely hate politicians. With strong passion. I mean, seriously, if you are a politician, get the hell out of my way. I would tap dance on your ass if you don’t.
  6. When I was on my last year of high school, I stopped going to class and instead would spend my time at the school bar. I ended up not going for over 7 months to class, so obviously I had to take a test in March for every subject (I think we had over 20), otherwise I wouldn’t graduate. Since I didn’t tell my parents what I did, they only thought I had to take just one test, for one class. I had to take them all *while* I was taking the exams to enter University. Somehow it all worked out, and I managed to pass those over 20 exams for high school and 4 university subjects in less than a month. Crazy.
  7. I absolutely love the new Guns N’ Roses album, Chinese Democracy. I haven’t bought a music CD since 1993, but I decided to buy this one. Totally worth it. If you don’t think so, you are clueless about rock.


  • Clauz: the coolest person to have near you
  • Tim Koschützki: someone who needs help figuring out how to play soccer and not cut his leg in the process
  • Chris Hartjes: one of the coolest canucks I’ve ever met. He gets grumpy though.
  • Martín Bavio: a fellow baker from argentina, who knows a thing or two about design
  • Mark Story: the other awesome canuck, this one is almost the opposite of the grumpy one: he’s strong with the force, since he never seems to loose his coolness
  • Lorena Iglesias: my fellow sister, a prolific writer (if you don’t know spanish, she’s worth the trouble to learn it)
  • Dennis Hennen: someone who I’ve been working with for a long time now, so I happen to know him quite well

Here are the MEME rules:

  • Link your original tagger(s), and list these rules on your blog.
  • Share seven facts about yourself in the post — some random, some weird.
  • Tag seven people at the end of your post by leaving their names and the links to their blogs.
  • Let them know they’ve been tagged by leaving a comment on their blogs and/or Twitter.


Book meme

Picking up the meme from jono and matthew, here’s my meme:

“a state of emergency became the rule” – The Dachau Concentration Camp, 1933 to 1945

  1. Grab the nearest book.
  2. Open it to page 56.
  3. Find the fifth sentence.
  4. Post the text of the sentence in your journal along with these instructions.
  5. Don’t dig for your favorite book, the cool book, or the intellectual one: pick the CLOSEST.


MySQL update puts my box to test

Wanna test your box performance, both its hard disk and memory? Try setting up a +370 table database, and then build a huge MySQL update file. Run it and get something like this:


Firefox is a hungry mother!

Here I’m working with my humble Dual Processor, 2 GB RAM running Ubuntu 8.04.1, AMD64 edition. I was talking to a colleague / friend of mine and he told me that he (with his 7 GB RAM on a Mac OS) has his firefox eating some 750 MB. So I decided to see how much memory was firefox eating on my box. I run this command:

ps -C "firefox" -o pid=,vsz=,rss= | awk '{ printf "PID: %d, Virtual: %-.2f MB, Resources: %-.2f MB\n", $1, $2 / 1024, $3 / 1024 }'

And I got:

PID: 6223, Virtual: 778.06 MB, Resources: 403.70 MB

And I had just a couple of tabs open. So I said, ok, let’s start fresh. Here’s the same command with a firefox with just an about:blank, having just started up:

PID: 9139, Virtual: 462.02 MB, Resources: 56.34 MB

Nice to see resources drop, but Virtual is still at over 450 MB. Why oh why are you so hungry, dear firefox?


My top 10 commands for July, 2008

Taking inspiration from earobinson’s top commands, I’ve decided to publish my own list of top 10 commands. Running the following command:

history | awk '{a[$2]++ } END{for(i in a){print a[i] " " i}}' | sort -rn | head

Brings the following list of top 10 commands:

66 ls
40 sudo
37 cd
36 httperf
36 exit
31 svn
18 mysql
17 ssh
17 chmod
15 ./amreg-vpn.sh

Only custom script there is amreg-vpn.sh, which looks like the following:

if [ "$1" == "" ]
	echo "Usage: $0 <start | stop>"
	case $1 in
		echo "Starting VPN..."
		sudo vpnc /etc/vpnc/amreg.conf --natt-mode natt --dpd-idle 0
		echo "Stopping VPN..."
		sudo vpnc-disconnect
		echo "Usage: $0 <start | stop>"


Wine rocks my world

Ubuntu is probably the best Linux distribution out there, but sometimes you need to use software that’s only available on Windows. What do you do? Give Wine a chance. As its website states, Wine is a free implementation of Windows on Unix. Installation on Ubuntu is pretty straight forward, so you should not have problems installing it.

The above screenshot shows Wincachegrind working through Wine. Eventhough there’s a KDE version (haven’t looked for GNOME, which I run), I really needed the Windows version as it offers far more information than its Linux counterparts. With Wine, I installed the package with no problems, and I’m now using it as if it was a native Linux application. Awesome!


Transparent Pidgin chat windows

If you have Ubuntu with the Compiz effects enabled, it’s pretty easy to control which application windows you want with some transparency. On this post I’ll show you how to set your Pidgin windows with a 90% opacity. Go to the Compiz settings manager by clicking System -> Preferences -> Advanced Desktop Effects Settings. On the window that shows up, click on the General category at the left category list, and then click on the General Options button at the right. Select the Opacity Settings tab. A screen similar to the following will appear:

We will create an Opacity setting for windows that match a certain condition. Click on the button New shown right below the Window Opacities list, and enter the following details for each shown field, and then click the Close button:

  • Opacity windows: class=Pidgin & !title=Buddy List

  • Opacity window values: 90

We’ve just specified that we want 90% opacity for all windows that have “Pidgin” at its class, but do not have “Buddy List” as a title. As you see, this procedure is not limited to Pidgin windows, so you can learn from the windows matching rules to apply different settings to different windows.

Thanks to Ryan for this post.


Show what music you are playing on Pidgin

So you want the world to know what cool tunes you are currently listening to on your Ubuntu? Well, perhaps not the whole world, but at least your IM contacts. First thing you need is to be using Pidgin, and your favorite music player (I use Rhythmbox), since we will install a plugin to link our music player to our messenger. Open the Synaptic Package Manager (System -> Administration -> Synaptic Package Manager), click the button Search, and enter “pidgin-musictracker”. Right click on the available package (it should be just one), and select “Mark for Installation”. Click Apply.

If you are already running Pidgin, restart it. Once it has started, click on the Tools menu, option Plugins. Look for “MusicTracker”. Enable it by clicking on the checkbox. You can optionally select it and click on Configure Plugin to have more fun. That’s it!

Powered by Wordpress and MySQL. Clauz's design for by Cricava