Thursday, August 16, 2012

Configuration management with Mercurial SCM


The increase of globalization has led to more organizations support everywhere and deploy anywhere in the world. From an experience of having been involved in providing deployment services, I've found that companies can waste lots of time and cost while trying to maintain the software installed at the customer site. 
If you have done that before, you must remember the minute you were sitting in front of your desk trying to remember which configuration files have been changed or what files been updated the last time you have been there.
It doesn’t matter what your role in the organization is, but as soon as you get in the doors at the customer’s office, you are the face of the organization and the customer trusts you. Trust is crucial in relationships – but this is for another discussion.
It's not your fault, just two hours before your flight back home the development team fixed a bug in a high severity state and you couldn’t leave your customer with a faulty system, so you just done what have to be done - replace the file or modify another one, test it and run to the wrap-up meeting.

An efficient management tool and a simple workflow can help organizations complete deployment activities faster and no matter what the size of the organization is.
Let’s get to the point, I suggest using Mercurial for that purpose (of course you can use others…).

Mercurial as stated in their website, is a free, distributed source control management tool. It handles projects of any size and every clone contains the whole project history and almost all actions are local.
You can download the Mercurial installer from here, binary packages are available for almost all platforms (Windows, Linux and others).
Just double-click the exe file to setup Mercurial and add the main Mercurial folder path to the “PATH” environment variable.
I suggest downloading TortoiseHG (available for non-windows platforms as well), which allows to interact with your Mercurial project in a friendly GUI other than using the command line version.
Right after all installed successfully, perform the following:
1.     hg init” in software folder to initiate the repository.
2.     hg add” to add all files to the local repository.
Note that Mercurial saves a local copy of tracked changes in hidden folders at the project folder. If there are any folders, large files or log files that you don’t like to track changes in, use the .hgignore file (http://www.selenic.com/mercurial/hgignore.5.html).
3.     hg commit –m <message>” to commit all files added (except the files/folders stated in the .hgignore file). Note that last version tagged as “tip”.
4.     Tags add a name to a revision and are part of the history.
Mark release changes by using the Tag (“hg tag –r 1 version1.4”).
5.     For further information read the Mercurial guide: http://mercurial.selenic.com/guide/

That’s it! From now on, you can track what have been changed and what files have been replaced. Next time you would like to make any changes, just read the repository logs and see what have been changed.

Good Luck



Tuesday, August 14, 2012

Min-Max Heap - Java Implementation

It is possible to build a Min-Max Heap data structure that will perform the following actions with an efficient time complexity:
- Insert a new item in O(lgn) - Find Maximum key in O(1) - Find Minimum key in O(1) - Delete Maximum node in O(lgn) - Delete Minimum node in O(lgn)
The proposed data structure holds Minimum and Maximum heaps with references to each other. The heaps are built as TreeNode[] array objects which hold a set of TreeNode POJO objects (TreeNode fields are: value, max reference and min reference).
maxHeap - is the Maximum Heap. maxHeap - is the Maximum Heap Heap.java - to hold the Min-Max Heaps and actions:
TreeNode POJO: