Disable the directory listing in apace

April 19th, 2012 No comments

Add the following line to your .htaccess file (create the file if it is not there in your site root)

Options -Indexes

Categories: LAMP, Linux / Ubuntu

How to flush DNS in Ubuntu

April 14th, 2012 No comments

$ sudo aptitude install nscd

$ sudo /etc/init.d/nscd restart

Categories: Linux / Ubuntu

parse a csv to xml using python

March 8th, 2012 No comments

Here is the working code which reads data from a CSV and write to XML format:

Assumptions:
Sample CSV format:
id,name,office,location

Here is the python code:

#! /usr/bin/env python

import csv
from xml.dom.minidom import Document

data = csv.DictReader (open("input_file_name.csv",'rb'))

#Create the XML doc
doc = Document()

#create the base element
docbase = doc.createElement("docbase")
doc.appendChild(docbase)

for row in data:
#create the company element
company = doc.createElement('company')
company.setAttribute('name', row['name'])
docbase.appendChild(company)

office = doc.createElement('office')
office.setAttribute('name', row['location'])
company.appendChild(office)

department = doc.createElement("department")
department.setAttribute("id", row['id'])
department.setAttribute("name", row['location'])
office.appendChild(department)

f = open('output_file_name.xml', 'w')
doc.writexml(f, addindent=" ", newl="\n")
f.close()

Categories: Python

Common commands in Git

January 27th, 2012 No comments

In my earlier post How to setup first GIT repositoryI described how to setup first GIT repository. Here is the list of common GIT commands which I have used in my programming life so far.

How to create a new branch from master:

$ git checkout

e.g.,
$ git checkout feature-test

How to add a new file in current branch

$ git add file_name

to add multiple files
$ git add file1 file2

to add all new files in the current directory and subdirestories simply use
$ git add

How to commit the files

$ git commit file_name1 file_name2 -m “commit message”

Once you commit the files it will not be added in the server repository until you push it.

$ git push

this will push all the commits and updates the indexes

If you wish to push a branch into the repository

$ git push

To push all the branches
$ git push –all

How to merge the branches

Being a developer sometimes I have to work on many tickets in parallel therefore I create separate branches for the assigned tickets and merge them into the master once I complete them. It is very common that from the time I started my branch some other developer commits their changes in master which results in code conflicts. To handle code conflicts I first “rebase” my ticket’s branch, resolve conflicts (if any), commit and push the changes in the ticket branch and then raise the pull request.

Lets walk with a complete example. Say I am working on a ticket new_field_#123.

I will first start a new branch from master

$ git checkout new_field_#123

Now add new files (f1) and modify and existing file (f2) in this branch

I need to explicitly add the new file using “git add” and the modifications in f2 need to be committed.
$ git add f1

commit the changes

$ git commit f1 f2 -m “f1 added and file f2 is modified”

Now I have to rebase my branch from master. It is a good practice to pull the changes from master on daily basis so that your working tree is not outdated.
To pull the changes
$ git pull origin master

So, my master branch is updated with the origin. Now I have to update my ticket branch. First checkout to the ticket branch
$ git checkout new_field_#123

$ git rebase origin/master

If there are any conflicts then fix them and commit your changes.

Categories: Git, Version Control