Custom Search

Tuesday, November 30, 2010

howto disable beep sound in ubuntu 10

Open up a Terminal and type:

sudo alsamixer

Now using your left/right arrow keys navigate over to PC Beep and press M on your keyboard, you'll see MM appear under the volume bar, this basically means it's been muted now press Esc to exit.

Tuesday, November 23, 2010

howto install vmware workstation in ubuntu fedora redhat centos suse linux

howto install vmware workstation in ubuntu fedora redhat centos suse linux

Download VMware Workstation
----------------
-----------------------------------
http://downloads.vmware.com/d/info/desktop_downloads/vmware_workstation/7_0

http://www.vmware.com/downloads/download.do?downloadGroup=WKST-713-LX

download "VMware-Workstation-7.1.3-324285.x86_64.bundle"

Install VMware-Workstation-7.1.3-324285.x86_64.bundle
--------------------------------------------------------------------------------------------
Open Terminal
#/bin/sh VMware-Workstation-7.1.3-324285.x86_64.bundle

Python synchronized method example

Python synchronized method example

import threading
class A:
    def __init__(def):
            self._lock = threading.RLock()
        # or threading.Lock(), if no reentrancy needed.

    def some_method(self):
        self._lock.acquire()
        try:
            "do your business"
        finally:
            self._lock.release()

Python Object Level Lock and Synchronized Method

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

* Object level lock.
* Python Synchronized method.
* Here variable 'lock' is an instance variable.
* So each object has its own instance variable 'lock'.
* Suppose object 'a' acquire a lock on function 'first_function', this time
object 'b' can call and acquire lock on function 'first_method', without out waiting for
object 'a' to release the lock.


import threading
class A:

def __init__(self):
#For private variable use single underscore before variable name.
#self._lock = threading.RLock()
self.lock = threading.RLock()

def first_function(self, name):
print "------first_function, Waiting for acquire lock------", name
self.lock.acquire()
try:
print "------first_function, lock acquired------", name
print "------first_function, sleeping----start----", name
import time
time.sleep(5)
print "------first_function, sleeping----end------", name
finally:
self.lock.release()
print "------ first_function, lock released-------", name

def second_function(self, name):
print "------second_function, Waiting for acquire lock------", name
self.lock.acquire()
try:
print "------second_function, lock acquired------", name
print "------second_function, sleeping----start----", name
import time
time.sleep(5)
print "------second_function, sleeping----end------", name
finally:
self.lock.release()
print "------second_function, lock released-------", name

a = A()

thr1 = threading.Thread(name='a.first_function',target=a.first_function, args=('T1',))
thr2 = threading.Thread(name='a.first_function', target=a.first_function, args=('T2',))

print "----------calling------thr1.start()------"
thr1.start()
print "----------calling------thr2.start()------"
thr2.start()

----------------------------------------------------CASE-1

2 threads 'thr1' and 'thr2' trying to call a method 'first_function' of class 'A'
using same object 'a'.

a = A()
thr1 = threading.Thread(name='a.first_function',target=a.first_function, args=('T1',))
thr2 = threading.Thread(name='a.first_function', target=a.first_function, args=('T2',))

OUTPUT
======
----------calling------thr1.start()------
----------calling------thr2.start()------
------first_function, Waiting for acquire lock------ T1
------first_function, lock acquired------ T1
------first_function, sleeping----start---- T1
------first_function, Waiting for acquire lock------ T2
------first_function, sleeping----end------ T1
------ first_function, lock released------- T1
------first_function, lock acquired------ T2
------first_function, sleeping----start---- T2
------first_function, sleeping----end------ T2
------ first_function, lock released------- T2


----------------------------------------------------CASE-2

2 threads 'thr1' and 'thr2' trying to call two seperate methods 'first_function'
and 'second_function' of class 'A' using same object 'a'.

a = A()

thr1 = threading.Thread(name='a.first_function',target=a.first_function, args=('T1',))
thr2 = threading.Thread(name='a.second_function', target=a.second_function, args=('T2',))

OUTPUT
======
----------calling------thr1.start()------
----------calling------thr2.start()------
------first_function, Waiting for acquire lock------ T1
------first_function, lock acquired------ T1
------first_function, sleeping----start---- T1
------second_function, Waiting for acquire lock------ T2
------first_function, sleeping----end------ T1
------ first_function, lock released------- T1
------second_function, lock acquired------ T2
------second_function, sleeping----start---- T2
------second_function, sleeping----end------ T2
------second_function, lock released------- T2


----------------------------------------------------CASE-3

2 threads 'thr1' and 'thr2' trying to call a method 'first_function' of class 'A'
using different objects 'a' and 'b'.

a = A()
b = A()

thr1 = threading.Thread(name='a.first_function',target=a.first_function, args=('T1',))
thr2 = threading.Thread(name='b.first_function', target=b.first_function, args=('T2',))

OUTPUT
======
----------calling------thr1.start()------
------first_function, Waiting for acquire lock------ T1
------first_function, lock acquired------ T1
----------calling------thr2.start()------
------first_function, sleeping----start---- T1
------first_function, Waiting for acquire lock------ T2

------first_function, lock acquired------ T2
------first_function, sleeping----start---- T2
------first_function, sleeping----end------ T1
------ first_function, lock released------- T1
------first_function, sleeping----end------ T2
------ first_function, lock released------- T2


----------------------------------------------------CASE-4

2 threads 'thr1' and 'thr2' trying to call two seperate methods 'first_function' and
'second_function' of class 'A' using two seperate objects 'a' and 'b'.

a = A()
b = A()

thr1 = threading.Thread(name='a.first_function',target=a.first_function, args=('T1',))
thr2 = threading.Thread(name='b.second_function', target=b.second_function, args=('T2',))

OUTPUT
======
----------calling------thr1.start()------
------first_function, Waiting for acquire lock------ T1
----------calling------thr2.start()------
------first_function, lock acquired------ T1
------first_function, sleeping----start---- T1
------second_function, Waiting for acquire lock------ T2
------second_function, lock acquired------ T2
------second_function, sleeping----start---- T2
------first_function, sleeping----end------ T1
------ first_function, lock released------- T1
------second_function, sleeping----end------ T2
------second_function, lock released------- T2



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

Python Class level Lock

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

* Class level lock.
* Here variable 'lock' is a class variable.
* So all objects using common lock.
* Here at a time only one object can acquire lock.
* Suppose object 'a' call the method 'my_function' and acquire the lock,
this time object 'b' or other objects can method 'my_function' but can not
acquire the lock until object 'a' release the lock, so object 'b' waiting in method
'my_function' for
acquire the lock.


import threading
class A:
lock = threading.RLock()

def my_function(self, name):
print "------Waiting for acquire lock------", name
self.lock.acquire()
try:
print "------lock acquired------", name
print "------sleeping----start----", name
import time
time.sleep(5)
print "------sleeping----end------", name
finally:
self.lock.release()
print "------lock released-------", name

a = A()
b = A()

thr1 = threading.Thread(name='a.my_function',target=a.my_function, args=('T1',))
thr2 = threading.Thread(name='b.my_function', target=b.my_function, args=('T2',))

print "----------calling------thr1.start()------"
thr1.start()
print "----------calling------thr2.start()------"
thr2.start()

----------------------------------------------------CASE-1

2 threads 'thr1' and 'thr2' trying to call a method 'my_function' of class 'A'
using two seperate objects 'a' and 'b'.

a = A()
b = A()

thr1 = threading.Thread(name='a.my_function',target=a.my_function, args=('T1',))
thr2 = threading.Thread(name='b.my_function', target=b.my_function, args=('T2',))


OUTPUT
======
----------calling------thr1.start()------
----------calling------thr2.start()------
------Waiting for acquire lock------ T1
------lock acquired------ T1
------sleeping----start---- T1
------Waiting for acquire lock------ T2
------sleeping----end------ T1
------lock released------- T1
------lock acquired------ T2
------sleeping----start---- T2
------sleeping----end------ T2
------lock released------- T2

----------------------------------------------------CASE-2

a = A()

thr1 = threading.Thread(name='a.my_function',target=a.my_function, args=('T1',))
thr2 = threading.Thread(name='a.my_function', target=a.my_function, args=('T2',))

OUTPUT
======
----------calling------thr1.start()------
----------calling------thr2.start()------
------Waiting for acquire lock------ T1
------lock acquired------ T1
------sleeping----start---- T1
------Waiting for acquire lock------ T2
------sleeping----end------ T1
------lock released------- T1
------lock acquired------ T2
------sleeping----start---- T2
------sleeping----end------ T2
------lock released------- T2


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

Sunday, November 21, 2010

10 Things To Do After Installing Ubuntu

