Monday, 23 February 2009

A Tribute to the Divine Genius of A R Rahman

Having won at the Oscars and the Golden Globes, A. R. Rahman is getting the recognition he deserves for his genius. Personally I do not rate Slumdog Millionaire among his top 5 albums even. He's composed for over 110 albums and a good debate on his best work is available here
My post today is on Rahman's truly divine gift. Some of his music makes one feel blessed to be just listening to the soul-stirring melody - and truly truly you close your eyes and feel you are in another land - sitting obeisant in front of God.
His own philosphy as written on this blog states
"Music is my means of connecting with the divine. What cannot be put into words, can be expressed through music."

It's well known that he is a follower of Sufism - and there are various songs which evoke that music. But you sometimes cannot believe that one man can put together all of this music. A true disciple of music in it's forms and variations, his music has blended such diverse techniques to create sound you never could imagine.
Among all the musical wonders he's produced over the ages the ones I'm writing about today are the devotional tracks appearing in various OSTs.
Sufi / Qawwali
“Khwaja Mere Khwaja” from Jodhaa Akbar
"Arziyan" from Delhi-6. The first two lines of this humble tribute sung by Javed Ali and Kailas Kher are just lovely and the rest is very well arranged.
"Tere Bina" from Guru

The bhajans
“O Paalanhaare” from Lagaan (sung by Lata Mangeshkar and Udit Narayan).
"Mann Mohana” from Jodhaa Akbar (sung by Bela Shende) - the violin interlude is such splendour. This is my favourite Rahman song. It must be heard with one's eyes closed to really feel the maetro's magic and oneness with God. Note to self: dont listen while driving.
"Aarti (Tumre Bhavan Mein)" from Delhi-6 is extremely simple with just the sitar stringing in the background but so moving. Sung in unison by Rekha Bharadwaj, Kishori Gowarikar, Shraddha Pandit and Sujata Majumdar

And his interpretation of the Sikh prayer "Ik Onkar" from Rang De Basanti - also picturized very well in the movie - simple and devotional.

Also must mention "Maa Tujhe Salaam" part of an album released to celebrate India’s 50th year of Independence in 1997.

Friday, 20 February 2009

Bad Java code with good intentions

My friend Deepak sent me a real-life example of the following Java code. Let's give the developer the credit of following defensive coding techniques. [Rather than calling him a dumb-a$$]



String flashPath = (String)request.getAttribute("flashPath");
String flashPathPath = flashPath.toString();




Sathya improved on it by adding checks


String flashPath = (String)request.getAttribute("flashPath");
If (flashPath instance of java.lang.String){
String flashPathPath = flashPath.toString();
}




So let's work on this some more



String flashPath = (String)request.getAttribute("flashPath");
If (flashPath instance of java.lang.String){
try{
String flashPathPath = (String) flashPath.toString(); //Let's cast it once more to be sure, if it escaped the first time, it'll surely get caught here.
}
catch (ClassCastException e)
{
// Don’t cast it
String flashPathPath = flashPath.toString();
}
}



Now this is open to all to further obfuscate.
How complicated can you make one line of code?

Friday, 13 February 2009

Now Playing Jan/Feb 2009

Music albums that I've picked up and liked over the last 2 months:

Best of Led Zeppelin
Keane - Under the Iron Sea
The Weepies - Say I Am You
Joshua Radin - Simple Times
Delhi 6 - OST
Luck By Chance - OST
Dashboard Confessional - Dusk and Summer
Dev D - OST

I seem to like most of the Indie picks from Zach Braff's movies - "The Last Kiss" and "Garden State" - and the Scrubs OST.
In addition to the above albums, Cary Brothers, Zero 7 and Imogen Heap were stumbled upon off various Scrubs episodes.

Thursday, 12 February 2009

junit.report fails with OutOfMemoryError

Running too many testsuites in junit.report causes a failure with the message

