11:26 PM

Using NTFS drivers on Linux


In Arch Linux the users will not have any read permissions on NTFS drives by difault. It can be resolved using a simple package called ntfs-3g. Apart from Debian the the ntfs usage has to be manually done by editting the /etc/fstab file. Perform the following as root to add the NTFS capabilities.

pacman -S ntfs-3g

add the following line to /etc/fstab

# <file system>   <dir>  <type>    <options>             <dump>  <pass> 
/dev/<NTFS-part>  /mnt/windows  ntfs-3g   defaults    0       0 
 
  
The partition will be mounted at /mnt/windows.If you do not want to mount the partition by default use none instead.
If you want to people in users group access the drive then use

gid=users,umask=0022 
 
instead of default under options.
Reboot the system and enjoy!!!

8:05 AM

Shell script to convert video to mp3

The following shell script takes a video file as input and converts it into mp3 file at users home directory.Ensure that the file name is specified in double quotes if it contains any whitspaces.

====================================================


#!/bin/sh


folder="/home/$USER/Music"
name=""
if [ -z "$1" ]
then
    echo "No file name specified "
    echo "Please provide the absolute path of the file Ensure that the file name is enclosed in single quotes"
    exit 1
fi

echo "Output file name?"
read name
ffmpeg -i "$1" -acodec libmp3lame -ab 160k -ar 44100 -ac 2 "$folder/$name" 
if (($? != 0 ))
then
    pacman -Q lame ffmpeg > /dev/null
    if (($? !=0))
    then
        echo "Please ensure that lame and ffmpeg are installed on your system"
        exit 2
    else
        echo "No such file exists"
        exit 3
    fi
fi
echo "File successfully converted"
exit 0

===================================================

12:55 PM

Hangman game through Python



Simple python code to implement the hangman game.The code assumes that you have a file named 'words.txt' which contains n number of words.The program randomly selects one word from the file. The user is given 8 chances to guess the word.Each word guessed by the user is added to the lettersGuessed list.Procedure isWordGuessed() is used to determine whether the guessed letter is in the secretWord.If not the number of guesses remaining is reduced by one.Procedure getGuessedWord is used to print present correctly guessed words and thier locations...

===================================================import

import random
import string

WORDLIST_FILENAME = "words.txt"

def loadWords():
        print "Loading word list from file..."
    inFile = open(WORDLIST_FILENAME, 'r', 0)
    line = inFile.readline()
        wordlist = string.split(line)
        print "  ", len(wordlist), "words loaded."
       return wordlist

def chooseWord(wordlist):
       return random.choice(wordlist)

def isWordGuessed(secretWord, lettersGuessed):
    for letter in secretWord:
        if letter in lettersGuessed:
            continue
        else:
            return False
    return True

def getGuessedWord(secretWord, lettersGuessed):
    result = ""
    for letter in secretWord:
        if letter in lettersGuessed:
            result += letter
        else:
            result +=  '_ '
    return result
   


def getAvailableLetters(lettersGuessed):
    result = ""
    for letter in string.ascii_lowercase:
        if letter not in lettersGuessed:
            result += letter
    return result
   

def hangman(secretWord):
    lettersGuessed = []
    mistakesMade = 8
    guess=""
    print "Welcome to the game, Hangman!"
    print "I am thinking of a word that is" ,len(secretWord)," letters long."
    while mistakesMade:
        print "--------------------------------------------------------"
        print "You have",mistakesMade," guesses left."
        print "Available letters:",getAvailableLetters(lettersGuessed)
        print "Please guess a letter:"
        guess=raw_input()
        guess=guess.lower()
        if guess in lettersGuessed:
            print "You've already guessed that letter" ,getGuessedWord(secretWord,lettersGuessed)
            continue
        else:
            lettersGuessed.append(guess)
        if isWordGuessed(secretWord,[guess]):
            print "Good guess:",getGuessedWord(secretWord,lettersGuessed)
        else:
            print "Oops! That letter is not in my word:",getGuessedWord(secretWord,lettersGuessed)
            mistakesMade -= 1   
        if  '_' not in getGuessedWord(secretWord,lettersGuessed):
            print "Congratulations, you won!"
    print  "Sorry, you ran out of guesses. The word was ",secretWord,"."

