May 11, 2013

Custom RecursiveIterator

PHP RecursiveIterator and its relatives are quite handy in any tree-related situation. Probably the most used is RecursiveDirectoryIterator for getting all files recursively in a directory. But this family of iterators has some issues to be addressed so that developers do not end up fleeing. First, you must not fear SPL. But there's more. Let's see…

Keep empty directories in git: The VERY easy way

I keep hearing this question over and over in the internets: How do I keep an empty directory in git?
And they're usually followed by a hundred of different answers, mostly "you can't" and very complicated ones.
But, in fact, there is a way that's pretty EASY:

January 16, 2013

Sublime Text 2 snippet Getter/Setter

It's almost a month since I embraced Sublime Text as my daily editor, even for coding. And I love how much easier my life is now. As an example, here's a snippet I just made to avoid writing all that getter/setter bolierplate over and over again in PHP…

October 17, 2012

Symfony2: How to start a new project easily with Composer

Composer is the best thing it happened to the PHP community since PHP 5.3 was released: PHP project dependencies made easy. It's worth the little time you must spent to learn how to use it. I can't recommend it enough.

How can I use this jewel to start a Symfony2 Standard Edition project? Have a look at how easy it is:

Symfony2: Repositories in DIC

Easy recipe to define a Doctrine repository in your Dependency Injection Container:

September 07, 2011

Cross browser Leading Zeros with JavaScript

This is a short entry for further reference

Left padding an integer with zeros was never so easy. Can't believe this ended up working.

function LeadWithZeros(num, pad) {
    return (Array(pad).join('0') + num).slice(-pad);
}

LeadWithZeros(5, 3) === '005';
LeadWithZeros(65, 3) === '065';
LeadWithZeros(120, 3) === '120';

March 15, 2011

!isset, is_null, empty: The Good, the Bad and the Ugly

Hi everyone, you programmers trying to grasp the intricacies of PHP. As coders, our raw material is, and will be, information and knowledge. But lack of knowledge does not give us some information, too? Is of this absence that we will discuss today: How to know if we don't know something in PHP. And our main tools are isset, is_null and empty. Want to know more about them? Which one is The Good, The Bad and The Ugly?

March 04, 2011

Exchanging currencies with Zend_Currency_CurrencyInterface

As many companies offering online services do, we handle multiple currencies. This often involves querying external services to know the real value of the currency exchange. Previously, this logic was scattered all over the code, even copy-pasted in multiple files, and is pretty hard to mantain, let alone to test.

So, in my work detecting and extracting patterns from old spaghetti code, I came with the following solution: A Service layer.

January 19, 2011

How to detect if a class implements an Interface?

I'm in the real need to know if, given a string className or object, it implements a particular interface. I'm specially interested in the string className part.

During the search, many seemingly valid options appeared: instanceof, is_subclass_of, is_a, ReflectionClass::ImplementsInterface, class_implements… Which one to use? Let's do some testing!

December 17, 2010

The Coder Zone Stats 2010

It's a fact: 2010 comes to an end in 2 weeks, and it's time for me to take stock of the year, get some numbers, think about them… As I did last year.

December 16, 2010

What my htaccess looks like in Zend Framework

While coding under Zend Framework there's a standard for what htaccess files should look like. Using mod_rewrite every request is checked against the filesystem for existance, and then served. If it does not exists, the control passes to index.php who starts the Zend Application.

Since, even nowadays, every disk access is paid in valuable time, I made my own htaccess, optimized for disk avoidance whenever possible. After all, it's only a convention to follow, isn't it?

October 26, 2010

Simplest Credit Card Validator

Searching for a simple credit card validation algorithm? The Luhn algorithm is a simple checksum that validates most identification numbers, mainly used in credit card ones. It's implementation is quite simple. Need one? Just come along!

September 21, 2010

Safe RecursiveDirectoryIterator

I love SPL... so simple, so powerful, so flexible.

