Thursday, 23 July 2015

Top Underrated Git Commands

Here are the most important commands in git , and their description .


git reset –hard origin/master 
Resets your Local Repo with HEAD
git reflog
Displays a walkthrough of git cycle through out your local repo with commit references.
git cherry
Note: Cherry and Cherry-pick are two different commands, Cherry displays a list of commit differences between branches/remotes
e.g git cherry master staging OR git cherry -v staging
git cherry-pick
Adds a commit to your current branch.
git shortlog
Displays Author and no of commits.e.g git shortlog -s -n
git shortlog
Everyone of us must be knowing what git logs can do , Today lets trick it out a advanced feature of Git log.
Lets take an example , Some one have merged master with staging and pushed accidentally.
I want to know who did it , who merged the changes because git will say the commit author name.
To do so we need to run
git log --pretty='%T %s --Commiter: %cn --Author: %aN'
Other method would be to open gitg and check author and committer name.
Author name is who changed the content in file and commiter is who merged or changed the commit history to your branch.

Thursday, 25 June 2015

Solved : Mule With Maven Failing

Recently , i encountered an error with maven build.

The pom file which i was using , started failing with failed dependency errors .It was working fine earlier.
Here is the error which i was getting while trying to build mule app with maven .

 Failed to execute goal on project middleware-services: Could not resolve dependencies for project com.javaroots:my-services:mule:1.0: Failed to collect dependencies at org.mule.transports:mule-transport-vm:jar:3.5.0 -> org.mule.modules:mule-module-xml:jar:3.5.0 -> net.java.dev.stax-utils:stax-utils:jar:20080702: Failed to read artifact descriptor for net.java.dev.stax-utils:stax-utils:jar:20080702: Could not transfer artifact net.java.dev.stax-utils:stax-utils:pom:20080702 from/to codehaus (http://repository.codehaus.org): Failed to transfer file: http://repository.codehaus.org/net/java/dev/stax-utils/stax-utils/20080702/stax-utils-20080702.pom. Return code is: 410, ReasonPhrase: Gone. -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal on project my-services: Could not resolve dependencies for project com.javaroots:middleware-services:mule:1.0: Failed to collect dependencies at org.mule.transports:mule-transport-vm:jar:3.5.0 -> org.mule.modules:mule-module-xml:jar:3.5.0 -> net.java.dev.stax-utils:stax-utils:jar:20080702
 at org.apache.maven.lifecycle.internal.LifecycleDependencyResolver.getDependencies(LifecycleDependencyResolver.java:221)
 at org.apache.maven.lifecycle.internal.LifecycleDependencyResolver.resolveProjectDependencies(LifecycleDependencyResolver.java:127)
 at org.apache.maven.lifecycle.internal.MojoExecutor.ensureDependenciesAreResolved(MojoExecutor.java:257)
 at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:200)
 at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
 at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
 at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
 at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
 at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
 at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
 at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
 at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
 at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
 at org.apache.maven.cli.MavenCli.execute(MavenCli.java:862)
 at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:286)
 at org.apache.maven.cli.MavenCli.main(MavenCli.java:197)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:483)
 at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
 at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
 at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
 at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)

Caused by: org.eclipse.aether.resolution.ArtifactResolutionException: Could not transfer artifact net.java.dev.stax-utils:stax-utils:pom:20080702 from/to codehaus (http://repository.codehaus.org): Failed to transfer file: http://repository.codehaus.org/net/java/dev/stax-utils/stax-utils/20080702/stax-utils-20080702.pom. Return code is: 410, ReasonPhrase: Gone.
 at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:444)
 at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolveArtifacts(DefaultArtifactResolver.java:246)
 at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolveArtifact(DefaultArtifactResolver.java:223)
 at org.apache.maven.repository.internal.DefaultArtifactDescriptorReader.loadPom(DefaultArtifactDescriptorReader.java:287)
 ... 41 more
