Archive for September, 2009


recursive directory walker using jython

Several months ago I wrote a post related to creating a recursive directory walker in Python. We did not make use of os.walk. While playing with Jython I thought it would be nice to write an equivalent. Here’s what I have :

from import File
import sys

class FileWalker(object):
	def walk(dir,cbf):
	    files = dir.listFiles()
	    for file in files:
	        if file.isDirectory():
	walk = staticmethod(walk)

def list_file(file):
    print "saw %s" % file

if __name__ == "__main__":

I think the code is pretty straight-forward. If you’re familiar with Java even a little bit, I’m sure you can understand what’ s going on in here. You should know that the callback function isn’t receiving a string as it’s parameter ( as the first version of the walker did ) . This one receives a Java File object, which means you have access to all the methods present in the File class.


a decorator that could come in handy

def hook(func):
	def mcall(self,*arg,**karg):
		func_name 	= func.__name__
		before_func	= getattr(self,"before_%s" % func_name,None)
		after_func  = getattr(self,"after_%s" % func_name,None)
		if before_func:
		res = func(self,*arg,**karg)
		if after_func:
		return res
	return mcall

class TestClass:
	def xec_me(self):
		print "xec_me called"
		return 50
	def before_xec_me(self):
		print "before xec_me"
	def after_xec_me(self):
		print "after xec_me"

x = TestClass()
res = x.xec_me()
print res

Given a class, if the @hook decorator ( maybe not the best name ) is applied, before that method gets executed, it will search for a method called before_ and the name of the method. If that method is found, it will be executed. Same thing applies to after, just that it will be executed after the execution of the decorated method.

Here’s the output this will produce:

before xec_me
xec_me called
after xec_me


creating an iso from a mounted cd/dvd

dd if=/dev/cdrom of=cd.iso

The location of the CDROM device may vary from computer to computer. If your distribution mounts your CD automatically, execute this to find your device :

mount | grep -i cd


some tips on getting an internet connection in backtrack linux

If you have a wired internet connection, and want to USE it, here’s what you can do :

  • for pppoe, run pppoeconf as root, and make the necessary settings ( basically, you just need to fill in your username & password, and go with the default for the rest of the settings ). Choose to start the connection then. For some reason, I have to configure it every time the distro starts. Can’t imagine why.
  • for regular cable connection, enable the network interface ( in my case it was eth0 ), by typing the following command:
    ifconfig eth0 up

    and then do:

    dhclient eth0

    This should do the trick ( I tested both these on my computer, and they worked ). For static ip address, you can do this:

    ifconfig eth0

    and replace the X’s with the actual address. You may need to configure the routes also. See the route command for that.


how i fixed the sound on backtrack 4

I wanted to try backtrack 4 for a long time. Tonight I finally did. I’m running a Lenovo laptop, with a Intel soundcard.
When logged on as a regular user I noticed I didn’t have sound. Being an avid music fan, this was unacceptable so I started to look for a solution. After googling for a while, and trying all sort of things, I finally found what worked for me: adding the user to the audio group.
To do this, open the /etc/group and look for the audio line. On my system, this was like this :


To add your user to the group, simply change the line to this:


where user is the name of the user you’re logged in with. Reboot, and you’re done!

Enjoy the sound!


seven day mile


amazing video

This is AMAZING:

Blog Stats

  • 215,219 hits