Posts

Showing posts from April, 2013

Fighting the zombies out of your linux system ...

I had tough time to figure out that zombies are invading my linux box, here's the powerful one-liner to kill them all :) kill -9 `ps -ef | grep defunct | cut -d ' ' -f 3`

Enable valgrind on Xenserver hosts with openvswitch installations

To install valgrind on xenservers, yum install valgrind --enablerepo=base To enable valgrind for openvswitch, you could add it to the OVS_CTL_OPTS in the file /etc/sysconfig/openvswitch OVS_CTL_OPTS=--ovs-vswitchd-wrapper=valgrind

Python madness in comparisons with None

In python, everything is greater than None, >>> 0 > None True >>> 0 < None False >>> 1 > None True >>> 1 < None False >>> -1 > None True >>> -1 < None False >>> 'a' > None True >>> 'a' < None False >>> 1.0 > None True >>> 1.0 < None False

Overriding class variables and destroying overriden references in python classes

Input: class foo(object):     ref = None     def setup(self):         self.ref = 1234     def clear(self):         del self.ref obj = foo() print obj.ref obj.setup() print obj.ref obj.clear() print obj.ref O utput: None 1234 None

Tip to organize photos by date taken as folder name

exiftool -d "./%Y-%m-%d/%%f.%%e" "-filename<createdate" *.JPG If you don't like the default file names which are mostly like IMG_0001.JPG in the DSLR cameras, you can just use the time stamp using the following command, exiftool -d "./%Y-%m-%d/IMG_%Y%m%d_%H%M%S_%%-c.%%e" "-filename<createdate" *.JPG %%-c will kick in the counter for your sub-second shots.

Exceptions and Finally in python

>>> Input def foo():    try:        print "I am in foo"        return    except:        raise    finally:        print "finally of foo" def foo_exec():    try:        print "I am in foo_exec"        raise Exception("Exception in foo_exec")    except:        raise    finally:        print "finally of foo_exec" foo() foo_exec() >>> Output I am in foo finally of foo I am in foo_exec finally of foo_exec Traceback (most recent call last):   File "a.py", line 20, in <module>     foo_exec()   File "a.py", line 13, in foo_exec     raise Exception("Exception in foo_exec") Exception: Exception in foo_exec