2009-02-11 08:33:25,664 [Thread-15] INFO ScriptRunner - junit.report:
2009-02-11 08:33:25,667 [Thread-15] INFO ScriptRunner - [mkdir] Created dir: /a01/home/Construction_temp/reports/ebilling/junit
2009-02-11 08:33:41,604 [Thread-14] WARN ScriptRunner - java.lang.OutOfMemoryError: PermGen space
2009-02-11 08:33:41,605 [Thread-14] WARN ScriptRunner - PermGen space








Resolution:

in the build.bat or build.sh, add more memory to the JVM process like so:

ANT_OPTS="-Xms128m -Xmx512m -XX:MaxPermSize=256m"
export ANT_OPTS=$ANT_OPTS










Thursday, 5 February 2009

Useful Unix Commands - Part 2

A selection of useful find commands

=== Find User ===

fuser displays the PIDs of processes using the specified files or file systems.
fuser command is very useful in getting rid of the .nfs files created when processes are killed. The .nfs* names refer to files that have been deleted but are still being held open by a running process.

You can find .nfs files using ls -la

rm does not work in removing .nfs files - use fuser to find the process that's locking the file and then kill the process

 /usr/sbin/fuser {filename} 


 kill -9 {pid} 


If you stop the processes that have them open, the files will be tidied-up and removed by the file server.


If you're interested a bit of general background follows:

