Saturday, December 24, 2011

Dinner at Savor Restaurant

The 'Food n Cruze' idea of Savor is a unique one and last week we have planned to Enjoy the Buffet in Savor with Cruise Ride. Click here to see the slideshow.


rizzz86

Sunday, October 30, 2011

Manually Install Erlang on Linux

Erlang is a programming language used to build massively scalable soft real-time systems with requirements on high availability. Some of its uses are in telecoms, banking, e-commerce, computer telephony and instant messaging. Erlang's runtime system has built-in support for concurrency, distribution and fault tolerance.

Applications that are built on Erlang also required Erlang's runtime for execution. Last week I got a chance to work on a Message Broker 'RabbitMQ' (will discuss it in other post) which is built on Erlang. So to get RabbitMQ Server installed on my machine I have to setup Erlang first. This post contains the steps for installing RabbitMQ Server manually on Linux machine. Following are the steps:

Get the Erlang package that you need to install
  • In my case I have otp_src_R14B02.tar.gz
Unzip the package:
  • tar xvzf otp_src_R14B02.tar.gz
Go to folder:
  • cd otp_src_R14B02/
Following files may be required to install on your OS before running the configuration file:

If it gives gcc compiler error then install gcc compiler with following command:
  • sudo yum install gcc gcc-c++ autoconf automake
  • sudo yum install make
  • sudo yum install ncurses-devel
For Ubuntu following command will be used:
  • sudo apt-get install build-essential
  • sudo apt-get install libncurses5 libncurses5-dev
Run cofigure File
  • ./configure
After running the configuration file, run the make command on same folder:
  • make
And in the and execute following command:
  • sudo make install
This will install Erlang on Linux and it can be tested using following command:
  • erl
It will show following lines:

Erlang R14B02 (erts-5.8.3) [source] [smp:4:4] [rq:4] [async-threads:0] [hipe] [kernel-poll:false]

Eshell V5.8.3  (abort with ^G)
1>

rizzz86

Saturday, October 15, 2011

My Experience of Installing MongoDB on Ubuntu

In my last post I have write some very basic and initial points related to MongoDB. That was my initial observation of what MongoDB is and what are its basic features.

This article does not contains the detailed step by step tutorial of how to install MongoDB on Ubuntu. There are already lots of articles available on the installation of MongoDB on Ubuntu &Windows operating systems. In this post I am going to write my experience of Installing MongoDB on Ubuntu.

There are two common ways of installing any kind of software on Ubuntu. One is by using the "Ubuntu Software Center" and other is to download the package and install it manually. Option one is commonly used by users as it is very simple and it automatically download and install the target software on Ubuntu. In the case of MongoDB both option can be used for installation.

For testing purpose I have installed MongoDB using the Software Center (you can also use apt-get command that also download and install package from Software Center). Initially it works good by using it from terminal. I can able to start and stop MongoDB and execute different types of queries. The problem begins when I try to use MongoDB programmaticaly. I cannot able to connect with MongoDB using Java and Eclipse IDE even MongoDB is running and can be used from terminal. So, I have removed all the packages of MongoDB and install it manually. After that I am able to use it via terminal as well as programmatically.

This seems to be something related to version issue as also mentioned on this link. If someone knows what is the actual reason of this different behavior on different installation options do comment here. This is what I have experienced when installing and using MongoDB on Ubuntu.

rizzz86

Sunday, October 9, 2011

MongoDB: {name:"mongo", type:"DB"}

“MongoDB” as the name suggest, is a database that can be used to store data and apply other operations on the data later on. It is not a relational database like (MySQL, Oracle, MSSQL etc), but it provides all the basic operations that eases developer’s life in playing with the stored content. The name is a bit funny for me when I first heard it, but really it is built on some serious concept that opens number of questions of something alternative of relational databases. The concept is of NoSql / non-relational database.

MongoDB (from "humongous") is a scalable, high-performance, open source, document-oriented database. Written in C++

RDBMS has ruled the database world alone for a long time and always remains the only option for most of the software industry to go for it as their first option. Yes, lots of questions are there to choose which RDBMS to use and how the data will be structured within it. With some powerful concept of querying, maintain the integrity, indexing of data etc within RDBMS how come MongoDB’s concept will compete with it? What is the concept on which MongoDB is built? Is MongoDB fully replaceable to RDBMS? Are there other databases built on the same concept? Many more questions are there in this debate, so just have a look how MongoDB is different from relational databases.

MongoDB store data in documents. Yes, a document that have key-value pair. There is a predefined structure of MongoDB that starts with Database -> Collections -> Documents & -> Fields. So there is not any brainstorming sessions on how to structure our data. Just answer How many collections do we have, and what are they?.

One of the most important features of MongoDB is that it provided Indexing on data. This feature makes it different from other No SQL databases. It also support to query data from database. 

 If you're moving to MongoDB from a relational database, you'll find that many SQL queries translate easily to MongoDB's document-based query language. 

Other important features include Replication, Auto-Sharding, Batch Processing etc. Detail of each feature will be part of other posts as soon as I explore them and create some examples.


rizzz86


 

Wednesday, October 5, 2011

JAVA: Date and Calendar

This is not something new but something of very common use in most of the projects. In this post I am going to write some date, time and calendar functions that are commonly used as utility. From next time I will copy them from this post rather than code them again.

To get a Date in any Format the SimpleDateFormat Class is used. Following snippet will return current date in provided format in SimpleDateFormat argument.

Date date = new Date();    
DateFormat dateFormatter = new SimpleDateFormat("dd");    
String formattedDate = dateFormatter.format(date);


Format "dd" is used to get the date number from date

Format "yyyy" is used to get the year number from date

