Posts

Comparison of Cloud Services

Comparison of services of AWS, Azure and GCP AWS Azure GCP EC2 Virtual Machines Compute Engine S3 Blob Storage Storage EC2 Container Service Container Service Kubernetes Engine Elastic Beanstalk Azure App Service App Engine Dynomo DB Cosmos DB Cloud Datastore RDS SQL Database BigQuery Lambda Azure Functions Cloud Functions

Kubernetes vs. Docker : Real meaning?

“Kubernetes vs. Docker” is a phrase that we hear more and more as Kubernetes becomes more popular as a container orchestration solution. Docker and Kubernetes aren’t direct competitors. "Kubernetes vs. Docker Swarm" are in the completion The rise of use of Docker Containers and container platforms provide more advantages over virtualization. Isolation of resources is done on the kernel level without the need for a guest operating system, so containers are much more efficient, fast, and lightweight. Which allows applications to become encapsulated in self-contained environments which has advantages, such as quicker deployments, scalability and reduced equality between development environments. Docker is currently the most popular container platform.  Docker has the Docker Engine, which is a run-time and allows you to build and run containers. The rise of Orchestration Systems While Docker provided an open standard for packaging and distributing co...

Embed Swing control into SWT composite

For this requirement, we need an SWT_AWT bridge to create EmbeddedFrame which will be used to add Swing Controls. Sample Code: JLabel label = new JLabel("sample label"); Composite composite = new Composite(shell, SWT.EMBEDDED); Frame frame = SWT_AWT.new_Frame(composite); frame.setLayout(new BorderLayout()); frame.add(label,BorderLayout.CENTER);

Code to scale JFace/SWT image

