Saturday, October 29, 2016

Dockerfile Commands

A list of commands are defined to build Docker image.

  • FROM

The first statement/command in the docker file which tells which image to download and start from.

  • MAINTAINER

Describes the author of the docker file.

MAINTAINER <First name> <Last name> <email address>

  • RUN

Run a command, wait for the result and then saves the result.

RUN echo hello docker

  • ADD

Adds local files, contents of a tar archives and works with urls.

  • ENV

Helps to set environment variables, both during the build and when running the result.

ENV artifactId=com.org.artifactId

  • ENTRYPOINT

Specifies the start of the command to run

  • CMD

Specifies the whole command to run

  • EXPOSE

Maps a port into the container

EXPOSE 8080

  • VOLUME

Defines shared or ephemeral volumes.

VOLUME [“/host/path/” “/container/path/”]

VOLUME [“/shared-data”]

  • WORKDIR

Sets the directory the container starts in. It is similar to use ‘cd’ after start.

WORKDIR /install/

  • USER

Sets which user the container will run as.

USER bimal

USER 1000

Thursday, September 22, 2016

TypeScript

TypeScript is a superset of JavaScript. When TypeScript is compiled, it transpiled to JavaScript.

Features:

  • Static Typing
  • Interfaces
  • Class Properties
  • Access modifiers (Public, Private)

Static Typing:

let name: string
let age: number
let dob: data

Interfaces:

interface IEmp {
     name: string
     age?: number //Optional property
     dob: date
}

let myEmp: IEmp

Class Properties:

class Employee {

name: string
dob: date
constructor (name){
       this.name = name
}
}

Access Modifier:

Class members are public by default in both ES6 and TypeScript.

class Employee {

private name: string
private getSalary() {
     console.log(‘Salary of ’ + this.name + ‘ is $5000.00‘)
}
}

let myEmp = new Employee ()
console.log(myEmp.name) //Compile time error

Thanks,
Bimal

Saturday, November 07, 2015

Custom Matchers in Jasmine 2.3

Custom matchers, provided by the behavior-driven development framework Jasmine, is a great feature for testing JavaScript code. Custom Matchers helps to group multiple catch checking which makes the test cases clean and self explanatory.

Let’s look at an example that I tried recently

Here is a Calculator.js file:

   1: var Calculator = function () { };
   2:  
   3: Calculator.prototype.add = function (a, b) {
   4:     return a + b;
   5: };
   6:  
   7: Calculator.prototype.divide = function (a, b) {
   8:     return a / b;
   9: };

One of the test scenarios that I would like to try is to check whether the result of the method is in a particular range. The test method will look like this with existing matchers.



   1: describe('Calculator', function () {
   2:     var calc;
   3:  
   4:     beforeEach(function () {
   5:         calc = new Calculator();       
   6:     });
   7:  
   8:     it('should be able to add 1 and 1', function () {
   9:         expect(calc.add(1, 1)).toBe(2);
  10:     });
  11:  
  12:     it('should be able to divide 6 by 2', function () {
  13:         expect(calc.divide(6, 2)).toBe(3);
  14:     })
  15:  
  16:     it('should be able to divide a rational number', function () {
  17:         expect(calc.divide(1, 3)).toBeLessThan(0.34);
  18:         expect(calc.divide(1, 3)).toBeGreaterThan(0.3);        
  19:     })
  20: });

But you can replace the existing matchers with a custom matcher like this.



   1: describe('Calculator', function () {
   2:     var calc;
   3:  
   4:     beforeEach(function () {
   5:         calc = new Calculator();
   6:  
   7:         jasmine.addMatchers({
   8:             toBeBetween: function (util, customEqualityTesters) {
   9:                 return {
  10:                     compare: function (actual, a, b) {
  11:                         var result = {};
  12:                         result.pass = actual >= a && actual <= b;
  13:                         return result;
  14:                     }
  15:                 }
  16:             }
  17:         });
  18:     });
  19:  
  20:     it('should be able to add 1 and 1', function () {
  21:         expect(calc.add(1, 1)).toBe(2);
  22:     });
  23:  
  24:     it('should be able to divide 6 by 2', function () {
  25:         expect(calc.divide(6, 2)).toBe(3);
  26:     })
  27:  
  28:     it('should be able to divide a rational number', function () {
  29:         expect(calc.divide(1, 3)).toBeBetween(0.3, 0.34);
  30:     })
  31: });

You can reuse custom matchers to make the test cases clear and more simple.


What are some scenarios that you use custom matchers?

Monday, May 11, 2015

JavaScript Data Binding Frameworks

Data binding is the process that establishes a connection between the application UI and business logic. It synchronize the elements of the application with different sources of data.
Over the last few years several JavaScript libraries have been released to handle the process of binding data to HTML controls which includes:
  • AngularJS
  • Backbone.js
  • Derby
  • Ember
  • JsViews
  • JQXB Expression Binder
  • Knock
  • Meteor
  • Simpli5
  • WinJS

Thanks,
Bimal


Thursday, January 15, 2015

Basic git operations

Git is a version control system and GitHub is a web-page on which we can publish our Git repositories and collaborate with other people.

The basic commands used are:

To initialize a project in local, go to the project directory and use the following command which will create a .git folder.

   1: >git init <project name>

To check the status of the repository use the status command.


   1: >git status

To track the files created or modified locally, add command should be used.


   1: >git add *

or



   1: >git add *.js


or



   1: >git add <file name>

To attach git repo to local workspace


   1: >git remote add origin <git url>
To commit changes to head


   1: >git commit –m “Commit my changes”
To push the changes to master branch in server


   1: >git push -u origin master
To pull an existing repo to the local


   1: >git pull


Thanks.
Bimal

Friday, January 09, 2015

RESTful Framework for Java

  • Apache CXF
  • Apache Tuscany
  • Apache Wink
  • Cuubez framework
  • Jersey
  • RESTeasy
  • Restfulie
  • Restlet

Monday, December 29, 2014

Basic Angular Application–Step by Step




Angular JS is a JavaScript framework from Google which helps to build structured, testable Single Page Applications(SPA).
Application Requirement
  1. Add a <script> tag which point to angular.js
  2. Add an ng-app attribute(it is a directive  and ng is short form of angular)
Step by Step
To build a basic Angular JS application, follow the steps shown below
  1. Create a html file or a project with a html file in your favorite IDE. I am using WebStorm 9.0.2 trial version and named the project as BasicAngular as shown below.

    image
  2. Add angular.js framework Angular JS framework can be pointing to a local copy of the angular.js file or from a CDN (content delivery network). The screenshot below shows the Google CDN URL.
    image
  3. Add ng-app attribute Include ng-app directive to auto bootstrap the angular application.
    image
  4. Run or open in a browser The expression 12 * 34 is included inside {{ }} will be evaluated and resulting html will be inserted into the div tag as shown below
    image
Thanks,
Bimal