Archive for the 'Programming' Category

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.

Technorati Tags: , , ,

Fixing PHP Redirect On Nokia N80 Web Browser

I had a problem on a PHP page that was supposed to redirect to another page after some process was done. This is the code I used.


header("Location: http://example.com");

This kept giving me a


Web: no gateway reply

So after looking at the PHP manual for the header function and HTTP status codes I managed to get it working with this redirect.


header("Location: http://example.com", 307);

Technorati Tags: , ,

Side Projects and Collaboration

I've been getting some requests for small PHP projects. At the moment I'm not taking on any projects. If you still think I should have a look email me a specification or the requirement and I will try to give some feedback or recommend another person who might be willing to take it on.

Freelance developers! Please contact me with a brief of your skills so I can contact you when I get requests like this.

Technorati Tags: , ,

Drupal db_query trimming leading 0

The Drupal db_query was killing my leading zeros. According to this post I added single quotes and it seems to work fine now. This is in MySql 5.x and Drupal 5.7.


$query = db_query("select active from {active} where name= %s", array($user->name));


$query = db_query("select active from {active} where name = '%s'", array($user->name));

I would have added single quotes anyway but the api doc said not to.

Valid %-modifiers are: %s, %d, %f, %b (binary data, do not enclose in '') and %%.

Technorati Tags:

PHP for Developers

I like to follow up on Why You should learn PHP by rumblinglankan.com which talks about PHP for bloggers and extend it for programmers in general.

I was a full blown Java developer back in the day. I knew many developers who stuck to their guns and did one thing like Oracle, Java or .NET and said it would never go away and there would always be a market for it.

Well things change. Windows administrators are learning Linux, VB6 guys probably moved to VB.NET etc. If you sit still your skills will become obsolete.

A few years ago I saw the potential of PHP. It was simple to learn widely deployed on the Internet. I started building some Intranets with it, thinking I can move some of that logic out to a website later.

That was back in 2005. Now more than 50% of my work day is PHP, MySql, drupal, Code Igniter, WordPress or something other than Java. If I locked myself into Java I wouldn't have got most of the projects or opportunities I got.

Now I use PHP from writing system scripts to extending drupal. I'm also thinking about trying PHP GTK to write a Windows GUI application.

Look around and try something. Software is always changing, try to keep up. :)

Technorati Tags:

Drag and Drop from Eclipse Navigator

Eclipse Navigator

My primary editor is Eclipse, EasyEclipse for PHP flavor to be exact. I usually open another few Windows Explorer windows to move files around.

Today out of shear laziness I dragged a file from Eclipse Navigator to my open WinSCP tab in the task bar and into the remote site. It worked! That's my tip.

Getting on Git

I'm trying out Git. Its a distributed version control system originally written by Linus Torvalds. I also looked at SVK and Mercurial but settled with Git since it's commands made more sense to me.

I was happy with Subversion since 2004. Working alone with my notebook and client servers it has been very useful. Now the problem is I have too many workstations, servers, repositories and checkouts lying around I have to check where my latest code is before I start on any project.

I tried moving them to 2 online servers and checking out from there. But its slow and when I loose power or without an Internet connection I'm stuck.

Git might help me. When I'm done working on a project I should be able to commit locally and also sync a remote repository when I'm online. That way when I'm on another pc I can pull from a remote repository and start working.

All this is speculation at this point I will report back if it works as planned. If not I'm sticking with Subversion. :)

Being on Ubuntu Gutsy Gibbon I tried a aptitude search to see if I can install it.

aptitude search git

I thought I found it and installed the git package. I was wrong. You have to install the git-core package to get git.

sudo aptitude install git-core

And if your like and have some Subversion repositories to import you need to also install git-svn.

sudo aptitude install git-svn

Now to import a Subversion repository create a new directory for your git workspace and run something like this.

git-svnimport -v http://path.to.your/repo/

Check out this tutorial introduction to git.