Friday, July 29, 2011

Git - Basic Commands

You can create an github account inorder to avail a free online git repository service. It’s not as normal site registration. It contains many steps including the set up of passphrase and keys.

You can also set up a git repository in your system also. For that you need to install the git packages first. For installing git package in your ubuntu or other Debian based system, type the following command,

$ sudo apt-get install git-core

We need to set our username and email id.

$ git config --global "Ajay Soman"
$ git config --global

Then you can create a git repository in the current directory.

$  git init

If want to add a corresponding file in the current directory,

$  git add filename

If you want to add all files then,

$ git add .

We cannot see the git repository in our current directory. It is hidden. Use ctrl+H to see the hidden files. Now commit all updates,

$ git commit -m 'first commit'

You can see the status of the repository to track the unstaged and updated files by the command,

$ git status

To see what you’ve changed but not yet staged, type git diff with no other arguments,

$ git diff

If you want to see what you’ve staged that will go into your next commit, you can use,

$ git diff –cached

To view the log of all the actions that are performed on the repository, use the following command,

$ git log

You can also clone a file from the github repository to own local machine. We need the exact URL of the online repository for that.

$ git clone url

These are the some basic commands that are used in Git to manage the files in it.



Friday, July 22, 2011

Three states of a file in Git

In my previous post I explained you the main advantages of Git. Here we need to concentrate on the main states that a file will face in Git.

Git has three main states that your files can reside in: committed, modified and staged. Committed means that the data is safely stored in your local database. Modified means that you have changed the file but have not committed it to your database yet. Staged means that you have marked a modified file in its current version to go into your next commit snapshot. This leads us to the three main sections of a Git: the Git directory, the working directory, and the staging area.

The Git directory is where Git stores the metadata and object database for your project. This is the most important part of Git, and it is what is copied when you clone a repository from another computer.

The working directory is a single checkout of one version of the project. These files are pulled out of the compressed database in the Git directory and placed on disk for you to use or modify.

The staging area is a simple file, generally contained in your Git directory, which stores information about what will go into your next commit. It’s sometimes referred to as the index, but it’s becoming standard to refer to it as the staging area.



Thursday, July 21, 2011

Git - Characteristics

I have introduced you the powerful DVCS, Git in my previous post. In this post, I give emphasis on the characteristics and advantages of Git.

Other version control systems like Bazaar, Subversion and CVS treats their data as a set of files and the changes made to each file over time.

Git doesn’t think of or store its data this way. Instead, Git thinks of its data more like a set of snapshots of a mini file system. Every time you commit, or save the state of your project in Git, it basically takes a picture of what all your files look like at that moment and stores a reference to that snapshot.

Most operations in Git only need local files and resources to operate — generally no information is needed from another computer on your network. To browse the history of the project, Git doesn’t need to go out to the server to get the history and display it for you — it simply reads it directly from your local database. If you want to see the changes introduced between the current version of a file and the file a month ago, Git can look up the file a month ago and do a local difference calculation, instead of having to either ask a remote server to do it or pull an older version of the file from the remote server to do it locally.

Everything in Git is check-summed before it is stored and is then referred to by that checksum. This means it’s impossible to change the contents of any file or directory without Git knowing about it. The mechanism that Git uses for this check summing is called a SHA-1 hash. A SHA-1 hash looks something like this:


When you do actions in Git, nearly all of them only add data to the Git database. It is very difficult to get the system to do anything that is not undoable or to make it erase data in any way. After you commit a snapshot into Git, it is very difficult to lose.

Another important thing that should be kept in mind is the three states of files in Git. I will come through that in my next post.



Wednesday, July 20, 2011

Git - An introduction

Before going to Git, I want you to familiar with the versions or revisions. What is a version? In our concern, versions have definition like : a version is any change in form.

Suppose we are working in a project for developing a computer game. Suppose the game have a size of 1GB. If we want to make a change in the code, first we take a copy of the game in order to rollback in the future. So we need another 1GB in the hard disk. Imagine if hundreds of software engineers are updating the game, how much memory will be consumed by them? Is it a efficient way?

