Sunday, September 12, 2010

Setting up Apache Ant 1.8 in Ubuntu 10.04

There seems to be a lot of incomplete tutorials out there relative to installation and configuration of Ant on Ubuntu. Here is how to do it correctly.

Open .bashrc and add the following lines

#Setting some paths
export ANT_HOME=$HOME/tools/apache-ant-1.8.1
export JAVA_HOME=/usr/lib/jvm/java-6-sun
# Add stuff to the path and export it in one step
export PATH=$PATH:$ANT_HOME/bin:$JAVA_HOME

 

Prerequisites: download ant and expant that into a folder (I use $HOME/tools) for all my tools.

rohit@lenovo:~$ ant -version
Apache Ant version 1.8.1 compiled on April 30 2010

Done.

Point-to-point SOA

p, li { white-space: pre-wrap; }

Service Oriented Architectures realizations are coupling departments within large organizations. Web-Services are being developed without compliance or guidance from any actionable enterprise architecture design. Without a full soup-to-nuts solution architecture template available to teams, well-intentioned developers are unfortunately creating a web of point-to-point systems architectures with SOA tools and technologies.

Vendors, marketing, tooling and technology isn't helping integration architectures evolve and arrive at the optimal quality attribute tradeoffs. Most quality attributes, like loose coupling, high cohesion, performance, scalability etc are skewing negatively.

It cannot be stressed enough that SOA is more dangerous with out a proper design in place, than no SOA at all. WSDL, SOAP, XSD, REST etc are still not properly understood or realized appropriately in many organizations. Basic systems architectures are unable to evolve due to a significant lack of skills, organizational constraints, poor processes, personnel and such.

Thursday, September 2, 2010

A Combination Algorithm

The problem: Write an algorithm that can provide combinations of a given word. The combinations need not contain a new word with the same letters.

Input: ABCDE

OUTPUT: ABCDE, ABCD, BCDE, ABC, BCD, CDE, AB, BC, CD, DE etc.

There are several algorithms out there that describe how to create effective combinations, SEPA does permutations, bubble sort and nested loops etc.

After spending some time looking for what’s been done - the one I liked the most was as follows: [0,0,0], [0,0,1], [0,1,1] [1,1,1]: null, A, AB ABC etc.

Incrementing decimals, start with zero, get a binary representation and map it to the array positions. This will give the combinations in constant time. A very efficient algorithm.

   /**
    * Take a word and return a collection of combinations
    * @param sortedWord
    * @return
    */
   public Collection<String> generateCombinations(String sortedWord)
   {
       Collection<String> c=new HashSet<String>();
       char[] broken=sortedWord.toCharArray();
       int combinationLength=new Double(Math.pow(2L, (new Long(sortedWord.length())).longValue())).intValue();
    //  System.out.println("Combination len="+combinationLength);
       for(int loop=combinationLength-1;loop>0;loop--)
       {
       String binary=fillWithZeros(Long.toBinaryString(loop),sortedWord.length());
       char[] bins=binary.toCharArray();
       StringBuffer wb=new StringBuffer();
       for(int a=0;a<bins.length;a++)
       {
           Integer binValue=new Integer(""+bins[a]);
           if(binValue.intValue()==1)
           {
            wb.append(broken[a]);  
           }
       }
       c.add(wb.toString());
       }

 

While there is a nested loop, the loops can be replaced with other techniques.

This is a very high performance combination creation technique. Comments/Improvements are welcome.