Sunday, December 3, 2017

Setting github webhook on your repository to trigger an action in Jenkins

The following steps show how to trigger a build by using github webhooks in Jenkins. The rpre requirements here are :

  • make sure jenkins in installed and git plugin is installed.
  • git is installed .
  • path of git.exe is valid in jenkins global tool configuration.
Please refer to my other articles if you have trouble in setting up the environment.


  1. open jenkins and click on new item. This would take you to the screen as shown below:
  2. Give a name and select freestyle project.Click Ok. 
  3. This will redirect to another screen.Enter description of the job if needed or else move the source code management section.
  4. Under source code management section select git and paste the git repository url as shown below:
  5. Now if you move to next section you find build triggers , under that select GitHub hook trigger for GITScm polling.
  6. Selecting this, if jenkins will receive PUSH GitHub hook from repo defined in Git SCM section it will trigger Git SCM polling logic.
  7. Now we need to set up webhook on our repositpory. So go to the github repository mentioned above in the git scm section.
  8. When we go to the repository, click on settings and then webhooks. Under webhooks click on add new webhook. The screen should look like this:
  9. Here under the payload URL we need to mention the details of the jenkins service we are running inorder to receive the HTTP POST information from github.com
  10. Here in my case I am running jenkins on my local machine, so I am providing the URL as below:
  11. If you have a secret provided during jenkins installation you can add this here and there is also a flexibility to select on which event we want the webhook to trigger.

In this way, we can setup webhook and trigger build in Jenkins.




Github Webhooks

Consider a situation where you are in an organisation which makes use of GIT source code management and you need to trigger a build only when there is a new commit on the repository, alternatively you may have a build triggerred at any custome interval of your preference but it is a waste of resource if we are building the same source code without any updates.
             The above requirement can be achieved by making use of github webhooks. Github webhooks allow applications to subscribe to certain events on github.com, so whenever one of those events is triggered , a HTTP POST payload is sent to the configured webhooks URL. Webhooks can be used to trigger builds, deploy code to production server, track issues and also send notifications.

Saturday, December 2, 2017

Errror while connecting to a repository in Jenkins

"Failed to connect to repository : Error performing command: git.exe ls-remote -h https://github.com/narendravenkata/React-Demo.git HEAD"




I was getting this error when I installed Jenkins on my windows 10 machine and trying to build my first job.

The error is caused because either git is not installed on your machine or the path of git.exe is not provided correctly.

Solution:
  1. After you install Jenkins, you will be running Jenkins as a service and we can access it at http://localhost:8080/ .
  2. Go to the url and login with the registered credentials.On the left hand side you see a side bar with items and click on Manage Jenkins and go to Global Tool Configuration.
  3. When yo see under git you will have an error like below.
  4. Now as I mentioned earlier we need to specify the correct path of the git.exe.
  5. After we specify the correct path, the error disappears and looks like below.
  6. After the above step ,we can now comfortably add the repository in our job and it looks like below.

In this manner we can resolve the error while adding a git repository in our jenkins job .

Tuesday, September 26, 2017

JavaScript

JavaScript is a lightweight, cross platform, object oriented programming language.

lightweight: it takes very less system memory

cross platform: can be run on multiple platforms and systems

object oriented : js is a language based on object

JavaScript is one of the three core technologies(HTML & CSS)

JavaScript is most commonly used as a part of webpages. It can be used in different places.
  • Client Side : JavaScript was used only in browser  for many years.
  • Server Side : With development of Node.js we are able to use JavaScript in the server side as well.
JavaScript made modern web development possible. With JS we are able to have dynamic effects and are building modern web applications that we can interact with.

Different states of a PROCESS

As a process executes it changes its state. The state of a process is defined in part by the current activity of that process. A process may be in one of the following states.


  • New : The process is being created.
  • Running : Instructions are being executed.
  • Waiting : The process is waiting for some event to occur.
  • Ready: The process is waiting to be assigned to a processor.
  • Terminated: The process has finished execution.

The state diagram gives you the detailed understanding on how the process changes its state.



Monday, September 25, 2017

JSX

JSX - JavaScript Syntax Extension

