I am writing this blog almost after an year now but now I guess I would be blogging more frequently then before….

So, in this blog what I want to focus on is the refactoring of XML file and the to edits in the file.
(For those who don’t know what re-factoring is, you can read this Wikipedia Article.)

Now sometimes your XML file is in a single line and you have to store it back somewhere in that single line format after editing so this guide is for you.
And again there are some developers who are forced to work in Notepad++(if you know what I mean😉 ) and that too in Windows environment(with restrictions), they may also take the help of this post🙂

To refactor a XML file :

  1. Go to TextFX in the Menu Bar.
  2. then “TextFX HTML Tidy”
  3. And then use “Tidy: Reindent XML”

These steps would re-indent yuor XML file according to the tags hierarchy (even if the tags used are User Defined).

Then you can edits the tags as not it code would be more easy to read and understand…🙂

Now, lets say that you have you save the file again in the a single line, the you must follow these steps in the same order:

  1. Press Ctrl + H, it would open the Replace Pop-up Box.
    • Type “/r/n” (without quotes) in the find textbox and nothing in the Replace Text Box.(select Extended in the Serach Mode box)
      This would replace all you new lines(or Enter Keys).
  2. Type “>(\s*)<” in the Replace Box.(this time select “Extended” in the Search Mode Box)
    This would replace all your unneccessary white spaces between a start and end tags.(This option is Optional though.)

And tada..!!
Your refactored XML is again in one single line(as is needed to be stored)…!!!

Do more than belong : Participate.
Do more than care : Help.
Do more than believe : Practice.
Do more than be fair : Be kind.
Do more than forgive : Forget.
Do more than dream : Work.

By William Aurther Ward

Quote  —  Posted: June 15, 2013 in Quotes

It just so happened recently that I needed to work and GitHub with two accounts, one on the project for the company i am working an intern as and one of my personal project.!
And to verify my emailId and password to gitHub for each project(because of different github accounts), was totally annoying.!!
So here’s an easy way to manage multiple accounts on a single machine.!
(It is assumed that you have set up an ssh-verification for your first account)

First create a new SSH key for your second account(in my case my Company’s Github Account).
$ ssh-keygen -t rsa -C "your-emailId
But be careful not to over-write your existing key for your personal account. Instead, when prompted, save the file as id_rsa_COMPANY.

Next attach the new generated ssh key to your GitHub account, browse to “Account Overview,” and attach the new key, within the “SSH Public Keys” section. To retrieve the value of the key that you just created, return to the Terminal, and type:
$ vim ~/.ssh/id_rsa_COMPANY.pub.
Copy the entire string that is displayed, and paste this into the GitHub textarea. Feel free to give it any title you wish.
Next, because we saved our key with a unique name, we need to tell SSH about it. Within the Terminal, type:
$ ssh-add ~/.ssh/id_rsa_COMPANY.
If successful, you’ll see a response of “Identity Added.”

We’ve done the bulk of the workload; but now we need a way to specify when we wish to push to our personal account, and when we should instead push to our company account. To do so, let’s create a config file for that.
$ vim ~/.ssh/config
(if you are not comfortable with vim, you can use just any other text editor for the purpose)

Now copy the following lines:

#Default GitHub

Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa

Host github-COMPANY
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_COMPANY

Here the First part is the default configuration for our personal GitHub account and the second part is for our Company’s GitHub accoount.
The Difference being the host name; instead of github.com we changed it to github-COMPANY and are attaching the new identity id_rsa_COMPANY that we created earlier.
Save the file and exit.

That’s all folks now you are ready to use different account for different projects without any headache.

Now to test all our work just create a test directory and initialize git, and make your first commit:
$ git init
$ git commit -m "My First Commit"

Login to your Company’s account, create a new repository and name it same as the test folder, anreturn to the terminal and push your local repository:
$ git remote add origin git@github-COMPANY:Company/test.git

Note that, this time, rather than pushing to git@github.com, we’re using the custom host that we create in the config file: git@github-COMPANY.

Return to GitHub, and you should now see your repository.
Remember: When pushing to your personal account, proceed as you always have.
But for your company account, make sure that you use git@github-COMPANY as the host.

I myself am a beginner in gdb but I know exactly how it feels when someone say “trying debugging that segmentation fault using gdb.