Here comes the advantage of a version control system. The version control system keeps various versions of the updates, not the entire software. It keeps the snapshots or current stage of the software and saves them as versions. So when programmers make changes and commit the changes, a new version is saved. We can rollback to any version at any time.

Software versioning is the process of assigning either unique version names or unique version numbers to unique states of computer software. A revision control is often used for keeping track of incrementally different versions of electronic information, whether or not this information is actually computer software. A Revision is the state at a point in time of the entire tree in the repository. The repository is where files' current and historical data are stored, often on a server.

The major DVCS(Distributed Version Control Systems) are Git, Mercurial, Bazaar, Fossil, Codeville, SVK etc. These all are open source DVCS tools. TeamWare and BitKeeper are the examples of proprietary DVCS tools.

In my main project I’m using the powerful DVCS – Git – to keep track of the versions of wiki articles. Git is developed by the famous Linus Torvalds. He was the developer of Linux also. Its initial release was on April 2005 and it is written in C, Bourne Shell and Perl. Git is primarily developed on Linux, but can be used on other Unix-like operating systems including BSD, Solaris and Darwin. Git is extremely fast on POSIX-based systems such as Linux. It can be also used in Windows systems.

The following websites provide free source code hosting for Git repositories:

You can create a free account in GitHub and I will post soon about how we can create and configure a repository in the GitHub.


Sunday, July 17, 2011

SQLite - Some basic commands

I have introduced you the SQLite database in my previous posts. I also showed a python program to work with the SQLite. Now I want you to familiar with the basic commands that are used in the SQLite3.

Open your terminal and type, sqlite3 followed by a database name and press enter. Look at the code given below,

ajay@AJAY:~$ sqlite3 ajay.db
SQLite version 3.6.22
Enter ".help" for instructions
Enter SQL statements terminated with a ";"

Now we can type the SQLite commands here. We can create a table in database, here ajay.db.

sqlite> create table t1(one varchar(10), two smallint);

We just created a table with name t1 and two variables one and two. We can see its structute by typing the code below,

sqlite> select * from sqlite_master;

Now we get the structure of the table.

table|t1|t1|2|CREATE TABLE t1(one varchar(10), two smallint)

This type of displaying the structure seems little bit strange. We can change the mode of display.

sqlite> .mode line

Now see the structure of the table. It will be like,

sqlite> select * from sqlite_master;
    type = table
    name = t1
tbl_name = t1
rootpage = 2
     sql = CREATE TABLE t1(one varchar(10), two smallint)

We can now add some values to the table by insert into command.

sqlite> insert into t1 values('hello!',10);
sqlite> insert into t1 values('goodbye', 20);

Now we can view the contents of the table t1.

sqlite> select * from t1;
  one = hello!
  two = 10

  one = goodbye
  two = 20

We can also change this mode of display. In other databases we see a user friendly table structured display. We can also set that in SQLite.

sqlite> .mode column
sqlite> select * from t1;
hello!      10        
goodbye     20        

But still the field names are not there. We need to set the header.

sqlite> .header on
sqlite> select * from t1;
one         two       
----------  ----------
hello!      10        
goodbye     20        

Now add two more set of values.

sqlite> insert into t1 values('welcome', 30);
sqlite> insert into t1 values('come in', 40);

Now the table have 4 set of values.

sqlite> select * from t1;
one         two       
----------  ----------
hello!      10        
goodbye     20        
welcome     30        
come in     40        

It also supports common commands that are used in other databases.

sqlite> select * from t1 order by one;
one         two       
----------  ----------
come in     40        
goodbye     20        
hello!      10        
welcome     30        

sqlite> select * from t1 order by one desc;
one         two       
----------  ----------
welcome     30        
hello!      10         
goodbye     20        
come in     40        

You can experiment on the other codes also. Later I will add more posts regarding the SQLite.



Saturday, July 16, 2011

Basic HTML tags

In this post I want to explain basic HTML tags that are used during the web page design. I think  it will be a good reference.

This is the HTML comments tag which is used for creating comments within your HTML code.
Eg : <!-- The level 4 heading goes here -->
<h4>How to comment out your code</h4>

