Friday, May 29, 2015

CentOS 7 Installation

CentOS 7 by default is installled as minimal server. To change this, during installation, click "SOFTWARE SELECTION" and choose the "Base Environment" and "Add-ons". 
For "Base Environment" there are several types to choose from like Gnome, KDE, Workstation, Web-Server etc.

Wednesday, May 27, 2015

Ubunty 15.04 Unity Freeze

Ubuntu 15.04 Unity freezes frequently. The solution to this problem follows:

  • Press Ctrl+Alt+F1 and get the terminal screen. Log in with password.
  • In the terminal type killall -v -9 compiz
  • Close the terminal and launch unity by pressing Ctrl+Alt+F7
Also avoid maximizing the window size to full screen. In the System Settings-->Appearance-->Behavior , For 'Shows the menus for a window' choose 'In the window's title bar'.

Tuesday, May 26, 2015

Decorators in Python

In Python Decorators are functions of functions. It is a wrapper function that wraps a regular function to modify its results.  
For example, say you have a function to capitalize the first letter of names. Now you want to add another function on top of this to include the title (Mr/Ms) depending upon the gender. This can be achieved by defining a decorator function to add the title. 

Decorator Function to add the title (Mr/Ms) based on gender:
def Title(func):
  def new(*args, **kwds):
    if kwds['gender'] == 'male': return ("Mr "+func(*args, **kwds))
    elif kwds['gender'] == 'female': return ("Ms "+func(*args, **kwds))
    else: return func(*args, **kwds)
  return new

Regular function to capitalize the first letter with decorator:
def Capitalize(name,gender=''):
  return name.title()

Now call the regular function as below:
Capitalize('john travolta',gender='male')
result >>> 'Mr John Travolta'

Capitalize('catherine zeta jones',gender='female')
result >>> 'Ms Catherine Zeta Jones'