def main():
    wordlist = loadWords()
    secretWord = chooseWord(wordlist)
    hangman(secretWord)

if __name__ == '__main__':
    main()

==================================================

12:45 PM

Python program to find solution of a polynomial using Newtons method



The Newtons method is used to find the root of an n digree polynomial by successive guesses.The simple algorithm to find the root using Newtons method is.
  1. Take initial guess as x_0
  2. Now evaluate the value of the polynomial at x_0
  3. Check if the value is near to zero within a small epsilon (say .01). If yes we call x_0 as the root 
  4. calculate new value of x_0 as x_0=x_0-[f(x)/f'(x)] 
  5. Check if this new value is close to root and so on until you find a root


Here is a simple python program to find the root of a polynomial.The polynomial is represented as a list with the index of each number as the power of x.Three procedures are used to find the value of the polynomial,its derivative and to compute the root of the polynomial

The program returns a list with root and number of itterations performed to find the root

=================================================== 



def evaluate(poly, x):
    value=0.0
    for index in range(len(poly)):
        value  = value+(x**index)*poly[index]
    return value

def Deriv(poly):
    for index in range(len(poly)):
            poly[index]*=index
    poly.pop(0)
    if len(poly) == 0:
        poly.insert(0,0.0)
    return poly

def Root(poly, x_0, epsilon):
    value = (evaluate(poly,x_0))
    poly1=[]
    for num  in poly:
            poly1.append(num)   
    Deriv(poly1)
    count = 0
    while abs(value)  >= epsilon:
        derivalue=(evaluate(poly1,x_0))
        if derivalue == 0:
            x_0 = 0
            break
        x_0 = x_0 - (value/derivalue)
        value=(evaluate(poly,x_0))
        count += 1
    return [x_0,count]
   
  def main():
    poly = [-13.39, 0.0, 17.5, 3.0, 1.0]   
    #poly=[1]
    x_0 = 0.1
    epsilon = .0001
    print computeRoot(poly, x_0, epsilon)   
           
if __name__ == '__main__':
    main()


===================================================
===fa 
  

1:55 AM

Migratting to Arch Linux..!!




After experimenting on Fedora for months today i ported myself fully to Arch.Arch Linux is a light weight Linux distribution.The Arch is based on simplicity, simple as stick!! The Arch Linux provides the power and combustibility than any other Linux system out there.

The Arch Linux involves installation from scratches and  one can customize the OS in any way one needs to. On a fresh installation of the operating system you will only have a basic Linux system with no GUI,no sound,etc but all basic modules to run an OS. You will be greeted only by a tty where you can login as root and start building your custom OS!!!

The Arch Linux emphasis on simplicity and wants to make your system as simple as possible.By giving such a low functional operating system, the Arch wants the users to add only those packages one needs to. This makes your system light weight and much more flexible than any other Linux distribution. That is in Fedora installing the OS will give you many different packages which you may not even know what it does.There no such case in Arch.If you think you want it then you can install it.

The Arch uses a power full package manager called pacman.The pacman is a light weight package manager in which you will have access to the latest packages compared to other package managers like apt or rpm.

Final word: The Arch Linus is a definite try for intermediate and expert Linux users. Even though the installation in little bit lengthy you will surely benefit from it, you will get a clear picture of what each are meant for and so on.....Beginners are not recommended to use Arch Linux as you should have basic understanding of Linux file system and which files are meant for what and so on....

The arch wiki page is the best guide one can find.The beginners guide contains all details you may want .

Arch Linux beginners guide

Be sure to read each and every line of the wiki if you miss one it will surely screw your system ;) . Last day I accidentally missed a warning which crashed my system...

So give it a try .
Keep exploring and live curious !!!

12:37 AM

Installing mp3 puling gstreamer and vlc on fedora