10 Things To Do After Installing Ubuntu

Ubuntu is a great operating system, especially the version 10.10. It comes with most needed software pre-installed. However, owing to licensing issues some packages are not installed by default. I recommend a few tweaks to polish your fresh installation. It takes lesser time and effort to prepare Ubuntu for a ride than it takes Windows 7 or Apple Mac.
1. Set up the repositories. Administration>Synaptic Package Manager>Settings>Repositories
a. Under Ubuntu Software enable all, except for Source Code
b. Other Software, select all. Here you can add needed [trusted] PPAs to install many more software.
c. Updates. Do not enable pre-release or unsupported updates, unless you are a dare-devil.
d. Reload.

Avoid using the search Box, instead use the Search button and select "Name" in the Look In. Now search for "restricted". Select Ubuntu-restricted-extras and addons. Mark Apply. This step will install all needed codecs and drivers which were otherwise restricted due to licensing issues.

2. Ubuntu comes with Brasero CD burner, but you can install a much more advanced K3B, which will enable you to get many more options of burning DVDs and CDs.

3. Install GIMP. Even if Ubuntu comes with Shotwell photo manager, GIMP is a powerhouse and can fight with Photoshop, shoulder to shoulder. Install GIMP through Synaptic or Ubuntu Software Center.

4. If you are a big fan of desktop effect and 3D desktop, you may want to enable the additional desktop effects. Please install "Compiz configuration settings manager". Search for compiz in Synaptic and install it. Once installed, you can find it under System>Preferences. Enable the effects you want.

5. You might have noticed some vertical lines in videos playing under Ubuntu. Just go to "CompizConfig Settings Manager" and under 'General Option' go to Display Settings and tick "Sync To VBlank'.
Read More.....

how Create Internet Radio Station With Ubuntu

how Create Internet Radio Station With Ubuntu
We all have music libraries stored/scattered across our laptops, desktops and handhelds. The question is, how do we unify this? Is there any way we can setup our own streaming solution to access this huge pile of data anytime, anywhere from any device? Yes you can set up your own On Demand streaming service using the magic of mukt and muft (Free & Open Source) software.

Here is a guide to help you setup your own On Demand Streaming System. We will be doing this using a nifty platform called Ampache – the Apache Amplifier.

Ampache has the ability to allow multiple users access the data, create sessions and personalized playlists. According to the website - Ampache is a web based audio/video streaming application and file manager allowing you to access your music & videos from anywhere, using almost any Internet enabled device.

This means, once set up, you can stream to any device -- Android phones, tablets, netbook and of course laptops & desktops -- which can connect to your network.

All you need is a PC running a GNU/Linux operating system. In this guide we are using Ubuntu, you can use any Linux distro of your choice.

You will need a working AMP (Apache, MySQL, PHP) setup. In Ubuntu, install the three software packages using Synaptic. If you are the adventurous type, you may also install the components individually and go about configuring each manually. This is a fun learning process, but only if you want to get your hands really dirty! You may also want to install the MySQL GUI Tools in case any problems arise and you need to do some under-the-hood fiddling.

Read More....

how Keep Your Files Secure On Ubuntu

how Keep Your Files Secure On Ubuntu

While working in a project, we all need to share various files and directories to our peers. It sometimes happens that a file gets deleted by mistake by the peers while working with it. In that case, if you do not have a backup of the file then a lot of hardwork gets wasted.

So, in Unix like system there are permission bits which let you chose what permission (read, or write, or execute, or all the three) do you want to give to a group, user, or others. But there is a fourth protection bit called the Sticky bit and it helps secure your files.

There are two major benefits of this Sticky Bit:

  • When the sticky bit is on in a regular file it keeps the file loaded into the RAM so that you can access the files quickly.
  • Helps you secure your file so that no one else can delete it.

Today memory has become cheap, so it is not so important to have sticky bit on for regular files. But when it comes to directories it is a really useful feature. The Sticky bit is by default set on in the /tmp directory. So, anyone can create any files or directory into the /tmp, but cannot delete other users files which are create there.

The sticky bit is useful for implementing group projects. Let us consider the situation, when a group of users work on a set of files without infringing on security...

1. Create a common group for the users in /etc/projects
2. Create seperate user accounts for each of them but specify the same home directory
3. Make sure the home directory and all subdirectories are not owned by any of the users.
4. Then, set the permission to group writeable abd set the sticky bit.

