Archive for October, 2008

Progress Bar

Wednesday, October 22nd, 2008

Here is something i have looked for a long time: printing on the stdout without make use of the new line (\n).
With this purpose i created a simple ascii progress bar.
Here is the code:

import sys, time

def main(argv):
	width = int(argv[1])
	length = width - 6
	for i in range(1, length + 1):
		percentage = "%3d%%" % (i*100/length)
		buff = "[" + "="*i + " "*(length - i) + "]" + percentage + "\r"
		sys.stdout.write(buff)
		sys.stdout.flush()
		time.sleep(0.1)
	print ""

if __name__ == '__main__': main(sys.argv)

Just save it as progressbar.py, and execute it with:

$ python progressbar.py "$COLUMNS"
[===================================>          ] 75%

Alan: alsa analyzer

Monday, October 20th, 2008

Alan is a tool which displays the playback of “default” alsa audio device; it can be used also as a dynamic spectrum analyzer.
In order to build alan you need alsa and gtk development libraries.

You can grab the source from the repo: the project name is alan.