Sunday, 15 November 2015

How to add library to an android project in eclipse with steps

Make sure you are adding a library to an android project only.





  1. Download the library to your computer.
  2. Create a new folder, libs, in your Eclipse/Android project.
  3. Right-click libs and choose Import -> General -> File System, then Next, Browse in the filesystem to find the library's parent directory (i.e.: where you downloaded it to).
  4. Click OK, then click the directory name (not the checkbox) in the left pane, then check the relevant JAR in the right pane. This puts the library into your project (physically).
  5. Right-click on your project, choose Build Path -> Configure Build Path, then click the Libraries tab, then Add JARs..., navigate to your new JAR in the libs directory and add it. (This, incidentally, is the moment at which your new JAR is converted for use on Android.)

Monday, 9 November 2015

How to use Git with steps

  1. At first go to the folder in which  using "cd .." and "cd [folder-name]". If you have used in similar way in command prompt, then you don't be guided about the first step.
  2. To first initialize, use "git init"
  3. Then, to check the untracked files, use "git status"
  4. Now, add the files into the tracked ones using "git add [file-name]", if you have not any files in the folder, then you will have to create one and then add.
  5. Use "git commit -m [Message]" to confirm with the message to identify what you are doing.
  6. Create a github account and create a repository there. Now that repository would have a link like https://github.com/[Username]/[Repository-Name].git
  7. Its to time to type the command "git remote add origin [Link-of-the-git]".
  8. Next, push it to cloud using command "git push origin master"
  9. A prompt will appear to type the username and password. Next your files will be the clouded in the desired repository.

 Once I was using "git push origin master" to push  my new update work. But an error was coming:

error: failed to push some refs to 'https://github.com/rajatraj733/firefox-extension.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

http://stackoverflow.com/questions/24114676/git-error-failed-to-push-some-refs-to
Then, I used the above mentioned link to rectify the error. What I did was:-
  1. 1st command: git pull --rebase origin master
  2. 2nd command: git push origin master
And it worked. Sometimes I think what would have happened to the so called developers, had stackoverflow.com not ever started.

By the way, I will explain these things like why such errors happened, later so that I could know the principle of github.

Friday, 6 November 2015

How to sort a pair or a structure based upon its element

For simple sorting in C++, sort() method is used of algorithm header.
e.g.

#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
    int n;
    cin>>n;
    vector<int> a;
    int t;
    for(int i=0; i<n; i++)
    {
        cin>>t;
        a.push_back(t);
    }
    sort(a.begin(), a.end());
    for(int i=0; i<n; i++)
        cout<<a[i]<<" ";
}

Input:
5
4 8 9 2 1

Output:
1 2 4 8 9




But for advanced sorting, where structures would be sorted based upon its one of the element, we need to create a method compare to guide the sort method. Check it out below:


#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
struct node {
    int value;
    int key;
};
bool compare(const node& a, const node& b) {
    return a.key < b.key;
}
int main() {
    int n;
    cin >> n;
    vector<node> a;
    int t1, t2;
    for (int i = 0; i < n; i++) {
        cin >> t1 >> t2;
        node t3;
        t3.value = t1;
        t3.key = t2;
        a.push_back(t3);
    }
    sort(a.begin(), a.end(), compare);
    for (int i = 0; i < n; i++)
    {
        cout << a[i].value << " "<<a[i].key<<endl;

    }
}

Input:
5
4 7
7 4
2 5
9 6
3 8

Output:
7 4
2 5
9 6
4 7
3 8

So, you can check out that the nodes are sorted based upon its "key" variable.
In the similar way, you can sort the pairs based upon its "first" variable or "second" variable, whichever you do want.