The fedora repository does not provide many software's which are provided in rpmfusion repo. The rpm fusion contains many popular packages like vlc and gstreamer (mp3 plugin for rhythmbox etc)
The following shell script configures rpmfusion on fedora and installs your favorite softwares........


#!/bin/sh

#program on fedora to install gstreamer vlc
#these packages are in rpm fusion repostiory

no_of_argmnt=1;

#checks wether the user is root or not
if (( $EUID != 0 ))
then
    echo "the script must be runed as root"
    echo "try again as"
    echo "su -c \`sh $0.sh \"package\"\`"
    echo "package can be gstreamer or vlc "
    exit 1
fi

#checks for the parameters
if (( $no_of_argmnt != $#))
then
    echo "parametes missing"
    echo "scrpit usage::"
    echo "su -c \`sh $#.sh \"package\"\`"
    echo "package can ve gstreamer or vlc "
    exit 1
fi

echo "Configuring Rpm fusion...."
echo "Getting rpm fusion package from http://download1.rpmfusion.org"
yum localinstall --nogpgcheck http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-stable.noarch.rpm http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-stable.noarch.rpm

if [ $1 == "vlc" ]
then
    echo "Installing vlc..."
    yum install vlc
elif [ $1 == "gstreamer" ]
then
    echo "Installing gstreamer..."
    yum install gstreamer-{ffmpeg,plugins-{good,ugly,bad{,-free,-nonfree}}}
else
    echo "Unknown package"
fi

echo "Finishing installation.."
exit 0
    

7:37 AM

Script to install flash plugin



A simple bash script to install flash for mozilla and/or chromium browser on any linux system.

sript usage:

To install for fedora use
    sh installflash.sh mozilla

To install for chromuin use
    sh installflash.sh chromium

For both use
    sh installflash.sh mozilla chromium

IMPORTANT :: the script must be excecuted as root

####################################################

#!/bin/sh


if [ -z $1 ]
    then
    echo "Arguements missings"
    echo
    echo "To install for fedora use"
    echo "    sh installflash.sh mozilla"
    echo
    echo "To install for chromuin use"
    echo "    sh installflash.sh chromium"
    echo
    echo "For both use "
    echo "    sh installflash.sh mozilla chromium"
    echo   
    exit 1
fi

if (( $EUID != 0 ))
     then
     echo "This scritp must be run as root"
     exit 1
fi
echo "Downloading flash files from adobe"
mkdir temp
cd temp

wget http://fpdownload.macromedia.com/get/flashplayer/pdc/11.2.202.236/install_flash_player_11_linux.x86_64.tar.gz
tar -xvf install_flash_player_11_linux.x86_64.tar.gz

if [ -n $2 ]
    then
    echo "installing flash for mozilla"
    mv libflashplayer.so /usr/lib64/mozilla/plugins/ 2> /dev/null
    if (( $? != 0 ))
    then
        mkdir usr/lib64/mozilla/plugins/
        mv libflashplayer.so /usr/lib64/mozilla/plugins/       
    fi
    echo "installing flash for chromium"
    mv libflashplayer.so /usr/lib64/chromium-browser/plugins/ 2> /dev/null
    if (( $? != 0 ))
    then
        mkdir usr/lib64/mozilla/plugins/
        mv libflashplayer.so /usr/lib64/chromium-browser/plugins/       
    fi
   
fi
if [ $1 = "mozilla" ]
    then
    echo "installing flash for mozilla"
    mv libflashplayer.so /usr/lib64/mozilla/plugins/ 2> /dev/null
    if (( $? != 0 ))
    then
        mkdir usr/lib64/mozilla/plugins/
        mv libflashplayer.so /usr/lib64/mozilla/plugins/       
    fi
fi

if [ $1 = "chromium" ]
    then
    echo "installing flash for chromium"
    mv libflashplayer.so /usr/lib64/chromium-browser/plugins/ 2> /dev/null
    if (( $? != 0 ))
    then
        mkdir usr/lib64/mozilla/plugins/
        mv libflashplayer.so /usr/lib64/chromium-browser/plugins/       
    fi
fi

rm -rf temp/
rmdir temp

###################################################