RecursiveDirectoryIterator was having problems while scanning a directory and threw me some nice errors on permissions, so I coded the snippet below...

January 14, 2010

Renovarse o morir

Poner puertas al campo es algo que todos los gobiernos han intentado, sea cual sea el color que enarbolen, y todo es gracias a los hombres tras la cortina, que parecen hacer y deshacer a su antojo.

Y es por eso, y a raiz de la polémica Ley de Economía Sostenible, que nace la plataforma Red-SOStenible, bajo el lema A partir de hoy, Red y Libertad, y con ellos su campaña Internet NO será otra tele. Sus objetivos son claros: Detener dicha ley mediante el diálogo con los representantes nacionales y la promoción de acciones ciudadanas.

Es difícil de creer pero, a estas alturas, hay muchísima gente que aún no se da cuenta del grave problema de libertades que hay en nuestro país en lo que respecta a las nuevas tecnologías.

Y así, como donde empiezan las libertades de uno, terminan las de otro, se nos insulta públicamente tachándonos de "piratas" mientras, por la trastienda, nos están cobrando cánones a cascoporro. Muy bonito, señores, muy bonito. Y todo por algo que es, demostrado en los tribunales, absolutamente legal.

En fin, el problema inicial son las industrias que pretenden mantener su cuota de mercado a cambio de nada, continuando su arcano modelo de mercado. Las discográficas ya hace tiempo que se resisten, pero con el mercado de eReaders en expansión, pronto se añadirán también las editoriales.

Señores que quieren y/o necesitan vivir económicamente del pasado:
Aplíquense el dicho, Renovarse o morir. No vamos a quedarnos de brazos cruzados.

December 31, 2009

Happy New Year 2010!

May the 2010 year bring you happiness and joy. And may all your dreams come true, like IE dissapearing from the face of the Net. This would be nice...

December 13, 2009

PNG study with CSS Sprites

While writing my first CSS Sprite article, I created a simple, in no way efficient, sprite generator. Last week I needed to show some numbers to the project manager to convince him the sprite technique is worth using, so I modified a bit the program to arrange the icons in different layouts and show the size savings.

Want to know with which layout I improved the file size by 78.6%?

December 12, 2009

Problemas y números

Inicié este blog hará cosa de 9 meses. No con un deseo comercial ni para obtener visitas a cascoporro, si no como terapia. Mi pretensión era la de practicar mi inglés mientras compartía los problemas que me iba encontrando en mis andaduras con la web. Pero está claro que algo falla en ese enfoque: Si ya es complejo mantener un blog en un idioma que es natural para uno mismo, más complicado es hacerlo en una lengua distinta.

¿Debería seguir, como hasta ahora, publicando en inglés? ¿O quizá ahorrarme molestias y expresarme en mi propia lengua?

November 25, 2009

Reset your CSS

Ever wanted a website that looks the same in all browsers? Tired of fighting slimy monsters while searching for excellance? Do these differences in UL padding make your head explode? So it's time for you to apply some CSS Reset Magic.

When it relates to CSS reset, there's a bunch of literature, do's and don't's, faqs and howtos, so this one won't take us too long.

November 17, 2009

Progressive enhancement example: Language Selection

It's easy to get lost in the Internet while looking for information. It's one of its greatest points: There are thousands of millions of websites out there. Information is the key purpose of the net and nobody can deny it.

But, as in many other cases, quantity does not equal quality. Poor designed websites, too bloated, with many inlined styles or little semantics (if none), are begging for trouble: Their information have lost accessibility.

November 11, 2009

Frames without frames. AJAH selective insertion

And W3C said Let there be frames, and there was frames, and they were used (and abused) and it was good, and W3C said This is right (we're gonna deprecate them soon) and there was much rejoicing.

Is not new that web developers hate all that's made with frames. They're a burden nobody wants to carry, so confusing, so "nineties", so... well, deprecated, that's it. So you may think I'm just delving into the past. Frames, as we know it, are dissapearing into extinction but, the main idea, more or less, is still needed nowadays.