The HTML a tag is used for creating a hyperlink to either another document, or somewhere within the current document.
Eg : <a href="" target="_blank">Killer Ab Workout</a>

The HTML acronym tag is used for indicating an acronym.
Eg : <acronym title="Computerized Axial Tomography">CAT</acronym>

The HTML applet tag is used for embedding a Java applet within an HTML document.
Eg : <applet code="wooferDog.class" width="500" height="650">
Java applet of a woofer dog.

The HTML b tag is used for specifying bold text.
Eg  : The HTML b tag specifies <b>bold</b> text.

The HTML basefont tag is used to specify a base font for the document to use.
Eg : <basefont face="cursive,serif" color="#ff9900" size="4" />

The HTML body tag is used for indicating the main content section of the HTML document. The body tag is placed between the </head>and the </html> tags.
Eg : <body style="background-color:orange">
Document content goes here

The HTML br tag is used for specifying a line break.
Eg : <p>This is before the line break<br /> and this after the line break.</p>

The HTML button tag is used for creating a button within forms.
Eg : <form>
<button name="quackitButton" value="Submit" type="button">Click Me</button>

The HTML caption tag is used for creating table captions.
Eg : <table border="1">
<caption>Table caption</caption>
<td>Left cell</td>
<td>Right cell</td>

The HTML center tag is used to center-align HTML elements.
Eg : <center>This text is centered</center>

The HTML del tag is used for markup of deleted text. Markup of deleted text can be useful in determining differences between multiple versions of the same document. Browsers will normally strike a line through deleted text and underline inserted text.
Eg : p>I am <del>very</del> <ins>extremely</ins> happy that you visited this page.</p>

The HTML font tag is used to specify the font to use.
Eg : <p><font face="cursive,serif" color="#ff9900" size="4">The HTML font tag is now deprecated. You should use <a href="/css/properties/css_font.cfm" target="_blank">CSS font</a> to set font properties instead.</font></p>

The HTML form tag is used for declaring a form.
Eg : <form action="/html/tags/html_form_tag_action.cfm" method="get">
First name:
<input type="text" name="first_name" value="" maxlength="100" />
<br />
Last name:
<input type="text" name="last_name" value="" maxlength="100" />
<input type="submit" value="Submit" />

The HTML frame tag is used to specify each frame within a frameset. For example, you can have a left frame for navigation and a right frame for the main content. For each frame, you specify the frame with the frame tag.
Eg : <frameset cols = "25%, *">
  <body>Your browser doesn't support frames.
  Therefore, this is the noframe version of the site.</body>
  <frame src ="/html/tags/frame_example_left.html" />
  <frame src ="/html/tags/frame_example_right.html" />

<h1> to <h6>
The HTML h1 tag is used for specifying level 1 headings. There are 6 levels of headings (h1 - h6) with h1 the most important and h6 the least important.
Eg : <h1>Level 1 heading using the HTML h1 tag</h1>

The HTML head tag is used for indicating the head section of the HTML document.
The head can contain other HTML tags that provide information about the document such as title, description, keywords etc.
Eg : <html>
<title>HTML head tag</title>
<body style="background-color:orange">
Document content goes here

The HTML html tag is the container that contains all other HTML elements (except for the !DOCTYPE tag which is located before the opening html tag).

The HTML i tag is used for specifying text in italics.
Eg: The HTML i tag specifies text in <i>italics</i>.

The HTML img tag is used for embedding images into an HTML document.
Eg: <img src="/pix/milford_sound/milford_sound_t.jpg" width="225" height="151" alt="Milford Sound in New Zealand">

The HTML input tag is used within a form to declare an input element - a control that allows the user to input data. Using the input tag, you can add controls such as text input, radio buttons, checkbox controls, submit buttons, and more.
Eg : <form action="/html/tags/html_form_tag_action.cfm" method="get">
First name:
<input type="text" name="first_name" value="" maxlength="100" />
<br />
Last name:
<input type="text" name="last_name" value="" maxlength="100" />
<input type="submit" value="Submit" />

The HTML label tag is used for adding a label to a form control. If you use the label tag, in some browsers, users can select a radio button or checkbox option by clicking on its label.
Eg : <form>
<input type="radio" name="fruit" id="banana" />
<label for="banana">Banana</label>
<br />
<input type="radio" name="fruit" id="None" />
<label for="none">None</label>

