how to merge a specific commit in Git

In this article am going to explain how to merge(cherry pick) specific commit in Git

When you are working on two different branches you often merge code from one branch to another. But if you want to merge specific changes to another branch you can do it by cherry picking specific commit.

Using Git Extensions you can easily merge a specific commit. (Download Git Extensions from link1 or from here link2)

In Git Extensions open your repository. It will show you all the commits. Select any specific commit and right click on it. Then select cherry pick commit. Check the below screenshot for reference


Once you select Cherry pick commit it opens another small popup as shown below


Check "Automatically create a commit" if you want to automatically commit this changes into current branch or if you want to manually commit, keep the box unchecked and click on "Cherry pick".

In this way you can merge a specific commit in Git
Read more...

ng-options with simple and complex array angularjs

In this article am going to explain how to use ng-options with simple and complex(array of objects) arrays

Assume you have following array

$scope.fruits = ['apple', 'banana', 'orange'];

If you want to show them in a dropdown using ng-options use the following code

<select name="fruit" data-ng-model="selectedFruit"  data-ng-options="fruit as fruit for fruit in fruits"></select>

What you get in the resulting html is below

<option label="apple" value="string:apple">apple</option>
<option label="banana" value="string:banana">banana</option>
<option label="orange" value="string:orange">orange</option>

when you select any option the value gets selected is same as value shown in dropdown.

Use ng-options for array of objects:


If you have an array of objects like below

$scope.fruits = [{ id: 1, name: 'apple' }, { id: 2, name: 'banana' }, { id: 3, name: 'orange' }];

Use the following html to show them in dropdown

<select name="fruit" data-ng-model="selectedFruit"  data-ng-options="fruit.id as fruit.name for fruit in fruits"></select>

If you use the above html then in the dropdown it shows name of the fruit but internally it stores the id of the fruit when you select any value from dropdown. resulting html code looks like below

<option label="apple" value="number:1">apple</option>
<option label="banana" value="number:2">banana</option>
<option label="orange" value="number:3">orange</option>

When you click on dropdown it shows names of the fruits but when you select any option internally id of the object will be selected.

Check this Plunker for working example: ng-options with simple and complex arrays

This is how ng-options works with simple and complex arrays.

For more posts on angularjs visit: AngularJS

Read more...

How to undo or revert last commit(s) in Git

When you are working on git, it is possible that sometimes you may commit the wrong files or the code you committed some times needs to be reverted back.

There are many ways to revert the last commit or any specific commit in git. This SO post has many answers which explains how to revert a commit. But those are to be done in a command prompt which many are un-familiar with. So here am going to explain a easy way to revert a commit in git.

This can be achieved using Git Extensions. You can download it from here link1 or from here link2

Once you download Git Extensions, open it and select the repository where your source code exists.

Once this is done Git Extensions will show you all the commits. Select any specific commit and right click on it. Then select revert commit. Check the below screenshot for reference


Once you select the Revert Commit option, it opens a pop-up like below


Select "Automatically create a commit" if you want to directly commit the reverted changes or if you want to manually commit the reverted changes keep the box un-selected and click on "Revert this commit" button.

In this way you can easily revert any commit in git using Git Extensions.

For more useful articles on git visit this link: Git

Read more...

javascript: typeerror (intermediate value) is not a constructor

It's been long time since i have written a blog post as i am busy with the project deliverable. So, here i am with one more issue which i faced today while writing some basic javascript code.

The error is 

javascript: typeerror (intermediate value) is not a constructor

i came across this issue when i am returning some object from a function. Following is the similar javascript code that i have written

function buildContact() {
        return new { name: "John", mobile: "123-456-7890", country: "US" };
    } 

this is the javascript function which was showing the mentioned error. 

Cause:

I used new which can be only used with a Function as operand. In this case i am using object as a constructor which is actually not. 

Fix:

Here we have two options to fix this error. 

1. To return object directly as shown below
function buildContact() {
        return { name: "John", mobile: "123-456-7890", country: "US" };
    }      

2. Create a constructor and use the constructor to create new object as shown below

function Contact(name, mobile, country) {
        this.name = name;
        this.mobile = mobile;
        this.country = country;
    }

    function buildContact() {
        return new Contact("John", "123-456-7890", "US");
    }

in this case we are returning the new Contact() by using constructor. 

In this way you can fix the error javascript: typeerror (intermediate value) is not a constructor.

Please do comment if you know better way to fix this error. Thanks in advance. 

To know more common javascript errors visit: Javascript 


Read more...

Add new data row to data table Error: 'System.Data.DataRow.DataRow(System.Data.DataRowBuilder)' is inaccessible due to its protection level

We can not directly create a new DataRow() . When we try to do so, it throws this exception

System.Data.DataRow.DataRow(System.Data.DataRowBuilder)' is inaccessible due to its protection level

So in order to create new row in data table use the following method

DataTable table = new DataTable();
DataRow row = table.NewRow();
table.Rows.Add(row);
reference link : https://msdn.microsoft.com/fr-fr/library/9yfsd47w.aspx

In this way you can create a new data row and add it to data table.
Read more...