Connecting PHP to PostgreSQL via Unix sockets

I’ve searched the web looking for a way to connect a PHP application to PostgreSQL by Unix sockets using the pg_connect() function, but I didn’t find an answer to my situation.

Today using the trial and error method, I found a solution. There’s two ways to do the connection, since you have Unix socket connection enabled in your server:

Continue reading “Connecting PHP to PostgreSQL via Unix sockets”

Opening links in new window: the XHTML way

Roger Johansson said the following about using the target attribute:

The target attribute is not allowed in strict doctypes, and since you should always use a strict doctype, the target attribute is invalid.

It’s possible to use a JavaScript trick to open a link in a new window and still having a valid XHTML Strict syntax. Continue reading “Opening links in new window: the XHTML way”

JavaScript simple image resizer

Often one needs to resize images only using client-side programming. For cases like that, I’m using a technique with JavaScript. Depending on the original size and the desired final size, it may distort a little or lose quality. But in most cases, it’s still useful.

The image is resized proportionately and limited to the maximum size set in the variables maxHeight and maxWidth. Continue reading “JavaScript simple image resizer”

Using Apache James to send e-mail from a Windows desktop

I use Windows at work and it doesn’t have sendmail program, like Linux or Mac. With Windows XP, there is the IIS built-in SMTP service. But, yet I use Apache Server and not IIS.

Until recently I had a hard time testing applications that send e-mails. But then I found the Apache James project. Despite some issues that I have with PHPMailer specific settings, it works just fine. Continue reading “Using Apache James to send e-mail from a Windows desktop”

Simple PHP XSS injection preventer

DISCLAIMER: This post is really old. There are better ways to prevent XSS injection nowadays.

I’m using the following snippet to avoid XSS injection through forms. It’s simple. I’ve already seen some more advanced techniques to do this, but for some cases, it’s enough.

If you have form fields that allow HTML tags, you probably want to ignore (or at least filter) its content. Continue reading “Simple PHP XSS injection preventer”

Auto formatting CSS code with JavaScript

The guys from Webstandards Blog have written a guide to front-end developers on writing beautiful and efficient code. Based on their idea, I write the following code with Krause. It orders and formats CSS code with the rules designed by them.

Some text editor allows you to write plugins using Javascript. This code can be useful in that context.

Notice that only properties defined in props array are ordered. Other properties are placed at the end of the rule. You can add more properties to props as you want.

Continue reading “Auto formatting CSS code with JavaScript”

Displaying your latest Twitter entries

DISCLAIMER: The Twitter REST API v1 is no longer active.

Helping Carlos Eduardo from Webstandards blog, I’ve adjusted this coded posted at WPRecipes. We wanted to show the latest twitter entries in a WordPress blog.

You can show how many tweets you want with this updated code, instead of just the last one. Another improvement is the session-based cache to speed things up.

UPDATE: Due to charset compatibility I switched from regular expressions to json_decode function. It also makes the code smaller. Continue reading “Displaying your latest Twitter entries”

Java Tip : Collections Performance

On Java development, performance is an element that drives developers crazy. Small details can make a considerable difference. Especially when dealing with a big volume of data. One of these details is the kind of collection used to store data. Here it goes some tips on it. Continue reading “Java Tip : Collections Performance”

Hello world!


Eu sou um fã de programação orientada a objetos. Apesar da minha linguagem preferida ser Java, lidero um time que também desenvolve aplicações em PHP e C# e talvez eu escreva sobre essas linguagens também.

Meu plano aqui é escrever sobre arquitetura de software, boas práticas de programação, técnicas para ganho de performance e outros tópicos relacionados a desenvolvimento de software.

Espero que meus artigos úteis para você.