Monday 29 April 2013

Finally 2 Karma On News Combinator

I joined news combinator 57 days before (from today i.e. 30th April). Right from the moment I joined it I was figuring out a way of how to increase Karma on this site. I googled same, searched on Quora too but nothing resulted in Success.

But just now I saw 2 written beside my name in news combinator and that feeling itself was awesome. But one question always comes out my mind "Why every site let it be URL aggregator like news combinator or simple question-answer frame-worked site's inculcate the system of Karma ??

Can't we have another system to control Spam??

Python Wikipedia Crawler To Get All Images Of A Page


Although there exist many frameworks to crawl web like Scrapy but there's no need of using all these frameworks for writing simple crawlers.

Aim of this tutorial is to write Wikipedia crawler which will crawl all images of given wikipedia page.

Requirements :

1. Python
2. BeautifulSoup - Python Package
2. urllib and urllib2 - Python Packages


Make sure that above packages are installed. Mostly Python and Urllib comes preinstalled on most version of Linux. To install BeautifulSoup type following command on terminal

>>pip install bs4

Have a look at the code here.

Steps Followed :

1. Send Request to wikipedia to connect to the site.So that data can be transferred.

2. The URL (variable site here) is opened and the source code of url is retrieved and stored into page

3. Finding img tag in whole page

4. Saving the iimages one by one in output folder

Please Contribute on git to make this crawler more useful.  

  

Monday 14 January 2013

What Are Macro Guards ?


What are Macro Guards  ?

Macro Guards are basically constructs to eliminate any chances of  inclusion of any header file more that once. Delving more into the technical aspect, we see that they are  actually pre-processor directive(s) included in header file(s). Let's have a look at it.
   
Example : Consider  header file <area.h>

                                                                  area.h
#ifndef __area_h__  //Macro guards
#define __area_h__ 

//Contents of header file
// Structure is defined here in the header file

struct area
{
float length;
float width ;
}
#endif


In above example :
  • __area_h__ is name of macro it can be any name but make sure that it is unique for each header file. 
  • #ifndef - Preprocessor Directive which means if not defined . If in object file generated by compiler above macro __area_h__ is already defined then rest of header file won't be executed else whole header file will be executed
  • #define - To define variable
  • #endif - To end if block
 for example shown, #ifndef are called as Marco Guards. They guard the whole header file and eliminate chances of their inclusion more that once.

Let's see how ??
Consider one example shown below :


Here class AREA_RECTANGLE is inherited from AREA_SQUARE class.

Implementation of area_rectangle class

                                                          area_rectangle.cpp
#include"area.h"

class area_rectangle
{
  //Implementation of class goes here
};



                                                       area_square.cpp
#include"area.h"

class area_square::public area_rectangle
{
  //Implementation of class goes here
};



Now  in both classes i.e. area_rectangle and area_square, area.h is included .So if we compile area_square.cpp that would add structure  area twice
  1.  one from header file included in area_square.cpp and other from 
  2. area_rectangle.cpp (as area_square class inherits area_rectangle). 
This will throw error saying that member "length" and "width" are already defined.





But due to Macro Guards once __area_h__ is defined in object file while compiling area_rectangle.cpp so again area.h won't be included even if it is included in area_square.cpp
and program is completed successfully.


Sunday 6 January 2013

How To Flash Samsung Galaxy SII (I9100G) With Jelly Beans



In my last post titled Root Samsung Galaxy S-II (I9100G) i had gone through all the steps for rooting your Samsung Galaxy SII Device. Now lets see how to flash Rom with Jelly Beans i.e.Android 4.2

Requirements
 Before starting with installation process please backup your data. It is easy to import data via Samsung Kies to your PC.
 
Important :  Make sure that your device is already rooted with Cynogen Recovery Mode configured. If
this is not done then please refer this link :  Root Samsung Galaxy S-II (I9100G)

Steps for flashing ROM
  1. Transfer files Cynogenmod 10.1 Rom and Google Apps Installer into Internal or External SD card of phone. 
  2. Start device in Cynogen Recovery Mode. To start in Cynogen Recovery Mode first Turn off the phone and wait for 1-2 minutes after phone is completely switched off. Now press Volume-up + Power-off + Home button of your phone simultaneously. Phone will start in Cynogen Recovery Mode.
  3. Now select option Install zip from SD-card  and select the path where Cynogenmod 10.1 ROM's location. (Volume button is to used to move up and down in options and Power button for selecting a option in CM Recovery mode)
  4. Select Yes and wait for ROM to be installed.
  5. Next, select same option Install zip from SD-card and select path where Google App Installer zip is present in SD card . Confirm your installation by pressing selecting Yes.
  6. Let it finish installing all Google Apps. Now Reboot the Phone.
Hurray!!...You installed Jelly Beans in your Galaxy phone.

Now Enjoy your phone with completely new and re-defined UI and features...:)
     

Saturday 5 January 2013

Root Samsung Galaxy S-II (I9100G)



Have you decided to install custom ROM on your galaxy device??...Well!!....nice decision..

So here's a tutorial on how to make it easier and hassle free...
First of all to install Custom Rom you need to Root your Device. Rooting Device means to give super user permission so that programs/applications can access root.

Before Starting with this process i would recommend you to note down your latest OS kernel. To get kernel Version go to "Setting" then "About Phone" option. There you would see kernel  version. Note down this kernel version. Although we won't be using this anywhere in whole process. But it is safe to note it down somwhere.....

Requirement
  • Samsung Galaxy SII I9100G (Make sure that version is same. You can verify same from "About Phone" option in "Settings" )
  • Laptop /PC (Win XP/7 Preferably)
  • USB Cable
  • Root_S2_i9100G File
  • Odin 3 v 1.85
  • Samsung Kies  
Follow These Steps to Root it...

Install Samsung Kies in your PC (it not installed). After installing kies connect your phone to Kies via USB cable. This is to make sure that all required drivers are installed successfully. Disconnect Device from PC after this step.

Power off your Phone. Phone should completely be off .Wait for 1-2 minutes after it is completely off.

Now Start Device in Download Mode by pressing Volume Down Key, Power Button and Home key simultaneously.
                                                        

            Press Volume up Button to enter in Data transfer Mode (At this time if u feel like quitting the  process  then just press power button for few seconds. Phone will Reboot Automatically)
       
        Start Odin in PC by clicking odin3 v1.85.exe and connect Phone to PC.In Odin at ID:COM  it should appear the USB cable as connected(COM1,COM2 etc) .Yellow Bar with something as COM shows that the device is recognized.


   
Auto Reboot and F.Reset time check-boxes should be checked in Odin window Rest all check-boxes should be unchecked. (As shown in above screenshot)

Click on PDA command button and select Location where Root_S2_i9100G File was downloaded in PC.

Click Start and Have coffee (or tea) till Odin shows "Pass"...

Congratulations!!....
You Successfully Rooted your  Device... :)

Restart Device and to check if device is successfully rooted  download app named "Superuser" from Play Store... It will check and will inform you if device is rooted or not...