Kushal Das

FOSS and life. Kushal Das talks here.

kushal76uaid62oup5774umh654scnu5dwzh4u2534qxhcbi4wbab3ad.onion

Getting md5

Want to get MD5 ? Examples are in Python and Java

In Python: >>> import md5 >>> print md5.md5("kushal").hexdigest() '6ec44a1207a3d9506418c034679087b6' Easy isn't it !!

Now let us do the same in JAVA:

import java.security.MessageDigest;
import java.lang.String;

class MD5 {
    public static void main(String args[]) {
        try {
            MessageDigest digest = MessageDigest.getInstance("MD5");
            digest.update("kushal".getBytes());
            System.out.println(byteArrayToHexString(digest.digest()));
        }
        catch (Exception e){
            e.printStackTrace();
        }
        }

    public static String byteArrayToHexString(byte in[]) {
        byte ch = 0x00;
        int i = 0; 
        if (in == null || in.length <= 0)
            return null;
        String pseudo[] = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"};
        StringBuffer out = new StringBuffer(in.length * 2);
    
        while (i < in.length) {
            ch = (byte) (in[i] & 0xF0); 
            ch = (byte) (ch >>> 4);
            ch = (byte) (ch & 0x0F);    
            out.append(pseudo[ (int) ch]); 
            ch = (byte) (in[i] & 0x0F); 
            out.append(pseudo[ (int) ch]); 
            i++;
        }
        String rslt = new String(out);
        return rslt;
    }    
}

I found that code on byteArrayToHexString somewhere in the net.

Update: As ignacio pointed in the comments that the md5 module is deprecated in Python 2.5, we have to use hashlib module instead. >>> import hashlib >>> h = hashlib.md5() >>> h.update('kushal') >>> h.hexdigest() '6ec44a1207a3d9506418c034679087b6'

A nice article for the students who want to move from the blue world of "T****C" to GCC using KDevelop

Here is a nice tutorial for the beginners who wants to move to GCC/Free Software world using KDevelop. The KDevelop-Project was founded in 1998 to build up an easy to use IDE (Integrated Development Environment) for KDE. You can write in C/C++/Java/Qt/Python and many other languages in it. At the end of the tutorial , there is a nice shortcut table for KDevelop.

Shell scripts and me

I always feared shell scripts when I was in college. Always knew that it is very powerful if I use it properly, I never did.

Two days back, in I was trying to help one of my college junior to setup Qt4 and the environment to run it. I told him to follow this page. But Pradeepto said the idea of having another user is not so good. and he said:

Apr 30 00:48:21 pradeepto: you can even do make sure that as you changedirectories,
the env-vars are set automagically.

So, I tried to something like that, asked few questions on #bash about how to write a function with same name of a shell command and then call the actual shell command. So, got the shell-builtin-command 'builtin' which executes other shell builtins. Also asked lots of questions to Jace about shell programming :p

My target was, as I change my directory to any directory named 'pyqt4' or sub-directories under it all environment variables should change accordingly to run Qt4 or PyQt4 codes and in other directories the normal environment should stay to run Qt3 :)

The result in my .bashrc :

export tQTDIR="$QTDIR"

export tPATH="$PATH"

export tMANPATH="$MANPATH"

export tLD_LIBRARY_PATH="$LD_LIBRARY_PATH"

export tPKG_CONFIG_PATH="$PKG_CONFIG_PATH"

export tQTINC="$QTINC"

export tQTLIB="$QTLIB"

export eFlag=0changePath()
changePath()
{QTDIR="$tQTDIR"

PATH="$tPATH"

MANPATH="$tMANPATH"

LD_LIBRARY_PATH="$tLD_LIBRARY_PATH"

PKG_CONFIG_PATH="$tPKG_CONFIG_PATH"

QTLIB="$tQTLIB"

QTINC="$tQTINC"

export QTDIR PATH MANPATH LD_LIBRARY_PATH PKG_CONFIG_PATH QTINC QTLIB

}

cd ()

{

if [ "$#" -eq "0" ]

then

if [ "$eFlag" -eq "1" ]

then

changePath

export eFlag=0

fi

builtin cd

else

bname=`echo "$1"|grep pyqt4 `

if [ "${bname}" = "$1" ]

then

QTDIR=/home/kdedev/src/kde/qt-copy

PATH=$QTDIR/bin:$PATH

MANPATH=$QTDIR/doc/man:$MANPATH

LD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATH

PKG_CONFIG_PATH=$QTDIR/lib/pkgconfig:$PKG_CONFIG_PATH

QTINC=$QTDIR/include

QTLIB=$QTDIR/lib

export QTDIR PATH MANPATH LD_LIBRARY_PATH PKG_CONFIG_PATH QTINC QTLIB

export eFlag=1

builtin cd "$1"

else

if [ "$1" = ".." ]

then

builtin cd "$1"

dname=`pwd`

bname=`echo "$dname"|grep pyqt4 `

if [ "$bname" != "$dname" ]

then

if [ "$eFlag" -eq "1" ]

then

changePath

export eFlag=0

fi

fi

else

if [ "$eFlag" -eq "1" ]

then

changePath

export eFlag=0

fi

builtin cd "$1"

fi

fi

fi

}

I think the code is not so much readable in my blog :)

Update: Pradeepto asked me to upload the code as a file, so here it is. Just copy paste the contents of this file into your $HOME/.bashrc .

Kalzium tutorial

After two days of work , Kalzium tutorial in Bengali is ready. You can download it from here. Yesterday night, I gave more than 25 takes on this, either sound is not coming properly, or some problem in mixing. I need a good app which can help me in the process of dubbing the tutorials. The video is in ogg theora format, audio can I get in any format. Can anyone please point me to some good app?

Recordmydesktop is rocking as far as the video is concerned, but the sound mixing is not working properly.

KBruch tutorial

Writing is always a difficult task for me. So, after I learned about Podcasting from Kiruba , thought of giving it a try. My last post was that test only Now another test, a tutorial of KBruch using screencasting with my bengali voice. Failed few times to speak proper bengali, but that problem will go out in the coming ones.The result on youtube.

You can also download it from here (ogg) or check it in google video.

Many people laughed on my first test, they will on this also. But I don't have any problem, you guys should have some moments to laugh in your busy life.