So, to your rescue, I have done the hard part. And here’s a quick and easy guide for a beginner.
First of all you need to ensure the following pre-requisites before debugging a segmentation fault with gdb:

    1. Make sure you have compiled the executables with “-g” command line switch, which will also produce debugging information for the gdb to work easily.

eg. gcc -g main.c -o main.o

  1. LINUX should be able to core-dump on a Segmentation Fault;
    $ ulimit -c unlimited
    (for more info do man info
    )

Now just run that the executable that is segfaulting. As soon as it segfaults, you should get an output something like:
Segmentation fault (core dumped)

Then, ls in your working directory and you will find a new core file has been created.
(probably with the name core.{pid})

Now, we just have to tell gdb to analyze this core. Here’s how
$ gdb {executable} {dump file}
eg. $ gdb hello core.1324

Check out the output spit out by gdb and make sure that all debugging symbols have been successfully loaded.

Now, you should see something like:
(gdb)
Congratulations!! you are in gdb now.

Now type :
(gdb)info line
It gives you the line number, function name and file name on which the segfault occurred.
(Sometimes, it gives the address of a header file function, in that case you can use (gdb)bt to backtrace the Function Calls…)

You can also make use of the following commands in gdb:

  • To would print the values of the local variables(variables local to the function):
    (gdb)info locals
  • To would print the values of the arguments passed to the function(that you is currently in)use:
    (gdb)info args
  • To print the value of any specific variable you can use:
    (gdb)print var_name
  • And to print the value that a pointer point to you can use(mind you the asterisk is necessary):
    (gdb)print *ptr_name
  • To call a particular function in between use:
    (gdb) call function_name()

You can also run the program inside gdb using the command:
(gdb)run [args]

Also gdb allows you the flexibility to stop the execution at any line number in any file using the breakpoints command:
(gdb)break
Creates a breakpoint at current line.
(gdb)break [filename]:line_number
Creates a berakpoint in the filename at line:line_number.
(gdb)break [filename]:function_name
Creates a breakpoint in filename at the line where function_name starts.

You can get the info of all the breakpoints by:
(gdb)info breakpoints

There are three kind of gdb operations you can choose when the program stops at a break point. They are continuing until the next break point, stepping in, or stepping over the next program lines.

gdb commands for the same are:

  1. c or continue : Debugger will continue executing until the next break point.
  2. n or next : Debugger will execute the next line as single instruction.
  3. s or step : Same as next, but does not treats function as a single instruction, instead goes into the function and executes it line by line.

gdb also provides some shortcuts to facilitate a user:

  • p – print
  • c – continue
  • s – step
  • ENTER: pressing enter key would execute the previously executed command again.
  • q - quit: Exit from the GNU debugger.

Recently, I needed to view the binary information of the file(Because I wrote a file with enum data type values) in Ubuntu. And I was not able to view the content of the file easily, because most of the text editors read the file in UTF-8 format.
So I searched Google for reading the file’s binary content and view it in VIM(cause I was working in it).
But it seems that there’s was no direct way to see the content but to dump the content in a hex format in Vim buffer.

So here’s it is I am sharing the useful command for the same(if anyone do need that ever):

:r !xxd <filname>

And voila the hex dump of the file is there on the vim screen.
But make sure you have opened vim first and are typing this command in it’s command mode.

And if you are not a Vim person you can always make use of beav – an open source binary file editor and viewer.🙂😀

Starting with Git on Ubuntu

Posted: May 24, 2013 in Git, Ubuntu
Tags: , , ,

Starting to use a VCS (Version Control System) like Git or Bazaar is a pain, and that too on a LINUX machine.
I myself started using it a Year back and to tell the truth it was a headache in the starting and then it slowly started making sense.

So for the beginners here’s a tutorial to start with.
(I am considering that the reader has a GitHub Account already.)

First of all, you need to have git installed on your machine, to install git on Linux you can:

  • Either install it through the Ubuntu Software Center..
  • Open a terminal using Ctrl+Alt+T and then type the following command:

sudo apt-get install git

.
Its easy and you do not have to verify your credentials again and again.

And you are set to start making your project and uploading(pushing) your source to GitHub.

Enjoy!!

