Chile

We’re thinking of moving to Santiago de Chile shortly. We paid a short visit to the city to check what was all about, how Ale would be working, the prices, the sights and the movement of the town. Check the full post for the pictures we took More of this at Santiago de Chile

Padre Nuestro

¿Por qué? Porque juego a Civilization IV y Baba Yetu es la canción que se escucha al entrar al juego. Vean el video de Baba Yetu y díganme si no les gusta. Les dejo cuatro versiones en idiomas distintos. More of this at Padre Nuestro

Getting started with Audacity

Getting started with Audacity 1.3

Getting started with Audacity 1.3

A few months ago I was approached by the good folks at Packt Publishing to do a technical review of their brand new book “Getting Started with Audacity 1.3“.

Before I start, please do note that, for SEO’s and good taste’s sake, I avoided any lame puns with the post’s title such as “To audaciously go where no-one has gone before”. Until now, at least.

Throughout the review I found the book to be interesting and very readable, proposing projects that were both easy to do and immediately compelling, such as creating and editing useful soundbits from a ringtone to a podcast. I even used what I had learned to create my own ringtones: the first chords of Fortunate Son for one, and a few bars of the main theme from Ponyo on the Cliff by the Sea for another.

I recommend this book for those that want to create or edit their own soundbits and don’t know how. It is the perfect introduction to audio editing. The fact that the app used is available on the three major operating systems for free, and that it has an intuitive interface is a major boon.

PHP tutorials: array_map and array_filter

This can be a series of tutorials. I hope it will be. The credit for the initiative goes to the blog post “The Beginner Pattern“.

Since PHP 4.0.6, PHP has included two powerful functions to process arrays: array_map and array_filter. These can be a bit hard to wrap your head around at first, for they flip the normal thought pattern of “do foreach on the array, modifying each value” over, in the case of array_map, or “do foreach on the array, extract the elements that match something” in the case of array_filter.

array_map

This function takes at least two elements: a function and an array. After the first array, more arrays can be added. It returns an array with the elements resulting after applying the function to all the following arrays in parallel.

That was a mouthful. What that blurb meant to say is that a call to array_map("func", arr1, arr2, arr3), where func is a previously defined (or standard library) function that takes -in this case- 3 arrays, is  approximately equivalent to:

$len = count($arr1);
$result = array();
for ($i = 0; $i < $len, $i++) {
    $result[] = func($arr1[$i], $arr2[$i], $arr3[$i]);
}

I said “approximately” because the longest array passed dictates the length of the resulting array. You should make sure that all the arrays you pass to array_map as function arguments are of equal length, otherwise the shorter arrays will pass Null as the argument to func if they are exhausted. On the other hand, that might be exactly what you wanted.

One quick example:  Say you have a form to process. First thing you want to do is sanitize the input (let’s say it’s in $_POST)before processing it. So you build a sanitizer($unclean_input). Without array_map(), you have to do a loop as in the example above to apply your function to each element of $_POST. With array_map, you simply do

$_POST = array_map('sanitizer', $_POST);

and you’re done.

array_filter

Have you ever had to filter an array based on a condition? Did you ever look up to the skies and begged “Oh supreme lord of all creation, I’d like to be home by seven today, but this damned method is taking forever to code and I can’t see straight anymore!”?

Well, suddenly the holy light is shining upon your brow, and the lord is smiting your misbehaved code with array_filter.

