Wednesday, January 8, 2014

Format XML with VIM + Indentation

Formatting XML in VIM is one of the most annoying things.  It is always easier to use other tools and paste the results back in VIM.  When you have to edit XML files very often it becomes a problem.

Recently a friend of mine and Sys Admin guru Kyle Douglas sent me an email with the VIM command to complete the task:

:silent %!xmllint --encode UTF-8 --format -

If you work with XML very often, this can be mapped to a key for easy access (in this example the F1 key).

:nmap :silent %!xmllint --encode UTF-8 --format -<CR>

Thanks for the info Kyle,

Ricardo Ramirez

Wednesday, March 23, 2011

Installing Firefox 4 in Ubuntu 10.04 & Ubuntu 10.10

Firefox 4 was recently released and here are the instructions on how to install it

Monday, March 14, 2011

Installing Internet Explorer on Linux

IE6, IE7 IE8 on Linux


This instructions are created assuming you are running a fairly reacent distribution of linux.  At the time of this post I'm using Ubuntu 10.10.
You will need to have all the required software installed and functioning.  Instructions about installing the required software is outside of the scope of this post.
This post assumes we are working on the  IE7-on-XPSP3.exe compreced VHC image.

Requirements (What we need)

I recommend the Windows XP images since they are several Gigs smaller than the Vista images.  This post is based on the IE7-on-XPSP3.exe file.

Virtual PC Configuration File (VMC)
This is an XML configuration files used by Virtual PC and required by VMware Converter.  This file can be generated by installing Microsoft Virtual PC on a windows machine  or by downloading the pre-generated filed from this post

IE7.vmc (the one used here)

Wine is used to extract the VHD image from IE7-on-XPSP3.exe.

Converts the Virtual PC (VPC) Images to VMDK which is the format understood by VMware Player.

Required to run our end product.

Step 1.  Extract the Virtual PC (VPC) file.
Open your terminal and locate your compressed Windows image and extract the VPC file using Wine.

$ wine IE7-on-XPSP3.exe

Accept the agreement.
Change "Destination Folder" to a location where you want to extract the Virtual PC (VPC) file.  I have chosen "/home/rramirez/Download"
Click on install.

Files extracted in "/home/rramirez/Downloads":
WinXPIE7.vhd    1.5G

Step 2. Convert VPC file to VMDK.
For this step we need a VMC file generated by Microsoft Virtual PC.  If you have machine with Windows on it, you can install Microsoft Virtual PC and generate this file.  Fortunately I have generated this file before hand (Download EI7.vmc) .

Place IE7.vmc  in the same directory where your extracted WinXPIE7.vhd.  This is "/home/rramirez/Downloads" from step 1.

Open VMware Converter

Click on "Convert Machine". 

for "Select source type", select "Backup image or third-party virtual machine"

for "Virtual machine" file, click on "Browse" and locate your Virtual Machine Configuration file VMC).  in my case the path is /home/rramirez/Downloads/IE7.vmc

Click on "Next"

for "Select destination type", select "VMware Workstation or other VMware virtual machine"

for "Select VMware product", select the latest VMware Player version. in my case this is "VMware Player 2.5.x".

for "Choose a location for the virtual machine", select the destination where you want to store your windows instance.  I chose "/home/rramirez/virtual_machines/".

Hit Next

Next Again

Click on Finish, and wait for VMware Converter to finish its job.

Step 3.  Run VMware Player and install the drivers.

Open VMware Player

Click on "Open a Vritual Machine".  Find the location where you have your VMDK file (Converted Instance).  I have chosen "/home/rramirez/virtual_machines/" in step 2.

Click on "Play virtual machine".  Wait for your windows instance to load up and your keyboard and mouse to become active.  This make take a few minutes.

At the logon screen, type the password provided by Microsoft (in ReadMe.txt extracted from IE7-on-XPSP3.exe).  At the time of this post, the password provided is "Password1" without the quotes.

Cancel the Activation screen and any other installation wizard that comes up.

Install the VMware drivers by clicking on "Virtual Machine"-> "Update VMware Tools...".  Once the VMware wizard comes up, finish all the steps.

Cancel any other Windows pop-up boxes asking for missing files.

Reboot the virtual machine.

When rebooted, go through the windows Activation wizard.


Comments about this procedure
To install other instances, just repeat the procedure above.  I have successfully loaded IE6-on-XP and IE8-on-XP with no issues.  When finished I notice there was a conflict with the battery in all the instances.  This should not be an issue for anybody since these instances are running just for Internet Explorer testing.

