Wednesday, April 23, 2008

Leap of faith


The woods are lovely,
dark and deep,

Inviting me to take a peek

Keeping faith I take the leap

I break some promises,
satisfaction I reap

Wednesday, April 16, 2008

A script to remove spaces from a file name

I face a lot of problem while dealing with files with spaces in their names on the Unix platform. I wrote a script yesterday to change the spaces in a file name to undescores.

It is very useful for changing the names of all files in a directory along with directory names.

Save the script to your home directory or to /usr/bin or some such directory,

Go to the directory in which you want to effect the name change and run
# find . -depth -exec ~/rename.sh {} \;

This will rename all files in the directory so that the spaces in filenames are changed to underscores.

The script is as follows:

#!/bin/bash
#
# Writen by Mayuresh Phadke (mayuresh at gmail.com)# To change the names of all files in a directory including directory names
# run the command
#
# find . -depth -exec ~/rename.sh {} ;
#
# This command is pretty useful if you have a collection of songs or pictures transferred
# from your windows machine and you are finding it difficult to handle the
# spaces in the filenames on UNIX
#
#set -x

progname=`basename $0`

if [ $# != 1 ]
then
echo "Usage: $progname \"file name with spaces\""
echo
echo "This utility is useful for renaming files with spaces in the filename. Spaces in the filename are replaced with _"
echo "\"file name with spaces\" will be renamed to \"file_name_with_spaces\""
echo
exit 1
fi

old_name=$1
dir=`dirname "$1"`
file=`basename "$1"`

new_file=`echo $file|sed "s/ /_/g"`
new_name=$dir"/"$new_file

if [ "$old_name" != "$new_name" ]
then
mv "$old_name" "$new_name"
fi

exit 0

Please let me know if you find this useful/useless or if you have any other comments about it.

Wednesday, April 2, 2008

Tools for developing Dynamic Web Sites

I started developing web sites about an year ago. When I started out I did not know of any of the frameworks which make the job of developing a dynamic web site easy. I spent a lot of time finding tools which suited my need.

In this post I have listed the tools I use. It may help newbies by giving a reference point to start out their exploration.

LAMP Based

The base infrastructure is LAMP with a little deviation. I use Linux-Apache-MySQL-Python (instead of PHP).

For the uninitiated this means I run the Apache web server, with MySQL as my Database engine, on the Linux operating system. Python is used for generating dynamic web pages on the fly.

Framework for Dynamic pages

Django is used for generating dynamic web pages. Django lets you build high-performing, elegant Web applications quickly. Django focuses on automating as much as possible and adhering to the DRY principle. Django is very well documented and the online Django Book makes it very easy for anyone to start using Django quickly.

Frontend

I layout my pages using Blueprint. This is a CSS framework which allows you to have a great layout with very clean and simple code. List formatting is done with Listamatic. It provides a easy way to create great looking lists.

And of course there is AJAX. I use the excellent Prototype and Scriptaculous libraries to add Ajax to my site. These libraries make it easy to have cross browser compatible JavaScripts.

Conclusion

Using tools greatly reduces the work required to be done to develop a website. Choosing a framework/tool which suits you is the biggest task. Think carefully about what you want to achieve and what the tool provides. Use the one which matches your style and requirements.