$ chmod 1775 [filename] or [directory], where chmod stands for 'change file mode bits'. For more information, type 'man chmod' on your terminal.

Read More ...

How To connect Tata photon plus in Ubuntu

How To connect Tata photon plus in Ubuntu

I recently purchased a Tata Photon plus, Huawei EC1261, and was wondering if I could use it in my Ubuntu 10.04. While buying the Tata Photon plus I asked the sales person if I could use the Tata Photon plus on my Linux system. He replied back saying, "No Sir, you cannot use it on Linux system. The device is made for Windows." I told him that I had searched on the Internet and found that the device can be used for Linux system. The sales person told 'maybe' and he can help me install the device only on a Windows system.

Now the challenge for me was to install Tata Photon plus on my Ubuntu 10.04. Around a year back, I had bought a 'Mobile Broadband' of Tata Photon and to get it installed on openSUSE was quite a task. I had to install wvdail and few others dependencies. But, when I tried to install the new Tata Photon plus on my Ubuntu 10.04, I found it was really easy-to-install. This is how I setup my Tata Photon plus on my Ubuntu 10.04 LTS. Read More

Tuesday, November 9, 2010

how directly login to mysql database without password prompt

how directly login to mysql database without password prompt

#mysql -Dmy_database -uroot -p123456 <-------

we can use this command to login to a mysql database and do some operations, using shell script.

------------------ Shell Script

1)create a file mysql_login.sh

2)Then type following line in it .
mysql -Dmy_database -uroot -p123456

3)save file

4)#chmod 777 mysql_login.sh

5)./mysql_login.sh <------ To run script

---------------------

how restore mysql database from dump file

how restore mysql database from dump file

#mysql -uroot -p123456 <----- Entering into Mysql prompt

mysql>

mysql> create database my_new_database; <----- Creating database 'my_new_database'

#mysql -uroot -p123456 my_new_database < /root/batabase_dump.sql <------ Restoring database from dump file

How partition disk in Linux ubuntu fedora debian

How partition disk in Linux Ubuntu fedora Debian

#cfdisk

best Ubuntu audio video players

popular Ubuntu audio video players

SMPlayer

totem-gstreamer

totem-xine

gxine

VLC


apt-get update
apt-get install vlc vlc-plugin-pulse mozilla-plugin-vlc

how install java jdk jre linux ubuntu fedora debian

how install java, jdk and jre in Linux Ubuntu fedora Debian

* On the command line, type:

$ sudo apt-get install openjdk-6-jre <----------

The openjdk-6-jre package contains just the Java Runtime Environment. If you want to develop Java programs then install the openjdk-6-jdk package.

$ sudo apt-get install openjdk-6-jdk <--------


http://openjdk.java.net/install/

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

Netbeans installation directory
/usr/local/netbeans-6.7

Java environment installation directory
/usr/lib/jvm/java-6-openjdk/jre



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

Create iso from CD/DVD linux ubuntu fedora debian

Create iso from CD/DVD linux Ubuntu fedora debian

----------- If CD/DVD drive is /dev/hdc

dd if=/dev/hdc of=/home/saju/file.iso

or

cat /dev/hdc > /home/saju/file.iso

----------- If CD/DVD drive is /dev/scd0

dd if=/dev/scd0 of=/home/saju/file.iso

or

cat /dev/scd0 > /home/saju/file.iso

How format disk in Linux ubuntu fedora debian

How format disk in Linux Ubuntu Fedora Debian.

#mkfs.ext3 /dev/sda6
#mkfs.ext4 /dev/sda6
#mkfs.ntfs /dev/sda6

--------------------- vim /etc/stab

/dev/sda6 /mnt/sda6 ext4 defaults 0 2



--------------------- To save the changes in /etc/fstab
#mount -a


---------------------
Label the partition

You can label the partition using e2label. For example, if you want to label the new partition /backup, enter
# e2label /dev/sdb1 /backup

You can use label name instead of partition name to mount disk using /etc/fstab:
LABEL=/backup /disk1 ext3 defaults 1 2

Thursday, November 4, 2010

Wednesday, November 3, 2010

howto pyqt project taskmanager


# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'a.ui'
#
# Created: Sat Oct 2 02:08:21 2010
# by: PyQt4 UI code generator 4.7.2
#
# WARNING! All changes made in this file will be lost!

from PyQt4 import QtCore, QtGui