The HTML link tag is used for defining a link to an external document. It is placed in in the <head> section of the document. The HTML link tag is commonly used for linking to an external style sheet. Despite its name ("link"), the link tag is not used for creating a hyperlink to another HTML document. If you need to link to another HTML document, use the HTML <a> tag.
Eg: <link rel="stylesheet" type="text/css" href="/global.css" />

he HTML map tag is used for defining an image map. This element is used in conjunction with the HTML <area> tag and the HTML <img> tag to create the image map.
Eg : <map id ="muellermap" name="muellermap">
  <area shape ="rect" coords ="90,80,120,151"
  alt="Mueller Hut" />

The HTML menu tag is used for specifying a menu list. For other list types, see the ul tag (for an unordered list), the ol tag (for an ordered list), and the dir tag (for a directory list).
Eg : <menu>

The HTML noscript tag is used for providing alternative content for browsers that don't support javascript or other scripting languages. This element is used in conjunction with the <script> tag.
Eg : <script  language="javascript" type="text/javascript">
  document.write('Disable your JavaScript then reload this page');
  Your browser doesn't support JavaScript or you
  have disabled JavaScript. Therefore, here's
  alternative content...

The HTML object tag is used for embedding an object within an HTML document. Use this tag to embed multimedia in your web pages. You can also use the <param> tag to supply parameters to your embedded object.
Eg : <object title="Woofer dog." classid="wooferDog.class">
  <!-- If the applet didn't work, try the image file -->
  <object data="wooferDog.gif" type="image/gif">
  <!-- If the image didn't work, display the text -->
  Woofer dog.

The HTML option tag is used in conjunction with the select tag and is used for defining option items within the select list.
Eg : <select>
  <option value ="sydney">Sydney</option>
  <option value ="melbourne">Melbourne</option>
  <option value ="cromwell" selected>Cromwell</option>
  <option value ="queenstown">Queenstown</option>

The HTML p tag is used for defining a paragraph.
Eg : <p>This paragraph is defined using the HTML p tag</p>.

The HTML <q> tag is used for indicating short quotations (i.e. quotations that needs to display within a non-quoted paragraph).
Eg : And then she said <q>like... whatever!</q>

The HTML <s> tag is used for rendering a strike (or line) through the middle of the text.
Eg : The HTML s tag renders a <s>strike</s> (or <s>line</s>) through the middle of the text .

The HTML script tag is used for declaring a script (such as JavaScript) within your HTML document.
Eg: <script type="text/javascript">
  document.write('The HTML Script tag allows you to place a
                    script within your HTML documents');

The HTML strike tag is used for rendering a strike (or line) through the middle of the text.

The HTML strong tag is used for indicating stronger emphasis than the em tag. The strong tag surrounds the emphasised word/phrase.
Eg : I'm <strong>serious</strong>. I really can <strong>not</strong> emphasise this strongly enough!

The HTML <style> tag is used for declaring style sheets within the head of your HTML document. Each HTML document can contain multiple <style> tags. Each tag must be located between the <head> tags.
Eg : <head>
<style type="text/css">
  h1 { color:#000099 }

The HTML <table> tag is used for defining a table. The table tag contains other tags that define the structure of the table.
Eg : <table border = "1">
<td>Cell 1</td>
<td>Cell 2</td>

The HTML <td> tag is used for specifying a cell (or table data) within a table.

The HTML <th> tag is used for specifying a header cell (or table header) within a table.
Eg : <table border = "1">
<td>Specifies a table header</td>

The HTML <tr> tag is used for specifying a table row within a table. A table row contains one or more td and/or th tags which determine individual cells.

The HTML <thead> tag is used for adding a header to a table.
Eg : <table border = "1">
     <tr> <td colspan="2">Table Header (thead)</td></tr>

The HTML <title> tag is used for declaring the title of the HTML document.
Eg : <html>
<title>HTML title tag</title>
<body style="background-color:orange">
Document content goes here

The HTML <u> tag is used for rendering underlined text.