Wednesday, May 31, 2017

Power of XOR

Power of XOR

if (b1 != b2) //XOR
if (b1 == b2) //XNOR

1) Any number xor'd with itself will give zero.
2) Any number xor'd with zero will give the number.

Wednesday, May 24, 2017

Java Maven Code Coverage

Sure Fire - The Surefire Plugin is used during the test phase of the build lifecycle to execute the unit tests of an application. It generates reports in two different file formats (.txt, .xml)

Fail Safe - The Failsafe Plugin is designed to run integration tests while the Surefire Plugin is designed to run unit tests. The name (failsafe) was chosen both because it is a synonym of surefire and because it implies that when it fails, it does so in a safe way. The Failsafe Plugin is used during the integration-test and verify phases of the build lifecycle to execute the integration tests of an application. The Failsafe Plugin will not fail the build during the integration-test phase, thus enabling the post-integration-test phase to execute. The Failsafe Plugin generates reports in two different file formats (.txt, xml)

Jacoco - The JaCoCo Maven code coverage plug-in provides the JaCoCo runtime agent to your tests and allows basic code Coverage report creation. When using the maven-surefire-plugin or maven-failsafe-plugin you must not use a forkCount of 0 or set the forkMode to never as this would prevent the execution of the tests with the javaagent set and no coverage would be recorded.

CoberturaCobertura is a free Java tool that calculates the percentage of code accessed by tests. It can be used to identify which parts of your Java program are lacking test coverage. It is based on jcoverage. It follows Bytecode Instrumentation.

Clover - Clover is designed to measure code coverage in a way that fits seamlessly with your current development environment and practices, whatever they may be. Clover's IDE Plugins provide developers with a way to quickly measure code coverage without having to leave the IDE. Clover's Ant and Maven integrations allow coverage measurement to be performed in Automated Build and Continuous Integration systems, and reports generated to be shared by the team

SonarQubeSonarQube software (previously called Sonar) is an open source quality management platform, dedicated to continuously analyze and measure technical quality, from project portfolio to method

Monday, May 22, 2017

Spring Profiles

If your project has 2 profiles

  1. local
  2. prod
you can choose profile when you run using property

spring.profiles.active

create 2 application.properties files one for each profile

  1. application-local.properties
  2. application-prod.properties
when you run the application pass the profile property like below

  1. mvn spring-boot:run -Dspring.profiles.active=local
  2. mvn spring-boot:run -Dspring.profiles.active=prod

Wednesday, May 10, 2017

Unit Testing Polymer Components

Requirements

  1. Polymer CLI
  2. Web Component Tester - WCT

Overview

  1. Install Polymer CLI
  2. Create An Element Project
  3. polymer test

Install Polymer CLI

  • npm install -g polymer-cli

Create An Element Project

  • mkdir my-el && cd my-el
  • polymer init

Run Test non-interactive

  • polymer test

Run test interactive

  • polymer serve
  • go to localhost:8080/components/my-el/test/my-el_test.html in your browser

Tuesday, May 9, 2017

Hello World Polymer

What is Polymer ?

  1. Library On top of WebComponent API
  2. Bulding custom component is easier with polymer
  3. Provides 2 way data binding
  4. Components are just HTML files

Creating Hello World Component 


helloworld.html

Using Hello World Component


index.html

Open in Browser


index.html

Creating myName Property in hello-world component


hello-world.html

Using myName Property


index.html

Open in Browser


index.html




Friday, May 5, 2017

CSV epoc to Human Readable Date

sample.csv 
apple,red,1494005258000
banana,yellow,1494005306000
lemon,green,1494005640000

Unix Command

grep -Eo '[0-9]{13}' ~/sample.csv | xargs -L1 date -r

Output
Tue Feb 21 04:33:20 PST 49313
Tue Feb 21 17:53:20 PST 49313
Sat Feb 25 14:40:00 PST 49313