Tuesday, December 11, 2012

Import hadoop with Eclipse

Eclipse is a good tool for study hadoop code. But it may takes a while to resolve all the links, make tool tip  and declaration jump work.

Here are steps:

1. create a java proj, using j2SE1.5 as your jre (to date it's the highest j2SE you can find in eclipse);
2. symlink src to src in hadoop
3. select proj->Build Path->configure build path, go to library tab
4. click "Add external JARs", and all jars from hadoop dir and lib dir
5. Switch to "Order and Export", check all hadoop-*.jars, click OK
6. select proj -> Refresh

That's it.

When you try to dereference a declaration of a obj, it may prompts you to "Attach file". Just attach to src folder should solve the problem.

 

Tuesday, December 4, 2012

C++ find common factors


It's such easy to do this:

#include <iostream>
using namespace std;

int gcd(int a, int b)
{
if(b == 0)
{
       return a;
}
else
{
return gcd(b, a % b);
}
}

int main()
{
     int a,b;
         
     cout << "Input first number: ";
     cin >> a;
     cout << "Input second number: ";
     cin >> b;
   
     cout << "Greatest common divisior (GCD) is " << gcd(a,b) << endl;
     return 0;
}