A preprocessor step that adds XML syntax to javascript.


  • It looks like XML/HTML
  • Defines a familiar syntax to define tree structure with attributes
  • It is not requires but makes things easier while writing react components.

     
The left side represents code written in JSX and right hand side is the corresponding javascript . Just to make a list of four colors you can see the amount of code we have to write if we are not using JSX.

Friday, September 8, 2017

" Hello World ! " using React JS


  • Create a document with .html extension, let it be index.html.
  • Now add title to the web page. In the body section create a div tag with id='app'. We will then write react code which replaces the content here under div tag.

  • Add the react-dom and react js script files to the index.html
  • Add the react js script to be rendered in index.html 
  • Open the index.html in your browser. You should see Hello World! as below.
You have done your first react application

Wednesday, August 9, 2017

Getting started with Windows IoT and Raspberry pi 3

The following tutorial drives through getting started with Windows IoT on a Raspberry pi 3.

Equipment needed:


  1. Raspberry pi 3.
  2. Adapter.
  3. Memory card.
  4. Card reader.
  5. Led,resistor and connecting jumper cables.

In this tutorial we will run Hello, blinky using Windows IoT and Raspberry pi3.

  • First go to https://developer.microsoft.com/en-us/windows/iot  and select getting started . It will redirect you to another page .Here we have to select the device, in our case "Raspberry pi 3". 
  • Select install on to my blank sd card. 
  • Then select the OS as Windows 10 IoT core. Click Next.
  • This will launch you on another page from where we get Windows 10 IoT dashboard. Download  and install the dashboard.
  • Connect the card reader to the computer and open the dashboard. Go to set up my device and select raspberry pi3.
  • Make sure you select the wifi on the right hand side and setup device name and password .
  • After this check I accept and press on download and install. This takes a while and after the installation place the sd card on the board and power it on.
  • The initial boot takes some time and on the dashboard go to my devices, there you will find the board.
  • Download and install visual studio if you dont have one.
  • Go to https://github.com/ms-iot/samples and clone the repository. This contains a bunch of samples we can run .
  • Set up the led and resistor on the breadboard as shown below. 
  • After that based on the picture below use the white jumper cable at pin 1 (3.3W power) and black jumper cable at pin 29 (gpoi 5).
    Place the pin1 jumper cable other end at the resistor and pin 29 jumper cable other end at led .
  • Open hello blinky solution in the visual studio.
    Go to properties of the project and select debug and click on find remote machine. You should see the raspberry pi 3, select it and save it .
  • Then click on remote machine to run the program, it would take a while to deploy and then you can see the led blinking.
  • The output should look like this, a blinking led.



Have you ever wondered why there are two options sleep and hibernate? I will explain here the differences.

There are two options other than shutting down your computer .

1.Sleep
2.Hibernate

Sleep will store all the applications which are running onto RAM. As we are storing on RAM,as it is a volatile memory it will consume power as normal and when we don't have power(in case of laptop battery)we will loose our data.

Hibernate will store all applications related data onto hard disk and shuts down the computer. In this mode power consumption is almost same as when we shutdown the computer. When we turn on the computer all our data is retrieved during booting. If we are having an SSD it is good to use hibernate over Sleep as power consumption is less.

Saturday, August 5, 2017

What is an Operating System

An operating system is a program or programs that act as a intermediary between user of computer and hardware of computer.

Operating systems mainly for making computer hardware to be used in an efficient manner, make the computer system convenient to use and also solve user problems in easier way.


Friday, August 4, 2017

Describe the terms regarding Operating Systems a)Concurrency b)Parallelism

Concurrency:

The term concurrency refers to techniques that makes program more usable. Concurrency can be implemented and is used a lot on single processing units nonetheless it may benefit from multiple processing units with respect to speed.If we can load multiple documents simultaneously in the tabs of our browser and still can open other applications and perform actions,this is concurrency.


Single Core

T1
T2
T3
T4
T1
T2
T3
T4




                              -------------------------------------------->  time


Concurrency on Single Core



Parallelism:

The term parallelism refers to techniques to make programs faster by performing several computations in parallel. Graphic computations on GPU are parallelism is reduce data dependencies in order to be able to perform computations on independent computation units with minimal communication between them.