Format "MM" is used to get the month number from date

Format "MMMM" is used to get the month name from date

This method will return the date of targeted format from source format.

    String dt = dateString;  // Start date
    SimpleDateFormat sdf = null;
    try {
            sdf = new SimpleDateFormat(sourceFormat);
            Date date = sdf.parse(dt);
    
            sdf  = new SimpleDateFormat(targetFormat);
            dt = sdf.format(date);  // dt is now in the new date format            
    } catch (ParseException e) {
        e.printStackTrace();
    }



To get Number of Days in a Month we will take help from Calendar Class here. Following method will be usd to get number of days in a month.

public static int getNumberOfDaysInMonth(int screenMonth){
      Calendar calendar = Calendar.getInstance();
      int year = Integer.valueOf(getYearNumber());
      int month = screenMonth;
      int date = 1;
      calendar.set(year, month, date);
      int days = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);        
      
      return days;
}


This method will return Month Name from month number. Calendar is used here as well.

public static String getMonthNameByMonthNumber(int currentMonthNumber) {
    String dt;
    Calendar c = Calendar.getInstance();
    c.set(Calendar.MONTH, currentMonthNumber);
    c.add(Calendar.MONTH, 0);  // number of days to add
    
    SimpleDateFormat sdf  = new SimpleDateFormat("MMMM");
    dt = sdf.format(c.getTime());  // dt is now the new date        
    return dt;
}


To get the First Day of month following method can be used.

public static String getFirstDayOfMonth(int month) {
    Calendar c = Calendar.getInstance();
    c.set(Calendar.MONTH, month);
    c.set(Calendar.DATE, 1);

    DateFormat f = new SimpleDateFormat("EEE");        
    return f.format(c.getTime());
}


Similarly to get the first date of week Calendar Class is used.

public static int getFirstDateOfWeek() {
    Calendar c = Calendar.getInstance();
    c.set(Calendar.WEEK_OF_YEAR, Calendar.WEEK_OF_MONTH);
    c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek());

    DateFormat f = new SimpleDateFormat("dd");
    String cc = f.format(c.getTime());

    // Plus 1 is done to get the Monday Date instead of Sunday
    return Integer.valueOf(cc) + 1;
}


There are many other methods that can be used commmonly. I will keep updating this post when ever I got something new. Also do comment If there is any method you want to add here or If any of them can be implemented in much better way.

rizzz86

Sunday, October 2, 2011

Hello Post !


I am writing on this blog after a long time due to some busy schedule from last 4 months. I have switched my job and joined a new software company with in this time frame. Also worked on lots of new tools and technologies that I have to blog on. So lots of topics are in mind to blog and now thinking to give some time to blogging in this busy schedule. I have also completed my MS (Software Engineering) and now looking forward to give some certifications as well.

rizzz86

Monday, March 7, 2011

Dinner at Ambala Corniche

"Ambala" is a newly opened restaurant near sea view - Clifton, Karachi. In comparison with other restaurants on the same street (including Sajjad, Afridi Inn, Hot Bite etc)  "Ambala" is the most well managed and also have a pleasing environment.

Click on the following image to see slideshow by smhumayun.


rizzz86

Monday, February 28, 2011

Split a String with Dot "." in JAVA


In JAVA we can split a String with Dot "." using a split() function. But it can be done in a different way as compared to other characters. Dot "." is a reserved character in regular expression, hence it will not treat the split on dot the same way.

Following code can be used to split a string by dot.

String stringWithDot = "rizzz86.blogspot.com"; 
String[] stringArray = stringWithDot.split("\\.");

Double backslash will do the work where one slash is work as a escape character.

rizzz86

Thursday, January 13, 2011

Iterate over JAVA HashMap in FreeMarker

Java HashMap can be iterated in FreeMarker by using a <#list> tag as follows:

<#list hashMap?keys as key>
        ${key}=${hashMap[key]}
<#list>


If you are using the above code with default FreeMarker Configuration then there would be some different behavior during iteration. For example if the HashMap is:

HashMap hashMap = new HashMap();
hashMap.put("1","one");
hashMap.put("2","two"); 

By iterating on hashMap with default Configuration it will output following keys in result:

put
remove
entrySet
hashCode
productElement
clear
isEmpty
1
values
empty
underlying
productElements
copy
getClass
get
copy$default$1
equals
productPrefix
class
canEqual
keySet
size
2
containsKey
productArity
containsValue
productIterator
toString
putAll        


This result shows that the iteration is done on all the available hashMap properties.

To get rid of this you have to set the FreeMarker Configuration as follows:


Configuration configuration = new Configuration();
BeansWrapper wrapper = (BeansWrapper) this.configuration.getObjectWrapper();
wrapper.setSimpleMapWrapper(true);
this.configuration.setObjectWrapper(wrapper);

Here the BeanWrapper's simpleMapWrapper property is set as 'true'. After setting this configuration the results over iterating on hashMap will give only the defined key-value pair.

rizzz86

Wednesday, January 12, 2011

MD5 Hashing in J2ME

MD5 (Message Digest) is a hashing algorithm that can be used to ensure data integrity, save and protect passwords/codes, generate unique keys of limited length against a long literal etc. It takes input as String and generates the Hash of that string.

In JAVA there is a built-in MD5 support in its Standard Edition (J2SE). But if we talk about its Micro Edition (J2ME) their is no support for MD5. The package of JAVA Standard Edition can also be used in Micro Edition if and only if the platform supports the SATSA-Crypto Optional Package (How to know that your platform supports SATSA-Crypto).

I have found and tested the Third-Party implementation that can generate MD5 hash and can be used in JAVA Micro Edition. You can get the MD5 source files from here.

rizzz86