Transforming XHTML documents with XSLT 1.0 and PHP

XSLT (Extensible Stylesheet Language Transformations) is a language used to transform XML documents. It is mostly used to transform an XML document into a different XML document with a different XML Schema.

XHTML (eXtensible HyperText Markup Language) is an XML version of the HTML markup language. It was created so websites could be parsed using standard XML processors instead of having to depend on specific HTML processors.

The problem

So far everything sounds good, but there are some problems. Following the standard you should be able (as a matter of fact you must) to send an XHTML document to the browser with a mime type of “application/xhtml+xml”. The problem here is that some browsers (IE) don’t understand that mime type and thus don’t render your document.

Read More

Run PHP unit tests automatically using git hooks

Git hooks

From git documentation:

Hooks are little scripts you can place in $GIT_DIR/hooks directory to trigger action at certain points. When git-init is run, a handful example hooks are copied in the hooks directory of the new repository, but by default they are all disabled. To enable a hook, make it executable with chmod +x.

If you take a look at your .git/hooks folder you will probably see a bunch of hooks created by default. In my current version of git all my hooks have a .sample extension. To make a hook executable you must remove .sample and make it executable. If you don’t want to remove the default example you can create a new file without .sample.

Read More

Getting more from git log

This post is basically a copy of pimping out git log. I just made some modifications to Bart’s alias to fit my personal preferences.

This code creates an alias named lg for the git:

1
git config --global alias.lg "log --graph --pretty=format:'%Cred%h -%C(yellow)%d%Creset %s %Cgreen(%ci) %C(bold blue)<%an>'"

Here is an explanation of what that command does:

1
git config --global alias.lg "..."
Read More

How to delete a commit in git, local and remote

It has happened to me more than once that I make a commit without verifying the changes I am committing. Time after that I review the commit and I notice that there is something in the commit that doesn’t belong there.

In those times what I want to do is make a patch with the changes of the commit, delete the commit, apply the patch and then redo the commit only with the changes I intended. In this post I will only explain how to delete a commit in your local repository and in a remote repository in case you have already pushed the commit.

Read More

Publish an extension to firefox directory

Once you have created an extension, you will probably want to make it easily available to the public.

For my tntfixer extension that I explained in some previous posts I had a folder structure similar to this one:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
/tntfixer
|----chrome.manifest
|----install.rdf
|----README
|----/chrome
|    |----/content
|    |    |----tntfixer.js
|    |    |----tntfixer.xul
|    |
|    |----/skin
|    |    |----overlay.css
|    |    |----/images
|    |    |    |----status-bar-icon-active.png
|    |    |    |----status-bar-icon-inactive.png
Read More

Using UTF-8 characters on an e-mail subject

If you have sent e-mails in a different language than English or using characters outside the ASCII range you have probably already used utf8 to send them.

Specifying the use of UTF-8 in the body of an e-mail is very similar to doing it for a HTTP response. You can specify the content-type in an e-mail header like this:

1
Content-Type: text/plain; charset=utf-8

But there is catch. The subject line of an e-mail is a header by itself, and headers must contain only ASCII characters. Happily, there is a work around. RFC 1342 is a recommendation that provides a way to represent non ASCII characters inside e-mail headers in a way that won’t confuse e-mail servers.

Read More

apache2: Could not reliably determine your servers’s fully qualified domain name, using 127.0.0.1 for ServerName

This is a common problem I find when I do a new Apache 2 install on Ubuntu. There is a simple solution to stop seeing this message. Edit httpd.conf, type this command in a terminal:

1
sudo gedit /etc/apache2/httpd.conf

Add this line at the end of the file

1
ServerName myserver

You can replace myserver with whatever name you want to use for your server.

If that doesn’t completely fix the problem try adding the same line:

1
ServerName myserver

At the end of /etc/apache2/apache2.conf

That should do it.

Read More

Creating local virtual hosts with apache

If you are a web developer, virtual hosts is probably something you already use, if not, you should.

Virtual hosts allow you to have multiple domains configured in your computer so you can have different web sites in different locations on your hard drive and keep your environment better organized when developing. Virtual servers are also used by shared web hosting companies to host multiple web sites in the same machine, the difference is that they deal with a bunch more stuff that I am not going to deal with in here. This guide should only be used to create virtual servers for local development.

I am currently using Ubuntu 11.04 (Natty Narwhal) but I am pretty sure the instructions are the same for other versions of Ubuntu. Other Linux distributions not based on Debian have a slightly different folder structure, but you should be able to adapt this guide easily.

Read More

Zend Framework Hello World

I am going to explain how to make a very simple hello world application using Zend Framework. While doing this I am going to try to explain how Zend Framework manages MVC.

Folder structure

Zend Framework uses the Front Controller pattern on its implementation of MVC. This means that all calls to your website are managed by one file and this files routes to a correct controller based on the URL of the call.

For this example we are going to create a folder for our application: /home/adrian/www/hello. Inside that folder we need to create three folders: application, library and public.

Read More

Changing the color of a tab on a firefox extension

Changing the color of a tab on a Firefox extension is a very straight forward task. You can use this code to change the color of all the tabs on a window:

1
2
3
4
5
6
7
8
9
var tabbrowser = window.getBrowser();
for (var i = 0; i &lt; tabbrowser.browsers.length; i++)
{
    tabbrowser.tabContainer.childNodes[i].style.setProperty(
        "background-color",
        "#0f0",
        "important"
    );
}

If you don’t provide the third argument “important” you won’t be able to override the browser default and therefore you wont see your change.

Read More