Tuesday, December 7, 2010

Dynamic Apache configuration for Development Servers

When configuring a development environment for PHP, the usual configuration is a LAMP server with mod_userdir enabled to assign each user their own URL (/~username).  I always though this URL format was not elegant.
I think the better way is to have the username in the domain part of the URL:
Configuring the server to handle this type of URL requires having per-user configuration files/sections.  It also requires restarting Apache every time this files are changed.  The solution was to use mod_vhost_alias which allows mapping domains to directories (More information found at Dynamically Configured Mass Virtual Hosting).

1. Solution (mod_vhost_alias)

The mod_vhost_alias module allows us to map parts of the domain name to directories.  The syntax used is similar to printf().  The following tables from the Apache website describes how the mapping is done:
%%insert a %
%pinsert the port number of the virtual host
%N.Minsert (part of) the name
0the whole name
1the first part
2the second part
-1the last part
-2the penultimate part
2+the second and all subsequent parts
-2+the penultimate and all preceding parts
1+ and -1+the same as 0
* For more information about this table visit

1.1. DNS
To make this work we need  a wildcard A record pointing to the development server:
* =>  #sample IP address (use your server's IP address in place or
1.2. Apache
In the default virtual host (or vhost of your choice) the following configuration is necessary:

ServerAlias * 
VirtualDocumentRoot /home/%-4.0/public_html

%-4.0   = username in [username]

The important directive to pay attention to is "VirtualDocumentRoot /home/%-4.0/public_html".  I tells apache to dynamically assign the document root based on the domain.

2. Going Even Further (sub domain per application)

With a wildcard a record and mod_vhost_alias we can assign a domain to each user app.   The format I use is the following:
to achieve this we add %-5+ to the VirtualDocumentRoot directive:
VirtualDocumentRoot /home/%-4.0/public_html/%-5+
%-4.0   = username in my-app.[username]
%-5+ = app in [app]

This configuration maps to /home/username/public_html/myapp

2.1. Omitting parts of the sub-domain 
A side effect of using this technique is that if any of the sub-domain parts is missing, apache will replace it with an underscore ( _ ):  maps to /home/username/public_html/_/  maps to /home/_/public_html/_/

This is not necessarily a bad side effect.  We can actually create pages inside underscore directories to display customized messages.


Monday, August 30, 2010

Local Git over SSH (Fixing GIT permission issues)

Solving Git local issues over SSH (Fixing GIT permission issues)

When I setup git in my company I ran into many issues.  I was moving all my projects from a Subversion environment to a GIT environment.  I already knew that GIT was a lot more flexible than Subversion and there were many possible ways of setting up the work flow.  Being the first time I ran into some issues and I have to change the way we worked a couple of times.

My first setup

The project I was working on at the time had two developers, including my self.  I opted for setting up a our work flow as a decentralized environment.  The problem with this approach was that we were used to a centralized environment.  It wasn't so much of an issue,  but actually an annoyance.  After some reading we decided to place a centralized bare repository some where in the /var/lib/project_name directory.  It was a work flow that we were more used.

After a couple of days working with it, we started having some permission issues in my local copy.  I looked inside my .git directory and found files owned by the other developer.  I quickly ran a "sudo chown -R myusername:myusername .git" to claim ownership of my files and fixed the issue.  I thought it was strange at the moment, but I didn't put to much thought into it.

Later that same day, the other developer was having the same issues. She was not able to perform certain tasks because the files where owned by me.  This time I looked a little closer.  I compared the files that had the issue with "ls -hli".  I used the "-i" switch to show the file inode numbers.  I quickly found that her files and my files where the same.  I discover that Git was actually not coping its internal files, but it was creating hard links of the files create by the other developer.

The solution

I did some reading on-line about the issue and I found that Git creates hard links for performance purposes. I was not a git expert and I wasn't sure how to turn off this feature, I thought about a workaround.  I already know that git worked over SSH and there was no way to create hard links over SSH.   I moved the git repository to it's own *nix account and had everybody clone the repository from this account.

The solution was elegant!, and it also had the added feature of being able to clone the project outside our development environment.

This is what I did.  All commands that start with # I ran as root, and commands that start with $ are ran as a regular user.

Create a *nix account for the git user as root:

# useradd git -m