Caused by: org.eclipse.aether.transfer.ArtifactTransferException: Could not transfer artifact net.java.dev.stax-utils:stax-utils:pom:20080702 from/to codehaus (http://repository.codehaus.org): Failed to transfer file: http://repository.codehaus.org/net/java/dev/stax-utils/stax-utils/20080702/stax-utils-20080702.pom. Return code is: 410, ReasonPhrase: Gone.
 at org.eclipse.aether.connector.basic.ArtifactTransportListener.transferFailed(ArtifactTransportListener.java:43)
 at org.eclipse.aether.connector.basic.BasicRepositoryConnector$TaskRunner.run(BasicRepositoryConnector.java:355)
 at org.eclipse.aether.util.concurrency.RunnableErrorForwarder$1.run(RunnableErrorForwarder.java:67)
 at org.eclipse.aether.connector.basic.BasicRepositoryConnector$DirectExecutor.execute(BasicRepositoryConnector.java:581)
 at org.eclipse.aether.connector.basic.BasicRepositoryConnector.get(BasicRepositoryConnector.java:249)
 at org.eclipse.aether.internal.impl.DefaultArtifactResolver.performDownloads(DefaultArtifactResolver.java:520)
 at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:421)
 ... 44 more
Caused by: org.apache.maven.wagon.TransferFailedException: Failed to transfer file: http://repository.codehaus.org/net/java/dev/stax-utils/stax-utils/20080702/stax-utils-20080702.pom. Return code is: 410, ReasonPhrase: Gone.
 at org.apache.maven.wagon.providers.http.AbstractHttpClientWagon.resourceExists(AbstractHttpClientWagon.java:724)
 at org.apache.maven.wagon.providers.http.AbstractHttpClientWagon.resourceExists(AbstractHttpClientWagon.java:680)
 at org.eclipse.aether.transport.wagon.WagonTransporter$PeekTaskRunner.run(WagonTransporter.java:518)
 at org.eclipse.aether.transport.wagon.WagonTransporter.execute(WagonTransporter.java:427)
 at org.eclipse.aether.transport.wagon.WagonTransporter.peek(WagonTransporter.java:398)
 at org.eclipse.aether.connector.basic.BasicRepositoryConnector$PeekTaskRunner.runTask(BasicRepositoryConnector.java:376)
 at org.eclipse.aether.connector.basic.BasicRepositoryConnector$TaskRunner.run(BasicRepositoryConnector.java:350)
 ... 49 more
The reason for failure of this is , Codehaus no longer serves up Maven repositories . So we need to change maven settings a little bit to make this work . Go to your M2_HOME/conf folder and open settings.xml .

Create following repo profile and activate it .
<profile>
   <id>mule</id>
  <repositories>
  <repository>
    <id>codehaus-mule-repo</id>
    <name>codehaus-mule-repo</name>
    <url>
      https://repository-master.mulesoft.org/nexus/content/groups/public/
    </url>
    <layout>default</layout>
  </repository>
</repositories>
 </profile>
<activeProfiles>
    <activeProfile>mule</activeProfile>
</activeProfiles>
And run the project again . It will work .

Ref : StackOverflow



Post Comments And Suggestions !!

Tuesday, 23 June 2015

How to Commit only part of a file in Git

Today we will be discussing How to Commit only a Part of File in Git , Instead of Commiting the whole file , basically useful if you have dev ,prod ,and other environment parameters in same file


Lets Take an Example of a file named database.yml which has three environment(development, staging and production).


I have changed the Credentials for Development/staging/Production, and I need to commit the file for production/staging change frequently keeping development changes in my local.

So, Instead of reverting the changes of development and commiting the files we can Patch the changes into chunks and commit.


Syntax : git add --patch filename.x (or -p for short) Stage this hunk [y,n,q,a,d,/,j,J,g,s,e,?]?

And here the meaning of each option:

y stage this hunk for the next commit.
n do not stage this hunk the next commit
q quit; do not stage this hunk or any of the remaining ones
a stage this hunk and all later hunks in the file
d do not stage this hunk or any of the later hunks in the file
g select a hunk to go to
/ search for a hunk matching the given regex
j leave this hunk undecided, see next undecided hunk
J leave this hunk undecided, see next hunk
k leave this hunk undecided, see previous undecided hunk
K leave this hunk undecided, see previous hunk
s split the current hunk into smaller hunks
e manually edit the current hunk
? print help



In Our Example:


git add --patch config/database.yml
So It will break the changes into chunk and ask :

 production:

   adapter: oracle_enhanced

-  database: //localhost:29801/mydb

-  username: mydb

-  password: mydb

+  database: //192.168.1.45:1521/ORCL

+  username: santosh

+  password: santosh 

Commit only part of a file in Git 

Stage this hunk [y,n,q,a,d,/,K,g,s,e,?]? y
Continue Providing the Options for Development & Production .


Finally you will see a Staged Config/database.yml and a unstaged config/database.yml