Parallelism on Multi Core

Core 1  
T1
T3
T1
T3
T1
T3
T1
T3






Core 2
T2
T4
T2
T4
T2
T4
T2
T4





                              --------------------------------> time 


Difference between threads and processes


  • Processes and threads are independent sequences of  execution ,the typical difference is that threads run in a shared memory space while processes run in separate memory spaces.
  • A process has self contained execution environment that means it has a complete, private set of basic run time resources particularly each process has its own memory space. Threads exist within a process and every process has at least one thread.
  • Each process provides the resources needed to execute a program. Each process is started with a single thread known as primary thread. A process can have multiple threads in addition to the primary thread.
  • Threads have direct access to the data segment of its process but processes have their own copy of the data segment of parent process.
  • Changes made to main thread may affect the behavior of the other threads of process while changes to parent process does not affect child process.
  • Processes are heavily dependent on system resources available while threads require minimal amounts of resource so a process is considered heavyweight while thread is considered a light weight process. 

Difference between ReactJS and React-Native

React-Native is a framework, whereas ReactJS is a java script library we can use to develop user interfaces. When we are using ReactJS in a project we need to choose a bundler like webpack, which we want to use in our project. React-Native is like a "go work" kind of thing . Here it comes with everything we need and it is very easy to setup,very fast and can be run in the terminal with just one command.
                 

Wednesday, July 26, 2017

How would you try to save or print a string with escape like this '\' ?

Today I got an issue working with a file path which contains '\' I wanted to save it to the database but I was unable to do.

The path is "C:\Narendra\Work"

Later I tried as "C:\\Narendra\\Work"

Tuesday, July 25, 2017

Monday, July 10, 2017

What is Mocking?

The process of replacing a module with generic and mostly empty object, called a mock.

Advantages:

  • Isolates our code from its dependencies.
  • Write tests with no knowledge of dependencies.
  • No need to change tests after change of dependencies.
  • Reduces false positives.
  • Tests will be less fragile.
  • Easier for other developers to understand.

Tuesday, June 13, 2017

How do you get id of a record newly inserted into the database with only one query .

In my project I was inserting a project into a database and I need to assign the "id" created when project is inserted into database.

r.db("DatabaseName").table("TableName").insert("Values")


{
"deleted": 0 ,
"errors": 0 ,
"generated_keys": [
"6538d988-f8e8-4ab0-bf71-f363fce91b9f"
] ,
"inserted": 1 ,
"replaced": 0 ,
"skipped": 0 ,
"unchanged": 0

}



The query to insert will provide a response as shown above and we can make use of the generated_keys to use for our purpose.

The database used is rethinkdb and query is written in reql language.



Sunday, June 11, 2017

get in rethinkdb

In rethink db when we want to have a row selected we can make use of this get.

table.get(key) will give us a single row. if there are no documents null is returned.

Saturday, June 10, 2017

Building your C# application

I am going to describe how to create a basic C# console application in which we generate a random number and then guess it.Before diving in I am just giving an introduction on C# and .NET and also which tools we will be using in building this application.

          C# is an object oriented programming language created by Microsoft and it is one of the many languages used along with .NET framework. There is generally a confusion between C# and .NET, I will try to clear this. C# is basically a programming language and we use it along with .NET framework to build applications for Windows and we can also use C# to build applications for other platforms like Linux  by making use of Mono, which is a open source implementation of Microsoft .NET Framework.
          .NET is a framework for building windows applications and web applications and this is not limited to one language. We can use C#, VB.Net, F#, C++, J# and many more like around sixty languages. It has two important components say Common Language Run-time and Class Library. CLR is a virtual machine component and manages execution of .NET programs. Common Language Runtime or CLR is the run-time execution environment of .Net Framework. Converting MS-IL into platform or OS specific code is done by the CLR. CLR is responsible for bringing application to life and its also the CLR’s job to tear down application when its finished executing or if it has an unrecoverable error. CLR actively tracks all the memory a program uses and it knows when the program is finished with memory so it will clean things up and allows program to have enough memory as it runs. 

We make use of an IDE(Integrated Development Environment) to build our application. We use Visual Studio (Community edition) as it is free.

