A Developer's Diary

Mar 31, 2008

Shell Scripting - Rotating Progress Bar

The echo -e command is used to change the term color


echo -e "\E[40;32m\b\c"
#Changes the term color to green with black background



#!/bin/bash

function success_banner()

{
echo -e "\E[40;32m\b\c"
echo -e "[OK]"
echo -e "\E[40;37m"

}

function progress_banner()
{
echo ""
echo "##############################################################"

echo ""
echo -e "Step: $1 \b\c"
}

function rotate_line(){

INTERVAL=1
timecount="0"
while :
do
timecount=`expr $timecount + 1`

case $timecount in
"1")
echo -e "-\b\c"

sleep $INTERVAL
;;
"2")
echo -e '\\'"\b\c"

sleep $INTERVAL
;;
"3")
echo -e "|\b\c"

sleep $INTERVAL
;;
"4")
echo -e "/\b\c"

sleep $INTERVAL
;;
*)
timecount="0" # Reset the count to 0

esac
done
}

function start_rotation(){
rotate_line &

}

function stop_rotation(){
rotate_line_pid=$!
kill -9 $rotate_line_pid

echo -e "\b\b\b"
}

progress_banner Rotation_Bar_Started
start_rotation
sleep 5
stop_rotation
success_banner Ok




Read more ...

Mar 26, 2008

Finding Linux Version

Linux Release Version can be obtained by executing


cat /etc/redhat-release


For getting linux kernel versions execute

uname -a or uname -r

Read more ...

Mar 2, 2008

Accessing 32 bit DLLs' from 64 bit code

A 64-bit process cannot load a 32-bit module into its process space, and a 32-bit processes cannot load a 64-bit module into its process space. The only way that communication can happen between 32-bit and 64-bit modules is through interprocess communication (IPC).

In other words, 32-bit and 64-bit processes can exchange data using IPC techniques such as out-of-process COM, sockets, Windows messages or memory mapped files.

A 32-bit software product contains the main module which calls into the DLL. As long as both the main module and the DLL are 32-bit processes the product can run on both 32-bit and 64-bit platforms. If both the main module and the DLL are migrated to the 64-bit platform, then they can both run in a native 64-bit process. However if only the main module is migrated to 64-bit, it will not be able to load the 32-bit DLL.
The best way to migrate such a product to a 64-bit platform is to migrate both the main module and the dependency DLL, but if the dependency DLL cannot be migrated then it cannot be loaded into the 64-bit process and the application won't work.

Alignment in Memory: The alignment of data in memory is different for 32-bit and 64-bit processes. This means that your more complicated custom data structures may be serialized by a 32-bit process in a way that is different to that expected by a 64-bit process, and vice versa.

Datatype Size: The differences are mainly in pointers which are 32 bits long in 32-bit platform and 64 bits long in 64-bit platform. The pointer-derived data types such as HANDLE and HWND (Windows) are also different between 32-bit and 64-bit versions.

More on Accessing 32 bit DLLs' from 64 bit code

Read more ...

Knowing Default Parameters in C++ and Java

C++ allows functions to have default parameters. This is useful when a parameter should have a specified value when the caller does not supply any value.

class DefParam{
    public:

        //Declare the default parameter(s) in function decalaration
        void printVal(int x=10);
};

//Don't repeat the default parameter in function definition
void DefParam::printVal(int val){
    printf("Val = %d\n",val);
}

int main(){
    DefParam obj;
    obj.printVal(); //Passes 10 to printVal()

    obj.printVal(25); //Passes 25 to printVal()
    return 0;
}

$ ./a.exe
Val = 10
Val = 25

Note: Java does not provide default parameter values, but you can use overloading to achieve the same effects.
Read more ...