Archive for the 'How To' 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: , , ,

SQL Play with Firefox 3 Places

I heard good things about Firefox 3. Now that I've got Ubuntu 8.04 I thought I'd try a few commands.

1. Get the places database
2. open with sqlite
3. query the bookmarks table

cp .mozilla/firefox/xxxxxxxx.default/places.sqlite .

sqlite3 places.sqlite
sqlite> .tables
moz_anno_attributes moz_favicons moz_keywords
moz_annos moz_historyvisits moz_places
moz_bookmarks moz_inputhistory
moz_bookmarks_roots moz_items_annos

sqlite> select * from moz_places limit 1;
1|place:queryType=0&sort=8&maxResults=10|queryType=0&sort=8&maxResults=10||0|1|0||0

Happy data mining!

Technorati Tags:

Make Windows Shortcuts with Cygwin

Did you know that you can make Windows shortcuts with Cygwin and ln? I did not know this, just tried it out today and it works!

This is probably the smallest thing I'm blogging about, but read on you might get some new ideas (like I did) about file organization in Windows. I swear some days Cygwin is the only thing that keeps me sane on this office Windows XP computer.

I like to keep my /projects folder separate from my /clients folder. It just saves clicks I guess and I'm a separation junkie I can't help it. I could have manually created these shortcuts for each project but now I can do it in a bash script. Yay!

Still not following? Let me explain. I have a clients folder like this.


/clients/a/projects/a
/clients/a/projects/b
/clients/b/projects/c
/clients/a/projects/d

But I like to keep my projects in a root level projects folder like this for easy access and backups etc.


/projects/a
/projects/b
/projects/c
/projects/d

I have simple, unique, short project names. That helps a lot. Here is the magical command that can help me a great deal.


ln -s /cygdrive/d/clients/a/projects/a /cygdrive/d/projects/a

This way I can keep projects I'm currently working on in /projects and move others back to /clients/x/projects. Ideas for a project folder management script is brewing will post about that later.

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: , ,

Things to do on Earth Day and Beyond

April 22 is Earth Day so I thought of spending my lazy Sunday morning looking at how to save the world! Here is what I came up with.

Lighting
Change to CFL bulbs for long running locations. I've noticed they bust sooner for short running lights like in the store room and bathroom. I've switched to 90% CFL. The units are down but the bill keeps going up (only in Sri Lanka).

Buy CFL's at an electrical shop rather than a supermarket. They will advise you better on which ones are better and where they will fit.

Consider motion sensors and timing units for lighting where appropriate. I have a motion sensor spot light at a dark corner of the garden and an automatic water pump system. I'm waiting for LED home lighting but I guess it'll be a while more till we get them down here.

Make use of daylight as much as possible. Move desks around knock down walls if needed. :)

Heating and cooling
That last point helps with ventilation and cuts down on running fans all day.

Look at overall air flow in the house, use an exhaust fan where needed. Consider running the exhaust fan on a solar panel directly. When the heat is up the sun is up, use the free energy falling from the sky.

If you need heated water consider solar heating. If you have a electric water heater turn it down to the bare minimum you need.

Water
If you have space and a garden look at rain water harvesting. At least to water the garden. You can also filter it and use it to flush the toilet.

In the bathroom change to a low-flow shower head and a dual flush toilet. Use faucet aerators for kitchen and bathroom taps.

Electronics
We love our gadgets, but do they have to be on all the time? Stand by power still uses some power. Turn it off from the wall if you are not using it.

According to this a LCD TV is better than a Plasma. My aging CRT is close to a LCD so it'll do for the time being.

Reality
The cost of solar even CFL's are not cheap. Living in a third world country some of these things are not available to buy even if you have money. But press on, do what you can. Influence local government, inspire business to notice these things.

Links

Technorati Tags: ,

A better ssh-copy-id | smithii.com

I wanted to authorize my web host with my Cygwin shell to do some backups. I'm used to ssh-copy-id but Cygwin doesn't have it. I found this script that does the trick.

A better ssh-copy-id | smithii.com

I put this code in a ssh-copy-id.sh file.

#!/bin/sh
# $Id$

SSH="${HOME}/.ssh"