Please find the code below ImageDescriptor scaleImage(Display display, ImageDescriptor imageDescriptor, int outMaxWidth, int outMaxHeight) { if (imageDescriptor == null) { return null; } ImageData imageData = imageDescriptor.getImageData(); if (imageData == null) { return imageDescriptor; } int newHeight = outMaxHeight; int newWidth = (imageData.width * newHeight) / imageData.height; if (newWidth > outMaxWidth) { newWidth = outMaxWidth; newHeight = (imageData.height * newWidth) / imageData.width; } // Use GC.drawImage Image outImage = new Image(display, newWidth, newHeight); GC gc = new GC(outImage); Image oldImage = imageDescriptor.createImage(); gc.drawImage(oldImage, 0, 0, imageData.width, imageData.height, ...

How to make Eclipse e4 RCP App Full-screen and Trimless

Image
To make your Eclipse e4 RCP App full-screen and trimless then you need to find your TrimmedWindow element in Windows & Dialog section of Application.e4xmi file. Add the tag shellMaximized and the persistentState value styleOverride to 8.

Find out a monitor’s size / resolution in Eclipse SWT

For Single Monitor : @Inject @Optional public void receiveActiveShell(@Named(IServiceConstants.ACTIVE_SHELL) final Shell shell) { if (shell != null) { final Display display = shell.getDisplay(); final Rectangle screenSize = display.getBounds(); final Point size = shell.getSize(); shell.setLocation((int) (screenSize.width - size.x) / 2, (int) (screenSize.height - size.y) / 2); } } For Multi Monitor : Monitor[] monitors = getShell().getDisplay().getMonitors(); Monitor activeMonitor = null; Rectangle rect = shell.getBounds(); for (int i = 0; i < monitors.length; i++) { if (monitors[i].getBounds().intersects(rect)) { activeMonitor = monitors[i]; } } System.out.println("The resolution of the active monitor is " + activeMonitor.getBounds().width + " x " + activeMonitor.getBounds().height);

VMware Virtual Machine Operations

VMware Virtual Machine Operations For these operations I used VI java as library: SourceCode: package com.shashwat.vijava;   import java.net.URL; import java.util.Scanner; import com.vmware.vim25.mo.Folder; import com.vmware.vim25.mo.InventoryNavigator; import com.vmware.vim25.mo.ServiceInstance; import com.vmware.vim25.mo.Task; import com.vmware.vim25.mo.VirtualMachine; public class VMPowerOps { @SuppressWarnings("deprecation") public static void main(String[] args) throws Exception { String address, userName, password, vmName, operation; Scanner scanner = new Scanner(System.in); System.out.println("Enter vCenter or ESXi IP address ?"); address = scanner.nextLine(); System.out.println("Enter username of " + address + " ?"); userName = scanner.nextLine(); System.out.println("Enter password of " + addr...

How to remove QuickAccess field from your Eclipse application

Image
Sometimes we need to remove the QuickAccess widget from Eclipse RCP application. Even after following below steps Ctrl + 3 will work. Add these dependency in your eclipse rcp plugin org.eclipse.e4.ui.model.workbench org.eclipse.e4.ui.workbench org.eclipse.e4.core.contexts In ApplicationWorkbenchWindowAdvisor, in postWindowOpen add these statements at end IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); if (window instanceof WorkbenchWindow) { MWindow mWindow = ((WorkbenchWindow) window).getModel(); EModelService modelService = mWindow.getContext().get(EModelService.class); MToolControl searchField = (MToolControl)modelService.find("SearchField", mWindow); if (searchField != null) { searchField.setToBeRendered(false); } }

Producer - Consumer Problem Java

Producer - Consumer Problem implementation: IntegerBuffer.java public class IntegerBuffer { private int index; private int[] buffer; private final int SIZE = 2; public IntegerBuffer() { this.buffer = new int[SIZE]; } public synchronized void add(int number) { while (index == buffer.length - 1) { try { wait(); System.out.println("IntegerBuffer.add() waiting"); } catch (InterruptedException e) { } } buffer[index++] = number; notifyAll(); } public synchronized int remove() { while (index == 0) { try { wait(); System.out.println("IntegerBuffer.remove() waiting"); } catch (InterruptedException e) { } } in...

Types of Virtualization

Paravirtualization is virtualization in which the guest operating system (the one being virtualized) is aware that it is a guest and accordingly has drivers that, instead of issuing hardware commands, simply issue commands directly to the host operating system. This also includes memory and thread management as well, which usually require unavailable privileged instructions in the processor. Full Virtualization is virtualization in which the guest operating system is unaware that it is in a virtualized environment, and therefore hardware is virtualized by the host operating system so that the guest can issue commands to what it thinks is actual hardware, but really are just simulated hardware devices created by the host. Hardware Assisted Virtualization is a type of Full Virtualization where the microprocessor architecture has special instructions to aid the virtualization of hardware. These instructions might allow a virtual context to be setup so that the guest can execute pr...

Implemention of LRU Cache

Source: import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentLinkedDeque; /** * Class LRU Cache * @author Shashwat * @param <Key> * @param <Value> */ public class LRUCache<Key, Value> { private final int MAX_SIZE; private ConcurrentHashMap<Key, Value> map; private ConcurrentLinkedDeque<Key> queue; public LRUCache(final int maxSize) { this.MAX_SIZE = maxSize; this.map = new ConcurrentHashMap<Key, Value>(this.MAX_SIZE); this.queue = new ConcurrentLinkedDeque<Key>(); } public Value get(Key key) { return this.map.get(key); } public void put(final Key key, final Value value) { if (this.map.containsKey(key)) { this.queue.remove(key); } while (this.queue.size() >= this.MAX_SIZE) { Key o...

Java Puzzle

Question: class Puzzle { public static void main(String[] args) { System.out.print(12345 + 5432l); System.out.print(" "); System.out.print(01234 + 43210); } } Output : 17777 43878 In lines: System.out.print(12345 + 5432l); 5432l ---- Its last character is L -- means long System.out.print(01234 + 43210); 01234 ---- Here starting digit is 0 which means octal Fixed version : class Puzzle { public static void main(String[] args) { System.out.print(12345 + 5432L); // make the last character L System.out.print(" "); System.out.print(1234 + 43210); // drop the 0 } } Output : 66666 44444

Print two dimensional array in spiral order

Source code: package com.in2soft.test; public class PrintSpiralTest { /** * @since Dec 26, 2015 * @author Shashwat.Anand */ public static void main(String[] args) { int[][] twoDArry = { { 2, 4, 6, 8 }, { 5, 9, 12, 16 }, { 2, 11, 5, 9 }, { 3, 2, 1, 8 } }; printInSpiralOrder(twoDArry, twoDArry[0].length, twoDArry.length); } private static void printInSpiralOrder(int[][] twoDArry, int m, int n) { int t = 0, b = m - 1, l = 0, r = n - 1; int dir = 0; // 0 = -> ; 0 = bottom; 0 = <-; 0 = top while (t <= b && l <= r) { if (dir == 0) { for (int i = l; i <= r; i++) { System.out.println(twoDArry[t][i]); } t++; dir = 1; } else if (dir == 1) { for (int i = t; i <= b; i++) { System.out.println(twoDArry[i][r]); } r--; dir = 2; } else if (dir == 2) { for (int i = r; i >= l; i--) { System.out.println(twoDArry...

Find two strings are anagram in Java ?

Source Code : import java.util.Arrays; /** * Anagram.java * @author Shashwat Anand */ public class Anagram { public static void main(String[] args) { System.out.println(testAnagram("Shashwat", "Shawatsh")); System.out.println(testAnagram("Shashwat", "Shawatwh")); System.out.println(testAnagramWithInbuiltMethods("Shashwat", "Shawatsh")); System.out.println(testAnagramWithInbuiltMethods("Shashwat", "Shawatwh")); } private static boolean testAnagramWithInbuiltMethods(String str1, String str2) { char[] charArray1 = str1.toCharArray(); char[] charArray2 = str2.toCharArray(); Arrays.sort(charArray1); Arrays.sort(charArray2); return Arrays.equals(charArray1, charArray2); } private static boolean testAnagram(String str1, String str2) { ...

How to add Xtext DSL editor in Multi-Page Editor

To add your Xtext Dsl Editor to Multi-Page Editor Getting the instance of XText editor MyDslActivator activator = MyDslActivator.getInstance(); final Injector injector = activator.getInjector("org.shashwat.xtext.mydsl.MyDsl"); XtextEditor xtextEditor = injector.getInstance(XtextEditor.class); Remember to have editor input instance of IFileEditorInput. XtextEditor uses XtextDocumentProvider which extends FileDocumentProvider FileEditorInput fileEditorInput = new FileEditorInput(file); // Here file is instance of IFile int index = addPage(xtextEditor, fileEditorInput);

Run Javascript Code inside Java Code

As JDK 8 has Nashorn Javascipt Engine, below is simple code snippet for this: package com.sha.java8.jjs_nashorn; import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; public class FirstEg { public static void main(String[] args) { ScriptEngineManager scriptEngineManager = new ScriptEngineManager(); ScriptEngine engine = scriptEngineManager.getEngineByName("nashorn"); String script = "var greet = 'Hello'; " + "greet += ' Shashwat'; " + "greet;"; Object output; try { output = engine.eval(script); System.out.println(output); } catch (Exception e) { System.out.println("Javascript Exception"); e.printStackTrace(); } } } Output: Hello Shashwat

When to use Import-Package and Require-Bundle in Eclipse Plugin?

The OSGi way is to use Import-Package, as it specifically decouples the package from the bundle that provides it. Require-Bundle: Bundles can be re-exported Gives you access to all exports of the bundle, regardless of what they are, and regardless of whether you need them. Specifies the explicit bundle (and version) to use. If a required bundle needs to be refactored and a package moved elsewhere, then dependents will need changes to their MANIFEST.MF file. Import-Package: Loose coupling, only the package (and version) is specified and the run-time finds the required bundle. Actual implementations can be swapped out Dependent packages can be moved to different bundles by the package owner But requires more metadata to be maintained (i.e: each package name) at lower levels of granularity In my view we should below approach in using Import Package or Require-Bundle Interface <=> Import-Package Implementation class <=> ...

Creating password protected ZIP file using TrueZip

try { final TConfig config = TConfig.get(); // Request encryption in archive files. config.setOutputPreferences(config.getOutputPreferences() .or(BitField.of(FsOutputOption.ENCRYPT))); // Configure archive detector with custom key management for ZIP files. config.setArchiveDetector(newArchiveDetector1("zip", "password")); // Setup file paths. TFile src = new TFile("file1"); TFile dst = new TFile("file2"); if (dst.isArchive() || dst.isDirectory()) dst = new TFile(dst, src.getName()); // Recursive copy. src.cp_rp(dst); } finally { // Commit changes. TVFS.umount(); }

AWS vs OpenStack

AWS (Amazon Webservices)                                            OpenStack AWS Console                                                             Horizon (it is a dashboad of services) IAM                                                               ...

OSGI and Eclipse Version

2004 Eclipse 3.0 -> OSGi 4.0 early draft 2005 Eclipse 3.1 -> OSGi 4.0 draft 2006 Eclipse 3.2 Callisto -> OSGi 4.0 2007 Eclipse 3.3 Europa -> OSGi 4.1 2008 Eclipse 3.4 Ganymede -> OSGi 4.1 2009 Eclipse 3.5 Galileo -> OSGi 4.2 2010 Eclipse 3.6 Helios -> OSGi 4.2 2011 Eclipse 4.1/3.7 Indigo -> OSGi 4.3 2012 Eclipse 4.2/3.8 Juno -> OSGi 5 2013 Eclipse 4.3/3.9 Kepler -> OSGi 5     The Bundle-ManifestVersion is not mandatory. If it is missing then defaults version 1. OSGi R4 introduced Bundle-ManifestVersion: 2 , and so in practice,  almost all bundles have this entry.