First we should decide the algorithm on how we are writing our program. The algorithm is as follows:

1.Generate a random number .
2.Take input from user.
3.Check whether both are equal.
4.Make user know whether value he entered is greater or lesser than the secret number.
5.Continue steps 2 ,3,4 until guess is correct.
6.If user quits close or else continue from step 1 again.

Get Microsoft Visual Studio installed and Create a new project. In creating new project select Console Application and select location where you want
 to save the project.



Once you click on OK you have a new screen with defaults loaded. We have a program.cs file created for us with an empty main method which is our entry point.


Now we can start writing our application. First we need to generate a random number for this we make use of Random class .


After generating this number we should prompt the user to guess a value.


Now we should check whether the guess and secret number are equal or not. We should do this until user enters the correct value.


We should allow user to play the game until he wants to quit.


now the application is done and we can start using it to play with your friends.

Friday, June 9, 2017

Nancy

Nancy is a light-weight ,low ceremony framework for building HTTP-based services on .NET. It provides a super-duper-happy-path to all interactions.

You might be wondering what the super-duper-path is. Here I will explain things clearly.


  • It just works
  • Easily Customizable
  • Low ceremony
  • Low friction

Thursday, June 8, 2017

Cors

CORS introduces a standard mechanism that can be used by all browsers for implementing cross-domain requests. The spec defines a set of headers that allow the browser and server to communicate about which requests are (and are not) allowed. CORS continues the spirit of the open web by bringing API access to all.

Wednesday, June 7, 2017

how to pass a javascript object to be written to a database

I have an Address object from my user interface like below

