Working with Git

octocat_darkwood.jpg

Git is a free and open source distributed open source system designed to handle everything from small to very large projects with speed and efficiency. All you need is a git hub account.

Here we go…

The very first step is to install git on your machine.

Installation

Run the following commands in your terminal:

  • sudo apt-get update
  • sudo apt-get install git

How to push a file to Github?

Pushing a file into GitHub is like backing up i.e, the chance of losing a file is zero!

Step 1: Create a repository in your GitHub account

Step 2: Specify the git configuration setting using git config command.

$git config –global user.name “username”

$git config –global user.email “email id”

Step 3: Generate ssh key

ssh-keygen

Enter passphrase (empty for no passphrase): [press enter]
Enter same passphrase again: [press enter]

Step 4: Copy the ssh key and add it in the github repository.

Step 5: Intialize empty git repository

$ git init

Step 6: Enter every file to added

$ git add .

Step 7:

$ git commit -m ‘first commit’

$ git remote add origin git@github.com:Username/Repository.git

Step 8:

$ git push -u origin master

// ‘git commit’ records changes made to the repository while ‘git push’ updates the remote reference along with the changes.

github-octocat.png

Advertisements

Excel access using python

Hai Everyone,

Excel access using python,this is a very interesting assignment which was given by one of my seniors. It is very simple.

The assignment was all about

  • To open a excel sheet and give two numbers in two different cells.
  • The next task is to extract the sum of these two numbers using python code.

How-To-Do?

There are two ways to crack

  1. openpyxl
  2. xlrd

I followed the second method , using xlrd.

xlrd

Installation

The very first step is to install xlrd(a python package).

Run the following commands on terminal to install xlrd:

sudo apt-get update
sudo apt-get install python-xlrd

Excel File

Open an excel file and add two numbers in two different cells. Save the file in “.xls” format as shown in the figure.

Screenshot from 2016-08-03 19:23:48

Code

The following code is the skeleton code which I got after googling :).

import xlrd
 
#----------------------------------------------------------------------
def open_file(path):
    """
    Open and read an Excel file
    """
    book = xlrd.open_workbook(path)
 
    # print number of sheets
    print book.nsheets
 
    # print sheet names
    print book.sheet_names()
 
    # get the first worksheet
    first_sheet = book.sheet_by_index(0)
 
    # read a row
    print first_sheet.row_values(0)
 
    # read a cell
    cell = first_sheet.cell(0,0)
    print cell
    print cell.value
 
    # read a row slice
    print first_sheet.row_slice(rowx=0,
                                start_colx=0,
                                end_colx=2)
 
#----------------------------------------------------------------------
if __name__ == "__main__":
    path = "test.xls"
    open_file(path)

This is my code. Using the above code I made some variations.

import xlrd
def open_file(path):
book = xlrd.open_workbook(path)
first_sheet = book.sheet_by_index(0)
cell1 = first_sheet.cell(0,0)
cell2 = first_sheet.cell(0,1)
sum = cell1.value+cell2.value
print cell1.value
print cell2.value
print sum
if __name__ == “__main__”:
path = “example.xls”
open_file(path)

Precautions

  • Don’t ever forget to give the proper indentations(4 spaces).
  • Make sure that you are giving the sheet number and cell number properly((sheet number,cell number)).
  • First assign the path of the file to a variable and then use that variable in the place of path.

VERSION CONTROL SYSTEM

What is version control system?

Essentially a version control system (or a revision control system) is software that has the ability to manage and track changes that occur to any document that is in a given project.

Basic concept

A version control system is mostly based around one concept, tracking changes that happen within directories or files. Depending on the version control system, this could vary from knowing a file changed to knowing specific characters or bytes in a file have changed.

In most cases, you specify a directory or set of files that should have their changes tracked by version control. This can happen by checking out (or cloning) a repository from a host, or by telling the software which of your files you wish to have under version control.

The set of files or directories that are under version control are more commonly called a repository.

As you make changes, it will track each change behind the scenes. The process will be transparent to you until you are ready to commit those changes.

 USES

  • Version control enables multiple people to simultaneously work on a single project. Each person edits his or her own copy of the files and chooses when to share those changes with the rest of the team. Thus, temporary or partial edits by one person do not interfere with another person’s work.
    Version control also enables one person you to use multiple computers to work on a project, so it is valuable even if you are working by yourself.
  • Version control integrates work done simultaneously by different team members. In most cases, edits to different files or even the same file can be combined without losing any work. In rare cases, when two people make do editing to the same line of a file, then the version control system requests human assistance in deciding what to do.
  • Version control gives access to historical versions of your project. This is insurance against computer crashes or data lossage. If you make a mistake, you can roll back to a previous version. You can reproduce and understand a bug report on a past version of your software. You can also undo specific edits without losing all the work that was done in the meanwhile. For any part of a file, you can determine when, why, and by whom it was ever edited.

Centralized and distributed version control system

In centralized version control, each user gets his or her own working copy, but there is just one central repository. As soon as you commit, it is possible for your co-workers to update and to see your changes. For others to see your changes, 2 things must happen:

  • You commit
  • They update

In distributed version control, each user gets his or her own repository and working copy. After you commit, others have no access to your changes until you push your changes to the central repository. When you update, you do not get others’ changes unless you have first pulled those changes into your repository. For others to see your changes, 4 things must happen:

  • You commit
  • You push
  • They pull
  • They update

Notice that the commit and update commands only move changes between the working copy and the local repository, without affecting any other repository. By contrast, the push and pull commands move changes between the local repository and the central repository, without affecting your working copy.

It is sometimes convenient to perform both pull and update, to get all the latest changes from the central repository into your working copy. The hg fetch and git pull commands do both pull and update. (In other words, git pull does not follow the description above, and git push and git pull commands are not symmetric. git push is as above and only affects repositories, but git pull is like hg fetch: it affects both repositories and the working copy, performs merges, etc.)

 CONFLICTS

A version control system lets multiple users simultaneously edit their own copies of a project. Usually, the version control system is able to merge simultaneous changes by two different users: for each line, the final version is the original version if neither user edited it, or is the edited version if one of the users edited it. A conflict occurs when two different users make simultaneous, different changes to the same line of a file. In this case, the version control system cannot automatically decide which of the two edits to use (or a combination of them, or neither!). Manual intervention is required to resolve the conflict.

“Simultaneous” changes do not necessarily happen at the exact same moment of time. Change 1 and Change 2 are considered simultaneous if:

  • User A makes Change 1 before User A does an update that brings Change 2 into User A’s working copy, and
  • User B makes Change 2 before User B does an update that brings Change 1 into User B’s working copy.

In a distributed version control system, there is an explicit operation, called merge, that combines simultaneous edits by two different users. Sometimes merge completes automatically, but if there is a conflict, merge requests help from the user by running a merge tool. In centralized version control, merging happens implicitly every time you do update.

It is better to avoid a conflict than to resolve it later. The best practices below give ways to avoid conflicts, such as that teammates should frequently share their changes with one another.