Posts

Spring Boot Docker Maven Using "io.fabric8" plugin

What is Docker?  Docker is the company driving the container movement and the only container platform provider to address every application across the hybrid cloud. Today’s businesses are under pressure to digitally transform but are constrained by existing applications and infrastructure while rationalizing an increasingly diverse portfolio of clouds, data centers, and application architectures. Docker enables true independence between applications and infrastructure and developers and IT ops to unlock their potential and creates a model for better collaboration and innovation. You can download the project from the github: https://github.com/SudharsanThumattiSathiamoorthy/docker-demo fabric8io plugin: 
This is a Maven plugin for managing Docker images and containers.  
Let's go into the example.  Below is the content of the plugin in pom.xml : io.fabric8 docker-maven-plugin 0.25.0 registry.hub.docker.com/sudharsanthumatti YOUR_GIT_H...

Segregate 0's, 1's and 2's

Efficient way of segregating 0's, 1's and 2's in a given array. Input:    0, 1, 1, 0, 1, 2, 1, 2, 0, 0, 0, 1 Output:   0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2 Java Program: package com.sudharsan.examples; import java.util.Arrays; public class Seggrega012 {     static public void main( final String[] args ) {         int a [] = {0, 1, 1, 0, 1, 2, 1, 2, 0, 0, 0, 1};        int left = 0, mid =0 ;        int right = a . length -1;        while ( mid <= right ) {            switch ( a [ mid ]) {            case 0:                swap( a , left , mid );                left ++;                mid ++;          ...

Longest Common Subsequence

Longest common subsequence is the common characters across two strings. Example Input 1 :  abcde Input 2 :  cdfge Output : 3 (c, d, e) Java Program: package com.sudharsan.examples; import java.util.HashSet; import java.util.Set; public class LongestCommonSubsequence {     public static void main( final String[] args ) {         final String s1 = "abcde" ;         final String s2 = "cdfge" ;         final Set<Character> c = new HashSet<>();         System. out .println(lcs( s1 , s2 , s1 .length(), s2 .length(), c ));         System. out .println( c );     }     private static int lcs( final String s1 ,             final String s2 ,             final int m ,         ...

Heap Sort

Time Complexity : O(n logn) Java Program: package com.sudharsan.examples; import java.util.Arrays; public class HeapSort {     private static void heapify( int [] a , int i ) {         int lc = i * 2 + 1;         int rc = i * 2 + 2;         int largest = i ;         if ( lc < a . length && a [ largest ] < a [ lc ]) {             largest = lc ;         }         if ( rc < a . length && a [ largest ] < a [ rc ]) {             largest = rc ;         }         if ( largest != i ) {             swap( a , i , largest );             heapify( a , largest );         }   ...

Median of two arrays

import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; public class MedianOfTwoArrays { public static void main(final String[] args) { findMedianSortedArrays(Arrays.asList(-50, -41, -40, -19, 5, 21, 28), Arrays.asList(-50, -21, -10)); findMedianSortedArrays(Arrays.asList(0, 23), Collections.emptyList()); } public static double findMedianSortedArrays(final List<Integer> a, final List<Integer> b) { final List<Integer> temp = new ArrayList<>(); int sizeA = a.size() == 0 ? 0 : a.size(); int sizeB = b.size() == 0 ? 0 : b.size(); int i = 0, j = 0; // Merge both the list into single list. while (i != sizeA && j != sizeB) { if (a.get(i) <= b.get(j)) { temp.add(a.get(i)); i++; } else { temp.add(b.get(j)); j++; } } while (i <= sizeA - 1) { temp.add(a.get(i)); i++; } while (j <= sizeB - 1) { temp.add(b.get(j)...

Convert Infix into Postfix expression

import  java.util.Stack; public   class  InfixToPostfix { private   final   static  Stack<Character>  stack  =  new  Stack<>(); static   boolean  isOperand( final   char   c ) { if  (( c  >=  'a'  &&  c  <=  'z' ) || ( c  >= 0 &&  c  <= 9)) { return   true ; } return   false ; } static   boolean  isOperator( final   char   c ) { switch  ( c ) { case   '+' : case   '-' : case   '*' : case   '/' : return   true ; } return   false ; } static   int  prec( final   char   c ) { switch ( c ) { case   '+' : case   '-' : return  1; case   '/' : case   '*' : return  2; case   '^' : return  3; ...

Producer Consumer Using Blocking Queue

package com.sudharsan.examples; import java.util.ArrayList; import java.util.List; class Producer implements Runnable { private List queue; private int threshold; public Producer(final List queue, int threshold) { this.queue = queue; this.threshold = threshold; } @Override public void run() { for (int i = 0; i queue; private int threshold; Consumer(final List queue, final int threshold) { this.queue = queue; this.threshold = threshold; } @Override public void run() { for (int i = 0; i list = new ArrayList (); final Producer1 producer = new Producer1(list, 20); final Consumer1 consumer = new Consumer1(list, 20); final Thread producerThread = new Thread(producer, "Producer"); final Thread consumerThread = new Thread(consumer, "Consimer"); producerThread.start(); consumerThread.start(); } }