So this is how we commit part file in git .

Thanks To Santosh for writing this post .

Friday, 19 June 2015

How To Enable Mass Storage on YU

This document describes how to connect mobile phones (like Yuphoria,Yureka), which are based on Cyanogenmod OS as Mass Storage/MTP in Linux.

This is a solution for ticket : https://jira.cyanogenmod.org/browse/YU-4This post will enable you to mount your device sd card and internal storage on PC .

STEP 1

Firstly we're going to need to install some of the common MTP apps that will be needed. Open up a terminal and type the following two lines one after the other.
sudo apt-get install libmtp-common mtp-tools libmtp-dev libmtp-runtime libmtp9
sudo apt-get dist-upgrade
STEP 2

Then we're going to amend the fuse.conf file. At the terminal type
sudo nano /etc/fuse.conf
We want to remove the # from the below line of code for user_allow_other, like so...
#/etc/fuse.conf - Configuration file for Filesystem in Userspace (FUSE)

#Set the maximum number of FUSE mounts allowed to non-root users.
#The default is 1000.
#mount_max = 1000

# Allow non-root users to specify the allow_other or allow_root mount options.
user_allow_other

Now save the file by pressing Ctrl+x, press Y and then Enter.


STEP 3

We now need to set up some rules for our device that we plan on connecting, but before we do that we need to find out.

Connect your device via an available usb port and from terminal enter
lsusb
This should bring up an output similar to the following

usermac44@usermac44:~/workspace/ps$ lsusb 
Bus 002 Device 004: ID 17ef:6019 Lenovo  
Bus 002 Device 003: ID 04b3:3025 IBM Corp. NetVista Full Width Keyboard 
Bus 002 Device 003: ID 0fce:01b1 Yuphoria Inc.  
Bus 002 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub 
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub 
Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub 
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub 

You need to look for your device, in this instance my Yuphoria in the list, the vendor id is 0fce and product id is 01b1 .


STEP 4

We're then going to amend the mtp udev rules as follows, from a terminal type :
sudo nano /lib/udev/rules.d/69-mtp.rules
# Yuphoria YU5010
ATTR{idVendor}=="0fce", ATTR{idProduct}=="01b1", SYMLINK+="libmtp-%k", ENV{ID_MTP_DEVICE}="1", ENV{ID_MEDIA_PLAYER}="1"
Once done, save the file.


STEP 5

The next step would also be to add a line of code to the 51 android rules file, again from a terminal type
sudo nano /etc/udev/rules.d/51-android.rules
ATTR{idVendor}=="0fce", ATTR{idProduct}=="01b1", MODE=”0666"
put your device product id and vendor id here .

Once that is done and the file is saved, remove any usb device currently connected and issue the following commands to reboot the system.
sudo service udev restart
sudo reboot
Enjoy Using Mass Storage in Yureka/Yuphoria (Cyanogen) Mobile Phones.


Post Comment , if any better solutions found


Thursday, 21 May 2015

Top 20 ROR Interview Questions

Some of the most important questions asked in Barclays India And TCS for Ruby On Rails Developer Position , but these questions can be asked in any company which is recruiting ROR developers .


• What are Modules in Apache?

• How does HTTP work, and specifically how does a web page appear in my browser?

• How to link your public directory to apache conf to serve assets ?

• How would you assess how “deployable” a software system is?

• What is Tracebility Matrix ?

• What is Resident memory in Ruby ?

• How New Relic works on different components of rails ?

• What are components of Puppet ?

• What is the difference between Puppet. Vagrant and Docker

• How to Load balance servers using Ruby Modules ?

• What is LDAP & AD how to configure them ?

• What is DML, DCL, DDL in SQL ?

• How to Replicate a NoSQL DB ?

• What is Kernel Programming in ruby how to bind and unbind Context in ruby?

• Write a Nagios Plugin in ruby which returns the health on mysql ?

• What is Database Sharding ?

• Which backup is Good when it comes to backing up database and why ?(Hint: Incremental or Differential)

• How would you monitor your Rails Application Performance ?

• What are the Different deployment tools(Automation) available in ruby ?

• What is MVVM in Javascript ?

Post Comments And Suggestions And Answers if you know them .

Thanks Amit for compiling this list .

Monday, 18 May 2015

How to Create Index With MongoDB 3 Java Driver