Most operating systems, including UNIX, operate a policy of not actually removing a deleted file (and freeing up it's data blocks) until the last process that has the file open closes it. So, if a running process has a file open and you use the rm(1) command to delete the file the data blocks on the disk will not be freed up by the OS until the process that has the file open closes it.

On a UNIX host using local disk store this behaviour can manifest itself it some seemingly confusing situations. For example, you may wish to free up some space on a file system that's used 900 MB of it's 1GB quota. You have a large file, 200MB say, named myjava.jar that you believe is no longer required, but is actually currently open in your WebLogic server. Not knowing this you delete myjava.jar and do an ls(1) command to see that the file is no longer listed. However, when you use the df(1) command it still reports that 900 MB of it's 1GB quota is used because your WebLogic server still has the file open. When you shutdown the WebLogic server or the server closes the file the disk space will be released and df(1) will report 700MB of it's 1GB is used.

If the file that is removed is on NFS mounted store then it is possible for a file to be deleted on one client whilst still being open on another client. In this situation the same rule of not actually deleting the file until the last process with it open closes it still applies. However, in order for the NFS file handle used by the client that still has the file open not to be broken a filename reference must be maintained. In order to achieve this and remove the files name from the directory ( so it doesn't show up in an ls command output) the NFS file server renames the deleted file to a name beginning '.nfs'. These are the files you are seeing. When the last process with these files open dies or closes them they will be tidied up and removed. Trying to delete them before they are closed will only result in the file being renamed again.



=== Find Class within Jar file ===

To find a class within a binary jar file

 for i in `ls *.jar`; do (jar tf $i  grep '{classname}' ) && echo $i;done   


If you want to search within all subdirectories use this

 for i in `find . -name ‘*.jar’`; do (jar tf $i  grep '{CLASSNAME}' ) && echo $i;done 


=== Find string within file of name ===


find . -name *.xml -exec grep {} \;

example

find . -name web.xml -exec grep -i servlet {} \;



=== Grep within zip file without unzipping it ===


gzip -c -d {file}.gz | grep {string}

Example

gzip -c -d admin_access.log0001_4Dec08_0147.gz | grep -i adq | wc -l







=== Find process using the port ===

The easy way to do this is using netstat passing the port number

netstat -a | grep 61014

If that does not help getting a pid, run this line below


for i in `ls /proc`; do pfiles $i | grep AF_INET | grep 61014 ; done


Output:

pfiles: permission denied: 12363
sockname: AF_INET 0.0.0.0 port: 61014
pfiles: permission denied: 12384

this shows the process appearing in between pids 12363 and 12384 uses that port.

ls /proc
gives the PIDs in order as .. 12363, 12369, 12384 ..


ps -ef grep 12369
wlsuser 12369 7852 0 01:07:40 ? 4:42 /opt/bea/jdk142_05/bin/java -server -DresKBD -Xms512m -Xmx512m -XX:MaxPermSize=

gave the process details which was using the port

Tuesday, 3 February 2009

Useful Unix commands - part 1

CPU Usage
The prstat command displays information about active processes on the system and resource consumption. By default, prstat displays information about all processes sorted by CPU usage.

The prstat -s cpu -n 5 command is used to list the five processes that are consuming the most CPU resources. The -s cpu flag tells prstat to sort the output by CPU usage (This is a default flag set, so can be skipped). The -n 5 flag tells prstat to restrict the output to the top five processes.

Adding the -a option to any prstat command will identify how many processes each user is using, what percent of the CPUs, and how much memory, they are using on a system

prstat -a 

The ps command displays information about currently running processes. Pipe the output to search for specific processes

 ps -ef  | grep java

/usr/ucb/ps -auxwww | grep {pid}

This command gives the complete classpath and start parameters of the process mentioned in pid

Example:

/usr/ucb/ps -auxwww | grep 19138 


user 19138 0.4 2.31272184732136 ? S Jun 01 342:11 /resolve/j2sdk1.4.2_03/bin/java -Xmx1024m -Xms1024m -XX:NewSize=341m -XX:MaxNewSize=341m -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:SurvivorRatio=8 -XX:TargetSurvivorRatio=90 -XX:+DisableExplicitGC -XX:+PrintTenuringDistribution -XX:+PrintGCApplicationConcurrentTime -XX:+PrintGCApplicationStoppedTime -Xloggc:/resolve/CPEE3112/composer/log/pa3.gc -Drmiport=61050 -Dg2config.home=/resolve/CPEE3112/composer/conf -Dg2config.baseipport=61020 -Dg2config.instance=Engine14 -Dg2.processid=3 -cp /resolve/lib/any_custom_libs.jar:/resolve/lib/G2.jar:/resolve/lib/oracle_10_2_0_1_0jdbc.jar com.xyz.platform.Main -recover &





prstat -L -p {pid}

The above cmd gives the summary of lightweight processes which make up the process. More is at an example I gave here

The top command provides an overview of CPU and memory utilization, and a list of the top consumers of CPU, it updates it's display every few seconds so you can monitor continuously. Use http://www.groupsys.com/top/display/ to view details of the stats shown


top

sar -s


Memory Usage
vmstat 5 vmstat reports virtual memory statistics regarding kernel, thread, virtual memory, and disk, trap, and CPU activity. vmstat also helps calculate the average page scan rate.


Below is the vmstat output


vmstat 5



kthr memory page disk faults cpu

r b w swap free re mf pi p fr de sr s0 s1 s2 s3 in sy cs us sy id

0 0 0 11456 4120 1 41 19 1 3 0 2 0 4 0 0 48 112 130 4 14 82

0 0 1 10132 4280 0 4 44 0 0 0 0 0 23 0 0 211 230 144 3 35 62

0 0 1 10132 4616 0 0 20 0 0 0 0 0 19 0 0 150 172 146 3 33 64

0 0 1 10132 5292 0 0 9 0 0 0 0 0 21 0 0 165 105 130 1 21 78

Note: The first line of vmstat shows a cumulative value and must be ignored. sr is the pages scanned by clock algorithm.




On Unix, to find out how much RAM is present on a machine, use

prtconf grep 'Memory size:'


On Linux, the same is done using

free -m


Disk Space

df -ek

du -h

How to connect Raspberry Pi Pico to a external temperature sensor(DHT11 or DHT22)

How to connect Raspberry Pi to DHT 11 / DHT 22   Connect your DHT11 sensor to the Pico accordingly -   Left pin (Signal) - GPIO Pin 22 (or a...