Create a password, this step is optional since I use SSH Keys, it's only temporary.

# passwd git

// create an empty bare repository in git's home directory
# su -  git
# mkdir project_name.git
# cd project_name.git
# git init --bare

I ran these commands as a regular user:

// create project
$ mkdir project_name
$ cd project_name
$ vi some_file.txt
$ git init
$ git add .
$ git commit -m "STARTING PROJECT"

// push to central repository
$ git remote add origin git@localhost:project_name
$ git push origin master

Now it's was up to the other developer to clone the central repository.

$ git clone git@localhost:project_name

If you don't want to type the password for the git account every time you push a commit or you don't want to distribute the password. You can install your SSH keys on the git account.

I you have not already don't so, generate your ssh keys.  You can leave the default key file and type your security pass phrase.  If you don't want to ever type the pass phrase, just leave it empty.

$ ssh-keygen
$ ssh-copy-id -i ~/.ssh/ git@localhost

That's it, now you can continue your live with your regular pulls and pushes to the central repository.

Good luck!

Wednesday, April 14, 2010

Conditional Comments HTML

Conditional comments are grate when targeting internet explorer, but when it comes to NOT targeting internet explorer they are a pain.  The code provided by Microsoft does not play well with HTML validators:

<![if !IE]>
    <p>This will not show in any version of IE</p>
<!--[if IE]>
    <p>This will only show in IE</p>

Fortunately, there is a work around.

<!--[if !IE]><!-->
    <p>This will not show in any version of IE</p>

<!--[if IE]>
    <p>This will only show in IE</p>

By adding the tags in red, our code passes HTML validation and targets all browsers that are not Internet explorer.


Rick Ramirez

Thursday, February 25, 2010

Eclipse PHP and Remote Editing

Original Post: September 4th, 2008
Eclipse PDT (former PHP IDE) is a free alternative to expensive PHP IDEs.  It comes loaded with a lot of features and a large plugin database.   One of the most usefull plugins is the Remote System Explorer (RSE). The Remote System Explorer (RSE) allows you to work remotely over the internet.  For this article, I explain how to mount a remote PHP project over SSH.
Eclipse PDT Installation
The easies way to install Eclipse PDT is to download the latest all-in-one version from  Once on the page:
  • Click on the Download link.
  • Find the latest release (stable release is recommended).
  • Look for All-in-one option and click on the link corresponding to your platform (Linux, Max, Windows).
  • Once downloaded, Uncompress the file and open the eclipse executable
Installing the Remote System Explorer (RSE)
Once your eclipse platform is open
  • Click on the Help menu.
  • Navigate your way to Software Updates and click on “Find and Install…”.
  • The “Feature Updates” window will open, then Select “Search for new features to install” and click on Next.
  • Check the the “Europa Discovery Site” and click on Finish.
  • On the “Update Site Mirrors” window, select a mirror or just click OK.
  • On the “Search Results” window, expand the “Europa Discovery Site”.
  • Check the “Remote Access and Device Development” box, then click on the “Select Required” button.
  • Click Next.
  • Accept the terms and click on Next.
  • Click on Finish. (wait for the software to download)
  • When the “Verification” window pops up, click on “Install All”.
  • After installation is complete, say “Yes” to restart the eclipse.
Open the Remote System Explorer Perspective
  • Click on the Window menu.
  • Navigate to “Open Perspective” and click on “Other…”.
  • Select “Remote System Explorer” and and click OK.
  • Click on the “Define a connection to remote system” icon.Define a connection to remote system
  • Select the “SSH Only” as the System Type, and click on Next.Select Connection Type
  • Type the Host Name of the SSH Server and click on Finish.Type Host Name
  • Navigate your way to the folder that has your PHP code.  While doing this, Eclipse will ask you for your login credentials. Type your SSH Login and Password and click OK.ssh navigationeclipse ssh login credentials
  • Once you find the folder you are looking for, Right-Click on it, and click on “Create Remote Project”. Depending on the size of the project this could take a while.
  • Now you should be able to open your PHP prospective by clicking on the Window -> Open Prospective -> “Other …” menu.  Then slect PHP from the list and click OK.
This is it, You should now be able to work remotely as if it where on the local machine.
Note:  If your PDT Eclipse doesn’t recognize the project as a PHP Project, then you must manually edit the .project file on the remote server and add the following code:
Between the <buildSpec> tags add:


and between the <nature> Tags add:


Then Restart Eclipse.