Category Archives: Programming

Aptana PHP Formatting Tip

I like the Aptana PHP formatter. Its the only one that works well for me. I used to my one liner tags messed up a lot like this.

			
<?php echo $content
?>

What I noticed was that the ones with the semi-colons in place didn’t break to a new line.

			
<?php echo $content;?>

Now the auto-formatter (Keyboard shortcut to Command + Shift + F on the Mac) keeps things in the same line.

Twig library for CodeIgniter 2.x

I’m trying to catch up with this social open source movement. I forked an existing CodeIgniter Twig integration library and added some changes to work with CodeIgniter 2.x.

Also I found a way map any CodeIgniter function to Twig like so.

$this->load->library('twig'); // load the Twig library
$this->load->helper('url'); // load the CodeIgniter URL helper
// map the base_url() function as a Twig function
$this->twig->add_function('base_url');

Then in your Twig view call the base_url() function like this

{{ base_url() }}

Head over to Github for more details.

In case you have no idea what I’m talking about. CodeIgniter is an excellent PHP framework and Twig is a Django style templating engine with inheritance for PHP.

SimpleXMLElement attributes

Ya unless you work on PHP SimpleXML that title won’t make much sense. But if you do and you need to mess with SimpleXML as I have been lately to parse some Media RSS feeds you will need to use this function.

I was using it to store some urls in a drupal job queue and it was dropping in serialized SimpleXMLElement objects rather than urls.

If you go to the relevant PHP manual page you will find a comment that explains that you need to cast these attributes as string to get the value I was looking to store.

What was more interesting was Googling php SimpleXMLElement shows the solution on the second result as a summery.

Damn they are good.

Selling out

The state of Java and MySql are changing. In case you missed it. Sun bought MySql and Oracle bought Sun. I’ve been working on Java for over 10 years and MySql for over 5 now. I’m not happy with what is happening.

The Java and MySql websites have changed. On the mysql.com site there is no prominent link to get to the community edition. If you go to mysql.org to redirects to dev.mysql.com where you can find it.

This is not good for me or a country like Sri Lanka. Most of the solutions I’ve been involved over the years have used open source foundations. So we were able to deliver solutions to clients at a very reasonable cost. If things get too commercial I’m a afraid the licensing costs will far overtake the implementation costs.

I’m sure there will always be open source or free to use versions of Java and MySql, but with a large commercial entity backing them profit comes first then community. I don’t know I think its time to look at some alternatives.

Update: They got to VirtualBox too.

Jar Clean Up Story

I’m pretty happy with moving some common Java libraries out of the project source folders.

I have about 4 branches of the same project checked out. Each of them were about 57mb a piece. I noticed this while I was trying to sync my projects to a remote server. (I hate slow running scripts)

I managed to move the jar files out to a common folder which was about 27mb. I wrote another recursive ant clean script (which I will share below) that helped me clean up before the sync.

Moving the libraries was relatively simple with a few changes in the ant build scripts.

Anyway I managed to bring down each project to about 10mb. Here is the recursive ant clean script.


#!/bin/bash

projects=~/projects

for project in $(ls $projects/);
do
if [ -f $projects/$project/build.xml ]; then
echo ""
echo "Cleaning $project"
cd $projects/$project
ant clean
fi
done

I tried a similar script in Windows batch, didn’t work as easily. Don’t need bat files, Cygwin is better. And the same bash shell scripts on Linux most of the time with little or no modification.

For a programmer tweaking never stops. I try not to work on Sunday. But its a good day to take a step back and do backups, cleanups etc.

I knew about this jar duplication but really saw it while trying to run a backup and then looking at the projects folder with jDiskReport. Need more tools like this.