nepali english date conversion logic - working java code

My friend Manoj has written about Nepali-English date conversion in this post. Take a look :

He has explained the algorithm in detail about how to convert English dates into Nepali dates with java code.

android media player - play file http rtsp streams

MediaPlayer class ( ) can be used to control playback of audio/video files and streams.  


String url = "http://........"; // your media URL here
//String url = "rtsp://........"; 
//String url = "file:///sdcard/intro.3gp"; //local file

MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.setDataSource(url); //Sets the data source (file-path or http/rtsp URL) to use

To play audio file, you can simply call mediaPlayer.start();


For the Audio Stream (http, rtsp)

After setting the datasource and the display surface, you need to either call prepare() or prepareAsync().
For streams, you should call prepareAsync(), which returns immediately, rather than blocking until enough data has been buffered.

A MediaPlayer object must first enter the Prepared state before playback can be started. MediaPlayer.OnPreparedListener defines Interfaces  for a callback to be invoked when the media source is ready for playback.

//You can show progress dialog here untill it prepared to play

mediaPlayer.setOnPreparedListener(new OnPreparedListener() {
        public void onPrepared(MediaPlayer mp) {
            //Called when the media file is ready for playback.
    mediaPlayer.setOnErrorListener(new OnErrorListener() {
        public boolean onError(MediaPlayer mp, int what, int extra) {
            return false;

java spring - read properties file variable from xml -PropertyPlaceholderConfigurer

Java springframework xml configuration file - how to read properties file variables from spring xml :
We have to use PropertyPlaceholderConfigurer bean for this.

1).properties file location -

  • src/main/resource @ maven managed project
  • OR at classpath

2)The xml code to initialize/read properties file, 

hibernate annotation inheritance mappedsuperclass - common columns in super class

When you are using annotations for hibernate object relational mapping, there might be the case that we need to abstract out some common columns that goes into all table definitions. These columns might be ID, DFlag, LastModifiedDate etc..
In such case we can take advantage of @MappedSuperclass annotation to achieve inheritance in hibernate annotation.

Example :

Super class BaseTable that contains common column definitions:

public abstract class BaseTable {
    @Column(name = "id")
    private int id;

    @Column(name = "dflag")
    private int dFlag;

    @Column(name = "lastmodifieddate")
    private Date lastModifiedDate;
    //other required columns

Extending it to use in other tables :

@Table(name = "LoginUser")
public class LoginUser extends BaseTable  implements Serializable{

    private static final long serialVersionUID = -1920053571118011085L;

    @Column(name = "username")
    private String username;

    @Column(name = "password")
    private String password;

    @Column(name = "invalidCount")
    private int invalidCount;
    //other required tables

It works !

mysql hibernate unicode support - character set, collate

I just did following configurations to achieve Unicode support in my Java+Hibernate+MySQL project.

Configuring MySQL to support Unicode - set Character Set and Collate as :
 COLLATE "utf8_general_ci";

NOTE : You Need to do "ALTER TABLE" instead of "CREATE TABLE", 
      if you are going to modify existing DB.

Hibernate JDBC connection string :

Hibernate Configuration:
    <property name="hibernate.connection.charSet">UTF-8</property>
    <property name="hibernate.connection.characterEncoding">UTF-8</property>
    <property name="hibernate.connection.useUnicode">true</property>

Java code to find public IP address (servlet and client side code)

Java code to find public IP address :

URL url= new URL("");
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
String ip = in.readLine();
System.out.println("IP : "+ip);

I created a simple servlet app on google app engine  and posted at .

The servlet code returns the public address of client, it looks like :

public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
  PrintWriter out = resp.getWriter();
  // Get client's IP address
  String addr = req.getRemoteAddr();

Java Script code that disables right click and prevents selecting the text on web page.

Java Script code that disables right click and selecting the text on web page.
Put the following code in your <body>........</body> tag.
function disableselect(e){return false;}
function reEnable(){return true;}
document.onselectstart=new Function (){return false;}
if (window.sidebar){

document.oncontextmenu = function(){return false;}
if(document.layers) {
    window.onmousedown = function(e){
        return false;
}else {
    document.onmousedown = function(){return false;}

For Blogger template,

  • Search for </body> in the template code
  • paste the above script just before </body> tage.
Enjoy !
You are now safe from website article thief.

facebook security bug - change password of a active user - without knowing original password

change password of a active user -without knowing original password - security bug - Facebook allows to change password in active login without entering current password

As of May 2012, Facebook has over 900 million active users. Security and privacy should be the number one concern of Facebook Inc. But I just found one BUG in Facebook security system.

This might (not) be a security bug in Facebook. And probably be fixed by Facebook when you tried to do the same, because I am going to report this to Facebook.

All the steps below that I am going to share - deals with changing someone else’s password without entering their previous/current password. I have never seen or write code for “login preference change” that allows to change password without entering previous password or other information.  I was shocked to know that Facebook allows it. I was just playing with Security option in Facebook’s Account setting And found that.

Steps that I followed :

eclipse proguard maven project configuration - java obfuscate

I am going to describe how can can configure proguard and maven to obfuscate a java project. If you need help on how to configure maven project in eclipse see my earlier post.

A)Project configs
    <!-- Project configs -->


Speech Recognition Java Code - HMM VQ MFCC ( Hidden markov model, Vector Quantization and Mel Filter Cepstral Coefficient)

Hi everyone,
I have shared speech recognition code in google code :

You can find complete source code for speech recognition using  HMM, VQ, MFCC ( Hidden markov model, Vector Quantization and Mel Filter Cepstral Coefficient). Feel free to use and modify this code.

The project report that accompanies this code is here.

Introduction to the project :