Sample Java Program to Create Index in MongoDB 3 Java Driver . This snipped also contains older code which was used to create index . You just need to create a BasicDBObject with key as a name on which you want to create a index , and value will be 1 or -1 . if you create it with 1 then it will create a ascending index , and if you create with -1 , then it will create descending index .
package mongoDBExample;

import java.util.Arrays;
import java.util.List;

import org.bson.Document;

import com.mongodb.BasicDBObject;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.DBObject;
import com.mongodb.MongoClient;
import com.mongodb.MongoClientURI;
import com.mongodb.client.ListIndexesIterable;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoCursor;
import com.mongodb.client.MongoDatabase;

public class MongoDBTest
{
 public static void main(String[] args)
 {
  MongoClient mongoClient = new MongoClient(new MongoClientURI("mongodb://localhost:27017"));
  
  /*MongoDatabase database = mongoClient.getDatabase("Test");
  List books = Arrays.asList(1251,2512);
  Document person = new Document("_id", "ABHSIHEK")
                              .append("name", "java roots")
                              .append("address", new BasicDBObject("street", "sad java")
                                                           .append("city", "mongos")
                                                           .append("state", "mongod")
                                                           .append("zip", 5151))
                              .append("books", books);
  
  MongoCollection collection= database.getCollection("people");
     collection.insertOne(person);*/
  
  MongoDatabase database = mongoClient.getDatabase("Test");
  MongoCollection collection= database.getCollection("people");
  //create index on name field 
                //use 1 for ascending index , -1 for descending index 
  BasicDBObject index = new BasicDBObject("name",1);
  
  collection.createIndex(index);
  System.out.println(" index created successfully ");
  ListIndexesIterable indexes = collection.listIndexes(BasicDBObject.class);
  MongoCursor cursor = indexes.iterator();
  while(cursor.hasNext())
  {
   BasicDBObject getCreatedIdx = cursor.next();
   System.out.println("index is : "+ getCreatedIdx.toString());
  }
  
  
  
  mongoClient.close();
  /**
   * Older code which is deprecated in 3.0
   */
  /*
  DB db = mongoClient.getDB("Test");
  List books = Arrays.asList(27464, 747854);
  DBObject obj = new BasicDBObject("_id", "javaroots").append("name", "java roots")
                .append("address", new BasicDBObject("street", "awesome java")
                .append("city", "mongos")
                .append("state", "mongod")
                .append("zip", 5151))
.append("books", books);;
  
  DBCollection col = db.getCollection("people");
  col.insert(obj);
                col.createIndex("name");*/
        
  
 }
}



Post Comments And Suggestions !!




Friday, 15 May 2015

MongoDB 3 With Java

Here is the simple java program to insert data in MongoDB database. version 3.0 API is changed a bit . MongoClient.getDB method is deprecated and MongoClient.getDatabase() is used , which returns an instance of MongoDatabse type .

package mongoDBExample;

import java.util.Arrays;
import java.util.List;

import org.bson.Document;

import com.mongodb.BasicDBObject;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.DBObject;
import com.mongodb.MongoClient;
import com.mongodb.MongoClientURI;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;

public class MongoDBTest
{
 public static void main(String[] args)
 {
  MongoClient mongoClient = new MongoClient(new MongoClientURI("mongodb://localhost:27017"));
  
  MongoDatabase database = mongoClient.getDatabase("Test");
  List books = Arrays.asList(1251,2512);
  Document person = new Document("_id", "ABHSIHEK")
                              .append("name", "java roots")
                              .append("address", new BasicDBObject("street", "sad java")
                                                           .append("city", "mongos")
                                                           .append("state", "mongod")
                                                           .append("zip", 5151))
                              .append("books", books);
  
  MongoCollection collection= database.getCollection("people");
     collection.insertOne(person);
  mongoClient.close();
  /**
   * Older code which is deprecated in 3.0
   */
  /*
  DB db = mongoClient.getDB("Test");
  List books = Arrays.asList(27464, 747854);
  DBObject obj = new BasicDBObject("_id", "javaroots").append("name", "java roots")
                .append("address", new BasicDBObject("street", "awesome java")
                .append("city", "mongos")
                .append("state", "mongod")
                .append("zip", 5151))
.append("books", books);;
  
  DBCollection col = db.getCollection("people");
  col.insert(obj);*/
        
  
 }
}


Also we dont need to use getLastError method , because now exception is thrown if any error occurs .


Post Comments And Suggestions !!