iterm2 Tip: Guake-like!

Back in good old linux days, I used to use Guake terminal. The feature that I liked the most is the ability to launch a transparent terminal from the top of the screen. This enables running simple commands without having to go to another window/desktop. This definitely increased my productivity as a programmer!

Now that I have a Mac, I sort of was missing out on Guake! A couple of google searches yielded me to realise that the same behaviour is possible with iTerm2

Here’s how I did it:-

You can customise the settings for the “Hotkey Window” profile under the “Profiles” tab. To make it look like a Quake drop-down terminal, you can use similar “Window” preferences:

All in all, you will note some differences from Guake (if you have used it). It’s a good replacement.



Phantom Js (Amazing library for web scraping)

Web scraping is an extremely well-visited area while developing any project that involves large amount of data. At some point or the other, during the development of the project, you will need to download the data, extract it and store (either by dumping into a database or by storing in static files). There are many libraries that does scraping of data (to name one, we have Scrapy from Python). Scrapy or other web scraping frameworks have one major limitation :- They don’t come with a headless browser and so they cannot perform/emulate dynamic ajax queries.

Sample usecase :- You have two drop down menus in a page and you will need to select values in both of them to generate content. The second drop down menu is dynamically created on selection of the first drop down menu. And you will need to write a script to go and select all the choices in both menu1 and menu2.

Here’s where PhantomJS comes into picture.

Think of PhantomJS as a headless browser that can be controlled by writing javascript code. Once after you request for a page, you have several callback functions where you can place your code.

1) onPageCreated

2) onResourceRequested

3) onResourceReceived

4) onLoadFinished

These are some of the commonly used callback functions when you are scraping from a website. Others are listed here

In addition to providing you different callbacks, PhantomJS exposes your entire DOM. So you can manipulate individual elements, trigger a Ajax request. Run the code in a loop to select all the combinations in both your dropdown menus. Tada! Your scraper is ready.

Bonus Section

“Screen Capture”  This is a really cool feature with PhantomJS where you can capture your entire screen as a screenshot as viewed by the browser.

VDFuse replacing GuestFS

Just a week back, we decided to replace GuestFS and use VDFuse. Though GuestFS comes with certain advantages, w.r.t VDFuse in terms
of support for several file formats which makes it easy to extend to other file formats and also python bindings, we faced a lot
of problems working with it. Some of them are:

  • Installing GuestFS is a big headache as there are lot of dependencies to be installed and even after that its not necessary that
    it works always. This might turn out to be one reason for developers to not try out PyTI.
  • GuestFS is not very stable . There were lot of times it didnt work and couple of issues of GuestFS hanging without any reason.
  • It takes a lot of time initializing GuestFS for reading or writing into the disk

Yes, as I mentioned before, we moved to VDFuse for now. It grows out of the difficulties of GuestFS and it is a decent solution for
reading or writing to the disk.

Fun with VirtualMachines

Over the last one week , all I did was play with Virtual Machines. The tests on the distributions will happen over a Virtual Machine . So its very important that we can control these VMs with a script.

Candidate : VirtualBox
Operating System : Damn Small Linux
Virtual Hard disk : A VDI image of 2.5 GB
RAM: 256 MB
Library: used libvirt to control the virtual machines
Features tested: Start, Stop, Snapshot, Rollback

Using libvirt was nice. It supports a range of hypervisors to be controlled with the same library, though I had my fair share of difficulties especially with the documentation.

Another feature I worked on this week is mounting the virtual hard disk image on the host. I used libguestfs library to achieve this. The features I have added for PyTI for now are
uploading and downloading files from and to the virtual hard disk on to the host machine.

Would really thank Alexis, one of my mentor for his help in giving me feedback , refactoring my code and testing it .

Pyti Infrastructure

Not been blogging in a while , but I guess I should blog more about what I am doing these days , mostly working on my Gsoc Project proposal .

Here is what I learnt after a lot discussions in the mailing list and talking to different people about the idea.

The idea goes somewhat like this :

Basically there are lot of packages in the PyPI (python packaging index) repository and it is open to everyone. So the community had decided to implement a PyTI (Python Testing Infrastructure) to test the packages which a user want to download .

The course of the project somewhat goes like this :

1) The user requests a test on a package which he wants to download.
2) Using a feed/notifier , we can schedule a init() call to a virtual manager (in this case Amazon EC2 is the most prefered option)
3) The virtual manager boots the os and then cleans up the environment for testing .
4) The packages are installed with their dependencies
5) Tests are conducted on these packages which include
1. Test suite (If it is already present )
2. pep8,pylint,maccabe
3. custom tests
6) The vm is shutdown after cleaning up the environment
7) A qa is done and the user is notified of the results

Input audio from microphone

Today I learnt how to input audio directly from the microphone
It requires two packages alsaaudio and audioop if its not already present .

import alsaaudio, time, audioop
inp = alsaaudio.PCM(alsaaudio.PCM_CAPTURE,alsaaudio.PCM_NONBLOCK)

# Set attributes: Mono, 8000 Hz, 16 bit little endian samples


while True:
	# Read data from device
	l,data =
	if l:
		print audioop.max(data, 2)

The code will print the audio as data on the screen . Try shouting and you will find the difference. You can probably store it in a .wav file .

Python boot camp day 1

Just conducted the first day of the two day boot camp ..
It was just an introduction to python today .
I guess around 40 people attended , though dayscholars left early .
I taught simple concepts as to create variables, use control structures , loops and the advanced data types of python-lists,tuples, and dictionaries. Taught them the basics as to how to run the scripts, how to create new modules ,etc,etc…..
Special thanks to ASCII team for organizing the boot camp , ofcourse who can forge Mr.Gautam .
Finally the audience was good, they understood the concepts , asked me a lot of questions,
I got a positive feedback from the crowd/audience..
Enjoyed teaching python , mostly it was my voice which i just startled me . I fell in love with my voice , reverberating the room 🙂
Planning to surprise the audience tomorrow , with some thing innovative. 🙂