if [ ! -f "${SSH}/identity.pub" ]
then
PASSPHRASE=
read -p "Enter ssh passphrase for ${HOSTNAME}:" PASSPHRASE
ssh-keygen -t rsa1 -N "$PASSPHRASE" -f "${SSH}/identity"
ssh-keygen -t rsa -N "$PASSPHRASE" -f "${SSH}/id_rsa"
ssh-keygen -t dsa -N "$PASSPHRASE" -f "${SSH}/id_dsa"
chmod -f go-w "${SSH}" "${SSH}/authorized_keys*"
fi

cd "${SSH}" && \
tar -c id*.pub | \
ssh $* 'tar -x
SSH="${HOME}/.ssh"
if [ ! -f "${SSH}/identity.pub" ]
then
PASSPHRASE=
read -p "Enter ssh passphrase for ${HOSTNAME}:" PASSPHRASE
ssh-keygen -t rsa1 -N "$PASSPHRASE" -f "${SSH}/identity"
ssh-keygen -t rsa -N "$PASSPHRASE" -f "${SSH}/id_rsa"
ssh-keygen -t dsa -N "$PASSPHRASE" -f "${SSH}/id_dsa"
fi
cat identity.pub >>"${SSH}/authorized_keys"
cat id_dsa.pub id_rsa.pub >>"${SSH}/authorized_keys2"
chmod -f go-w "${SSH}" "${SSH}/authorized_keys*"
rm -f identity.pub id_dsa.pub id_rsa.pub
'

Speed up Firefox Startup with Firefox Preloader

My Firefox startup was slow. Its one of my primary applications as a web developer so its very important that it runs well.

I found Firefox Preloader and it did the trick. It cut down my initial startup time to a few seconds.

One more thing. It turns out I've been blogging here for a year now and I just past my 100th post. This is post 101. Feels good still to be around. Thanks for visiting.

Internet on the Road with WIFI, 3G and JoikuSpot

I tried out JoikuSpot with my Nokia N80 and notebook. Its simple to setup and worked pretty well. This is definitely useful on the road.

This method can't beat 3G modems since they can go up to 7.5Mbps. The Nokia N80 only supports 384 kbps. But its better than buying a dedicated 3G modem for me because I don't need to use it often between ADSL points.

If you don't already have a 3G phone it might be cheaper and faster to get a 3G modem.

I checked Mobitel and Dialog for 3G modems a few months ago. Back then I was on Linux only and they didn't have drivers etc. This should work on Linux as well since its on WIFI.

JoikuSpot has a few limitations at this time. It only supports HTTP/HTTPS and the WIFI hotspot is not secure. They say other protocols and security is on the way.

Here is the introduction from the developers:

JoikuSpot is a free mobile software solution that turns a Nokia Smartphone to a WLAN HotSpot. You will carry internet in your pocket. Connect your laptop to web everywhere! FREE -- INSTANT -- EASY

Technorati Tags:

SQLite Vacuum on F-Spot

I heard on FLOSS Weekly 26: SQLite the other day about the vacuum command in SQLite and how it rebuilds the database and makes Apple Mail faster.

I started F-Spot to check some old photos and it was getting stuck. Hmm wait F-Spot uses a SQLite database too, so I tried something like this.

Went to the F-Spot directory.

cd /home/dilantha/.gnome2/f-spot

Backed up the current SQLite database.

cp photos.db photos.db.20080326

Opened the database

sqlite3 photos.db

Then in SQLite I got some help, listed tables and ran vacuum on photos and photo_tags.


.help
.tables
vacuum photos;
vacuum photo_tags;
.quit

Now F-Spot is running smooth as ever.

Technorati Tags:

Running Bash Scripts in Windows Scheduler

Normally you can run scripts in the Cygwin shell. But I wanted to run a bash script in Windows scheduler. Find the Cygwin.bat file probably located in C:\cygwin. It looks something like this.


@echo off

C:
chdir C:\cygwin\bin

bash --login -i

This batch file doesn't let you run an external script with it. Add a %1 at the bash command's end like this. What you are doing is passing the first parameter in Windows to bash.


@echo off

C:
chdir C:\cygwin\bin

bash --login -i %1

Now drag and drop the Cygwin.bat file into the Windows scheduler window and edit running time properties etc. Now add the script to run at the end of the Cygwin command. For example like

C:\cygwin\Cygwin.bat ./bin/mysql/db.dilantha.info.sh

Windows Scheduler

Technorati Tags: ,