Install wxPython on Ubuntu 12.04

Posted: May 23, 2013 in Python, Ubuntu
Tags: ,

As the official wxPython Wiki is not yet updated with the recent versions like Ubuntu 12.04. I had found a workaround.

Run the following Command:

sudo apt-get install python-wxgtk2.8 python-wxtools wx2.8-doc wx2.8-examples  wx2.8-headers   wx2.8-i18n

And wxPython would be installed without any problem.🙂

There’s no short-cut to Learning..!!

Quoted.!!

Quote  —  Posted: April 3, 2013 in Quotes

So this post is about my quest of switching to Windows-8 on my HP-pavillion-dv6 with ubuntu-12.04 and Windows-8 and Window-7 (triple boot) and at the same time fool the uptime utility in Ubuntu so that I could shoe w to my friends that I ran my computer for almost a month without turning it off or restart it😀 (the trick was to get it hibernated so that it’s state gets save).

I am used to let a lot of tabs open in chrome(but now I like Firefox instead because of it’s low memory consumption).
So one day I needed to switch to windows to create my resume in microsoft office(didn’t have LaTeX setup at that time, also wanted to create it fast mainly). And I thought that I would hibernate my system to get to Windows; but alas Ubuntu-12.04 installation comes with pre-disabled hibernation. So I googled it about how to enable it (because I have previously used hibernation on Ubuntu 11.10).

So I found the official documentation here . But then I had another problem which I came across some page about the size of the swap partition to be greater that the RAM size( beacause mine was only 1/4th of it)😦.
So, I googled again to increase the swap size. But my bad fate, resizing a partition meant to restart the system. So now my system that was running for continuous 10 days was about to restart😦 (but only for the long run🙂 ).

I’ll complete the rest of the blog later. Not feeling well now.

This post is for the beginners who want to set-up the Eclipse IDE Environment for Developing Android Apps with/without the Internet connection.

 

 

Automated Way :

Installing the Eclipse IDE

1.) Download the Eclipse for Java/Mobile Developers from Download Eclipse page (Eclipse Juno 4.2 was the latest version at the time of writing this post).

2.) Extract the tar ball(downloaded .tar.gz file) to a folder (preferably to the home Directory in Android/Eclipse/).

3.) Double-Click the Eclipse Binary/Executable File in the folder.

Setting the Android Development Environment

4.) Click on the HELP menu and Select the “Install New Software”.

5.) Enter “https://dl-ssl.google.com/android/eclipse/&#8221; in the Work with text-box and wait for the links to be downloaded. Also enter the name “ADT Plugin” in the Name.

6.) Select all the Check-Boxes and complete the setup by clicking Next and then accepting the License Agreement of Google. And then Restarting Eclipse.

7.) Download the SDK Tools for Android from Android Developers site.

8.) Extract the SDK to a folder(under the directory Android/SDK-Tools/).

9.) Open the SDK manager in Eclipse (from Window Menu) and set the path for the SDK folder.

10.) Download the Android API level that you want to make your application on.

11.) Open the Android Virtual Device Manager and create the Virtual Emulator for one of your Android API level to test your App.

Manual Way :

Repeat the steps up-till 3 and then :

4.) Download the ADT Plugin :

Package Size MD5 Checksum
ADT-21.0.0.zip 13556487 bytes 7db4eaae5df6a34fd853317a2bd8250b

(This is the Latest version at the time of writing the post)

6.) Click on the HELP menu and Select the “Install New Software”.

7.) Click on ADD and then select the Archive Option. Select the ADT zip file that you downloaded and write the name “ADT Plugin”. Click OK.

8.) Select all the Check boxes and click Next. Accept the Google’s Agreement and click Finish. Restart Eclipse to be able to use the installed ADT Plugin.

9.) Download the SDK Tools here. ( And UnZip it to the Folder Android/SDK-Tools/)

10.) Open the SDK manager in Eclipse (from Window Menu) and set the path for the SDK folder.

11.) Download the SDK that you want to work with here.

12.) Unzip and move the Unzipped folders to Android/SDK-Tools/Platform/)

13.) Restart Eclipse and then open the Android Virtual Device manager.

14.) Click on the NEW button and set up the Emulator to test your apps.

DONE.