Address:{address1:"Franklin",address2:"Warrensburg",adress3:"Missouri}

so as i am sending an object i should be able to capture all the fields.

so i define a class as

public class Address
    {
        public string Address1 { get; set; }
        public string Address2 { get; set; }
        public string Address3 { get; set; }
    }

and now when we get an object ,we get values as follows

["Address"] = new JObject
                {
                    ["Address1"] = _customer.Address.Address1, ===>Franklin
                    ["Address2"]= _customer.Address.Address2, ===>Warrensburg
                    ["Address3"] = _customer.Address.Address3 ===> Missouri
                }

Tuesday, June 6, 2017

Monday, June 5, 2017

Err address in use

this error occurs when we are using a port and try to bind the same port again. I have this error when I was using react and using 9080 port and tried to run server on same port. We have to kill the process first and then we have to bind the port again.

In windows you can use the following command to kill all instances of node server running

taskkill /f /im node.exe

Saturday, June 3, 2017

Use the `defaultValue` or `value` props on select instead of setting `selected` on option error in using react

This error can be solved by making use of select Value={this.state.option} which we are going to use , instead of making use of selected on option values.

Friday, May 26, 2017

converting json structure to circular error

I faced this error while having a react js web application requesteing data from backend services which talk to our rethinkdb database.

The root cause was there were no tables created in the database and backend services are requiringn these tables to process the request.

So after creating the data tables and inserting data into the tables I was able to solve the error.

Tuesday, May 23, 2017

Import and require difference in react

Require:
This allows us to have dynamically load module which isnt predefined or we can also conditionally load  a module when we reuire it.
Ex: var Navitem =require ("./components/NavItem");
Imports:
We can use ES6 import to selectively load the pieces which we need and by doing this we can save memory.
import Navitem from("./components/NavItem);


require is in ES 5 and in ES 6 we make use of import

Monday, May 22, 2017

Soft link and hard link in linux

Soft link has a different inode number and original file has different number. Soft link can link to a directory and the link will not have original file but shows the path.

Hard link has same inode number and will have original file contents. Removing the links will not affect original file contents. We cannot create a hard link to a directory.

Wednesday, May 17, 2017

How to know password for a wifi you connected previously, in case if you forgot and need to connect another device

The following is for windows.

Open command prompt and run it as administrator

Enter the following command

netsh wlan show profile

This command lists all the network names you have connected and remembered.




then enter the above command along with wifi name and key=clear

netsh wlan show profile netgear72 key=clear

This would display various profile properties in which we can find the password, look out for key content.



Monday, May 15, 2017

React js

React is a javascript library which can be used to develop user interfaces. We can also use it to develop complex and amazing web apps. It can be also be combined with Redux and many other tools to develop amazing applications.

Saturday, May 13, 2017

Given two words word1 and word2, find the minimum number of steps required to make word1 and word2 the same, where in each step you can delete one character in either string.

public class Solution {
    public int minDistance(String word1, String word2) {
        if (word1.equals(word2)) {
        return 0;
    }
    if (word1.length() == 0 || word2.length() == 0) {
        return Math.abs(word1.length() - word2.length());
    }
    int[][] dp = new int[word1.length() + 1][word2.length() + 1];
    for (int i = 0; i <= word1.length(); i++) {
        dp[i][0] = i;
    }
    for (int i = 0; i <= word2.length(); i++) {
        dp[0][i] = i;
    }
    for (int i = 1; i <= word1.length(); i++) {
        for (int j = 1; j <= word2.length(); j++) {
            if (word1.charAt(i - 1) == word2.charAt(j - 1)) {
                dp[i][j] = dp[i - 1][j - 1];
            } else {
                dp[i][j] =Math.min(dp[i-1][j], dp[i][j-1]) + 1;
            }
        }
    }
    return dp[word1.length()][word2.length()];
    }
}

Output:
"sea"
"eat"

Answer:
2

Friday, May 12, 2017

express module node.js

Express module is one of the most installed module in Node.js.  Express is a flexible Node.js web application framework which provides a robust set of features for web as well as mobile applications.
Using express we can create robust API's very easily and quickly .

Thursday, May 11, 2017

NPM (Node.js package manager)

NPM comes with node.js installation. It is node.js package manager, as the name suggests it is used to install node programs/modules. We can also easily specify and link dependencies.

npm install express                                installs express module

npm install express --save                     installs express and updates the dependencies in package.json


Modules get installed into the "node_modules" folder .

Wednesday, May 10, 2017

package.json in Node.js

This file goes in the root of our package or application and it tells how our package is structured and what to do to install it.

"npm init" command will create a package.json file and it will ask for details as shown below



Tuesday, May 9, 2017

Partial Classes

Partial classes concept was introduced in .NET 2.0 which allows us to split business logic in multiple files with same class name but with a "partial" keyword.

Monday, May 8, 2017

Explain the differences between TCP and UDP?

Tcp is connection oriented service which means every time you send a message you get an acknowledgment from the receiver stating the message has been received.
This is a reliable way of communication, but is slow. Think of it as a telephonic call. Only when the other side picks up the call, you can talk.

UDP is connectionless service. Like the one we use in online streaming. There is no acknowledgement in this case so the data might not be perfect at the receiver but the transmission is fast. So a few packet loss doesn't really matters. It is like an email. You can send but you wont know if it has been read or not. Like you wont know which packets reached and which were dropped.

Sunday, May 7, 2017

constant and read only difference in C#

constant needs to be initialized when it is declared.

read only variable can be assigned dynamically but need to be done before constructor exists as the the value is not changeable later.


Choosing between  read only or constant depends on our requirement. When we are confident that our constant value does not change we can use "const". The issue with constant is when we define a constant "a" variable with value 20 in an assembly X and use this assembly in another assembly Y, any update of variable "a" is not reflected until we recompile it.

But when we use a read only value here it is a reference to memory location and when we have new "a" value and on building assembly "X" all the assemblies using this X assembly the value of "a" is updated without being building them again.

Saturday, May 6, 2017

Software Testing

Verification and Validation of a software can be considered as Software Testing.

Tuesday, May 2, 2017

object literals in Javascript

A JavaScript object literal is like a comma separated name value pairs .

 Ex: var myObject={name:"narendra",height:180};

We can access the properties as myObject.name which gives "narendra"

Monday, May 1, 2017

Truthy and falsy values

Truthy Values:

"0"
"false"
empty functions
empty arrays
empty objects
typeof(null)

these above listed items are considered true in javascript


Falsy values:

false
0
""
null
undefined
NaN(Not a number)

These are considered false.

When dealing with these truthy and falsy values we should be careful and always try to use "===" or "!==" when we need to compare .

Sunday, April 30, 2017

difference between "==" and "==="

"==" will not check for type but when we use "===" it will check for type also and returns true when type of variables on both sides is same.

Example:

if(3=="3") will return true;

if(3 ==="3") will return false;

Thursday, April 27, 2017

AJAX

AJAX is acronym for Asynchronous JavaScript and XML. Ajax makes it possible to send and receive data asynchronously without reloading the web page. In general web applications the client(browser) is blocked when we refresh the page as it makes use of synchronous requests. But with Ajax the client is not blocked and works independently. Web applications like gmail, facebook etc make use of AJAX .

Wednesday, April 26, 2017

WSDL

WSDL means Web Services Description Language.It is written in XML and it is used to describe a web service. It provides details about location of service and methods of service.

Monday, April 24, 2017

Object Class

Object class supports all classes in .Net Framework class hierarchy and provides low level services to derived classes. This is the base class of all classes in the .NET framework .

Sunday, April 23, 2017

Continuous Integration

Continuous Integration is a development practice in which  the developers are required to commit changes to source code in a shared repository several times a day or more frequently.

Every commit made in the repository is then built. This allows the teams to detect problems early.


Saturday, April 22, 2017

p5.js

p5.js is a JavaScript library which can be used by artists,designers,educators and beginners who want to code. Using p5.js we have a full set of drawing functionality and this is not limited to canvas alone, we can make use of addon libraries from p5.js and easily interact with other html objects like text, input, video, webcam and sound.

Friday, April 21, 2017

Cloud Computing

Services and solutions that are delivered and consumed in real time over internet are cloud services.
Cloud computing is a delivery model of computing services over the internet .It enables real time development ,deployment and delivery of broad range of products, services and solutions.


Cloud cloud characteristics:

  • On demand self service
  • Ubiquitous network access:anywhere, anytime ,any device
  • location independent resource pooling
  • Rapid elasticity-Auto scaling
  • Pay as you go

Thursday, April 20, 2017

What is a Hypervisor?

hypervisor or virtual machine monitor (VMM) is computer software, firmware, or hardware, that creates and runs virtual machines. A computer on which a hypervisor runs one or more virtual machines is called a host machine, and each virtual machine is called a guest machine.

Hypervisor is a virtualization platform. A hypervisor is a computer software,firmware or hardware that will create and run virtual machines. On a computer with hypervisor we can run one or more virtual machines is called host machine and the virtual machines are called guest machines.

There are two types of hypervisors:

Type 1: Delivered as an integral part of Operating System

Type 2: Delivered as a process that runs within an Operating System 


Wednesday, April 19, 2017

Friendly Words:Friendly words can be defined as if a word is formed from characters of another word then those two words are friendly words.Example:listen,silent. Given an array of strings print group of friendly words in alphabetical order horizontal and vertically.

import java.util.*;
public class helloworld
{
public static void main(String []args){
String []a={"ivra","cheating","ravi","abc","cba","listen","teaching","dale","god","dog","lead","silent","deal"};
Arrays.sort(a);
String[] temp=new String[a.length];
for(int i=0;i<temp.length;i++){
temp[i]=a[i];
char[] chars = temp[i].toCharArray();
       Arrays.sort(chars);
       String sorted = new String(chars);
       temp[i]=sorted;  
}
String[] ans=new String[temp.length];
int kj=0;
Set<Integer> kh = new HashSet<>();
for(int i=0;i<temp.length;i++){
if(!kh.contains(i)){
String str=new String();
boolean matched=false;
for(int j=i+1;j<temp.length;j++){
if(temp[i].equals(temp[j])){
str=str+" "+a[j];
matched=true;
kh.add(j);
}
}
if(matched){
str=a[i]+str;
str.trim();
}
if(!str.isEmpty()&&str!=null)
ans[kj++]=str;
}
}
for(String word : ans){
if(word!=null)System.out.println(word);
}

}
}

Output:
abc cba
cheating teaching
dale deal lead
dog god
ivra ravi
listen silent

Call a function in child component from parent component in React

Consider the following parent component class Parent extends React.Component { constructor(props) { super(props);         thi...