Convert rpm to deb

#Install alien
sudo apt-get install alien

# Convert rpm to deb
alien my_package-1.1-1.rpm

# Install deb package
dpkg -i my_package-1.1-1.deb

# Convert deb to rpm
alien -r deb_package-1.1-1.deb


Clean pyc file from python project

How do I remove all .pyc files from a project?

find . -name '*.pyc' -delete

You can use Flask-Script:
# manage.py
from flask.ext.script import Manager
from myapp import app

manager = Manager(app)

def clearpyc():
    os.system('find . -name \'*.pyc\' -delete')

if __name__ == "__main__":


VIM Configuration for Python Development.

# Install CTags
sudo apt-get install exuberant-ctags

# Clone repo:
git clone https://github.com/rmk135/vimrc.git ~/vimrc

# Copy .vimrc file to home dir
cp ~/vimrc/.vimrc ~/.vimrc

# Copy color schemes to .vim home dir
mkdir ~/.vim && cp -r ~/vimrc/.vim ~/

# Setup Vundle (Vim Plugin Manager)
git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/Vundle.vim

# Run VIM (ignore errors)

# Install VIM Plugins (inside VIM)

# Rehash terminal
hash -r


Python DB wrappers

  • MySQL
  • SQLite
  • Mongo - soon ...

Before proceeding, you make sure you have MySQLdb installed on your machine.
To install MySQLdb module:

apt-get install build-essential python-dev libmysqlclient-dev
pip install mysql-python

Python Mock

Mock is a library for testing in Python. It allows you to replace parts of your system under test with mock objects and make assertions about how they have been used.

import os
from mock import patch

def file_extension(file_path):
    if os.path.isfile(file_path):
        return os.path.splitext(file_path)[1]

def is_date(val):
    datetimeobject = datetime.datetime.strptime(val, '%Y%m%d')
    return isinstance(datetimeobject, datetime.date)
    return False

if __name__ == '__main__':
    with patch('is_date'as mock_is_date:
        mock_is_date.return_value = True

 with patch('os.path.isfile'as mock_isfile:
        mock_isfile.return_value = True

Python work with files and directories

Very often there is a need to work with files in Python.
shutil.copy() # copy the file
shutil.copytree() # copy the directory
shutil.move() # moves files
shutil.rmtree() # remove directory

tmpfile.mkstemp() # temporary file
filecmp.cmp() # compare file
filecmp.cmpfiles() # compare directory
os.getcwd() # get working directory
os.chdir() # change working directory
os.access() # access check
os.listdir() # list of directories and files
os.stat() # file information
os.mkdir() # make directory
os.makedirs() # create a directory and intermediate directories
os.rmdir() # remove empty directories
os.removedirs() # remove empty directories
os.remove() # remove
os.walk() # execute all the directories tree
glob.glob() # get a list of files and folders on a mask

os.path.abspath() # absolute path
os.path.isabs() # check that the path absalyutno
os.path.realpath() # the canonical path to the OS
os.path.dirname() # get out of the way only to directory
os.path.basename () # get out of the way the file name
os.path.join() # join path directory and file
os.path.isfile() # check if this object is file
os.path.isdir() # check if this object is a directory
os.path.getsize() # get size file or directory
os.path.exists() # check if this object exists
os.path.getctime() # get time when file was created
os.path.getmtime() # get time when file was changed


Back Up MySQL Databases From The Command Line

Creating A Backup

mysqldump database_name > database_name.sql

mysqldump --databases database_1 database_2 > two_databases.sql

mysqldump --all-databases > all_databases.sql

Restoring a Backup

mysql database_name < database_name.sql

mysql --one-database database_name < all_databases.sql

Rsync + SSH + Cron

Ssh-keygen generates keys:
ssh-copy-id -i ~/.ssh/id_rsa.pub

Creae sh file:
rsync -avuz /var/www/example.com/ root@

a - archive mode
v - increase verbose
u - skip files that are newer on the receiver
z - compress file data during the transfer

Edit crontab:
run crontab -e and add:
*/5 * * * * /home/ramesh/backup.sh