This function takes an input array (the aptly named $input and a callback function. It iterates over each value of $input, passing it to $callback, and collecting every value for which $callback returns true in the result array. A quick example, lifted verbatim from PHP’s documentation:

< ?php
function odd($var) {
    return($var & 1);
}

function even($var) {
    return(!($var & 1));
}

$array1 = array("a"=>1, "b"=>2, "c"=>3, "d"=>4, "e"=>5);
$array2 = array(6, 7, 8, 9, 10, 11, 12);

echo "Odd :\n";
print_r(array_filter($array1, "odd"));
echo "Even:\n";
print_r(array_filter($array2, "even"));
?>

The output from this would be:

Odd :
Array
(
    [a] => 1
    [c] => 3
    [e] => 5
)
Even:
Array
(
    [0] => 6
    [2] => 8
    [4] => 10
    [6] => 12
)

A quick and useful tutorial to using PDO

PDO (PHP Data Objects) is a PHP extension that grants you generic access to databases in an object-oriented fashion. Perusing stackoverflow I found an excellent tutorial on the subject written by Paul DuBois at kitebird.com.

Using PDO, you’ll stop embedding calls to mysql_ functions across your code, your scripts will improve, your breath will smell mintier, swallows will chirp around your head as you suddenly break into dance. In the rain. Seriously, you will start writing safer, better code. You will be more productive. Your code will be more extensible and maintainable. And isn’t that what this is all about? Plus, swallows, man. Effin’ swallows!

I encourage every fellow PHP programmer that can* to update their mysql_query()es and start using prepared statements like God commanded it.

*You might not be able to use PDO if you’re running older versions of PHP. Shame.

Something from the Scary Devil Monastery

This is airlifted directly from a post by ‘Szechuan Death’ at the Scary Devil Monastery. I didn’t touch a iota, but I found it extremely insightful. If the original author feels it is inappropriate to display his content here, I’ll gladly remove it. I thought it was something worth to be preserved beyond Usenet archives.

The basic rules of systems administration – agnostic of platform, era,
personal preference, management diktat, whatever – are three, eternal,
and easy to articulate:

Rule #1 (Principle of Least Intervention):

“If it ain’t broke, don’t fsck with it.”

[An oldie but a goodie, well known by nearly everyone who's ever played
with a comple system. From this springs several corollaries, my
favorite being 'Developers are tools of the Devil.']

Rule #2 (Principle of Escape):

“If you *have* to fsck with it, have a plan to roll back whatever
changes you’ve made.”

[First recorded in the year 20 B.I. (Before Internet), by the first
sysadmin to ever botch a change on a production system, Harassus Maximus
the Eternal Catamite, verbalized only moments before he was swallowed by
a demon dispatched from the bowels of the nether to punish his
accidental folly.]

Rule #3 (Principle of the Panic Button):

“If you cannot roll back the changes you made, be damned sure you have
some way to restore service as soon as practically possible.”

[This chestnut was first uttered by Hero Bastardus the Elder, as an
admonition to a PFY, shortly before the PFY was executed by Hero for the
sin of finger-fscking a production system into a terminally crashed
state without any coherently-verbalized plan for unfscking it or
mitigating the outage.]

Yet these Articles of the Faith are routinely ignored, by clueless
management; by mouthbreathing submorons who should never have been let
near a keyboard, much less given root access; by perpetual spastics who
know these things in an academic sense, but somehow manage to routinely
lose control of their sphincters at precisely the correct time to cause
a fsckup of epic proportions; by users. Oh, God, the users. They
demand ponies, and demand them *now*, the hell with the havoc it will
wreak on the machines and on the hard-won stability achieved over
man-eons of effort prying bugs and strange failure modes from the
systems. And the PHBs, who perpetrate such insanities as attempting to
force practitioners of the Art into eternal Follies such as “democratic
design” (usually ignoring Rules #1 and #2) and craptastic Kool-Aid fads
like “agile development methods” (destroying all Rules in a pyre of
brilliantly iridescent stupidity).

Yet have heart, O ye my brethren; the Rules are eternal, and Wankery is
ever-passing. It returns, yes, and frequently, like a maladaptive
evolutionary trait recurring at random intervals on the theory that
‘Hey, maybe *this* time it will work’; but never does it triumph, not in
the long run.

(This is a good thing to believe, because otherwise one winds up curled
in a ball beneath one’s desk, the tears and gibbering flowing freely
until the men with needles come to carry you off to the Wacky Factory
for a vacation.)

Apropos of nothing, of course, this fine Monday evening. Nothing
a’tall. Just another swell day in Paradise, yessir.

Traffic in Buenos Aires

Today, I got off work at 18:20. Subway line B was

  • full of people in the runway
  • pressed like sardines inside the trains themselves
  • running with delays

After some half an hour of letting trains pass, I could bear no more and got out, tried to take a bus. The 24 line was there to get me home, but it did take another good 30 minutes.

I can’t wait for flying cars. I see no other solution to the traffic congestion down here. Or maybe I do. Massive decentralization of offices, banks and firms from the centre coupled with a decent redistribution of same over the city, perhaps a congestion charge as implemented in London… Both things could help a lot, I think.

Civ 4

Thou shall not start late games of Civilization IV, for they will drag on into the night and cause your wife to be mightily angry at you.

My mind, she’s blown

I just found a meta-quine. More of this at My mind, she’s blown

ESR? te voy a dar ESR!

Como para que quede asentado (esto viene por el artículo sobre sexismo y RMS), ESR también me parece un pelotudo importante, tanto o más que RMS (que al menos tiene un montón de código atrás de él, no ’solamente’ fetchmail, libpng y juegos). More of this at ESR? te voy a dar ESR!