class Ui_MainWindow(QtGui.QMainWindow):

def __init__(self):
self.widget=QtGui.QMainWindow()
self.setupUi(self.widget)

def setupUi(self, MainWindow):
self.widget.setGeometry(QtCore.QRect(0, 0, 500, 500))
MainWindow.setObjectName("MainWindow")
self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.but_show_proc = QtGui.QPushButton(self.centralwidget)
self.but_show_proc.setGeometry(QtCore.QRect(100, 400, 93, 27))
self.but_show_proc.setObjectName("but_show_proc")
self.tableWidget = QtGui.QTableWidget(self.centralwidget)
self.tableWidget.setGeometry(QtCore.QRect(90, 30, 340, 341))
self.tableWidget.setObjectName("tableWidget")
self.tableWidget.setColumnCount(3)
self.tableWidget.setRowCount(0)
item = QtGui.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(0, item)
item = QtGui.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(1, item)
item = QtGui.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(2, item)
self.but_shutdown = QtGui.QPushButton(self.centralwidget)
self.but_shutdown.setGeometry(QtCore.QRect(260, 400, 93, 27))
self.but_shutdown.setObjectName("but_shutdown")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtGui.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 549, 23))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtGui.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
QtCore.QObject.connect(self.but_shutdown,QtCore.SIGNAL("clicked()"),self.shutdown)
QtCore.QObject.connect(self.but_show_proc,QtCore.SIGNAL("clicked()"),self.show_process)
self.show_process()
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)

def show_process(self):
try:
import subprocess as subp
f1 = subp.Popen(['ps', '-au'], stdout = subp.PIPE)
lines = []
for l in f1.stdout.readlines():
lines.append(l)
self.tableWidget.setRowCount(len(lines[1:]))
r = 0
for x in lines[1:]:
item=QtGui.QTableWidgetItem()
item.setText(x.split(' ')[6])
self.tableWidget.setItem(r,0,item)

item=QtGui.QTableWidgetItem()
item.setText(x.split(' ')[8])
self.tableWidget.setItem(r,1,item)

item=QtGui.QTableWidgetItem()
item.setText(x.split(' ')[10])
self.tableWidget.setItem(r,2,item)
r += 1
except Exception, e:
print e

def shutdown(self):
import subprocess as subp
subp.Popen('poweroff')

def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow",
"Task Manager", None, QtGui.QApplication.UnicodeUTF8))
self.but_show_proc.setText(QtGui.QApplication.translate("MainWindow",
"Refresh", None, QtGui.QApplication.UnicodeUTF8))
self.tableWidget.horizontalHeaderItem(0).setText(QtGui.QApplication.
translate("MainWindow", "PID", None, QtGui.QApplication.UnicodeUTF8))
self.tableWidget.horizontalHeaderItem(1).setText(QtGui.QApplication.
translate("MainWindow", "Cpu", None, QtGui.QApplication.UnicodeUTF8))
self.tableWidget.horizontalHeaderItem(2).setText(QtGui.QApplication.
translate("MainWindow", "Mem", None, QtGui.QApplication.UnicodeUTF8))
self.but_shutdown.setText(QtGui.QApplication.translate("MainWindow",
"Shutdown", None, QtGui.QApplication.UnicodeUTF8))


import sys
if __name__ == "__main__":
app=QtGui.QApplication(sys.argv)
obj=Ui_MainWindow()
obj.widget.show()
sys.exit(app.exec_())

python List extend() method

List extend() method

>>> l = [1]
>>>
>>> n = {'a':2,'b':3} <--------dict
>>>
>>> l.extend(n)
>>> l
[1, 'a', 'b'] <------- Note: taken only keys
>>> n = (8,9) <--------Tuple
>>> l.extend(n)
>>> l
[1, 'a', 'b', 8, 9]
>>>

Python isinstance() check

Python isinstance() check

>>> a = [1]
>>>
>>>
>>> isinstance(a , list)
True

>>> isinstance(a , (list))
True

>>> isinstance(a , tuple)
False

>>> isinstance(a , (tuple))
False

>>> isinstance(a , (tuple, list))
True

>>> isinstance(a , (tuple, list, dict))
True

>>> a = (1)
>>> isinstance(a , (tuple, list, dict))
False

>>> a = (1,)
>>> isinstance(a , (tuple, list, dict))
True

>>> a = {'n':1}
>>> isinstance(a , (tuple, list, dict))
True
>>>



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