• About

    Swaroop C H is 29 years of age. He is a coder and startupper. He has previously worked at Yahoo!, Adobe, his own startup and Infibeam.


    Read more about him


    Email: swaroop (at) swaroopch.com

  • Subscription

    If you want to know when new stories and articles appear on this website, you can receive them via:

  • I'm a Wannabe Hacker

    The Glider: A Universal Hacker Emblem

Archive for the ‘Python’ Category

Lookup

Saturday, August 25th, 2007

Most of my writing inside the browser is done with the combination of the It’s All Text extension and Vim. During this writing, I use words whose meaning I know vaguely but don’t know the exact usage, and in such cases, I usually open a new browser window and look up the meaning of the word in an online dictionary. This process of looking up the dictionary meaning was getting rather tedious, so I wrote a small Vim plugin today to do this job with a simple command.

To use the plugin, first install BeautifulSoup. Then, get my lookup.vim script and copy it to ~/.vim/plugin/.. See the new version’s installation instructions, it now uses John Goerzen’s dict client implementation in Python.

Next time you use Vim, just place your cursor over any word and run :Lookup, and you’ll see something like this:

lookup.vim screenshot

Since, this is the only command starting with L on my Vim installation, I just end up running :L. Of course, you can always create your own keyboard shortcuts to make it easier.

Update: Based on the comments, I’ve updated the script to now use the DICT protocol and talks to some servers. This avoids screen-scraping, is much faster to use, allows me to now use both a dictionary and a thesaurus which is very very handy because I can see what other words I can use, and of course, doesn’t violate any TOS (which screen-scraping could amount to).

Big Brother

Tuesday, April 10th, 2007

Long ago, I had seen Nat Friedman show off a small Mono app that displayed the amount of time you spent on each application, and updated the chart in real time – so that you could clearly make out how much time you’re spending in the browser and how much time you’re actually spending on work.

I couldn’t locate that app, so I had been wanting to write my own version for a long time and finally got around to doing it today.

It turned out to be easier than I thought. First, I had to figure out how to find out what application has the current focus at any point in time, and I was trying to see if I can do it from Python (using the Win32 extensions, and yes, this hack is Windows-only). After a lot of searching, I finally found out that it boils down to just one line: win32gui.GetWindowText(win32gui.GetForegroundWindow()) and this would fetch the title of the application that the user is using at that moment.

After this, all I had to was record the window title every 5 seconds and increment the time spent for each window, and voila, the data is ready. I was quite satisfied with just a command line output, but Raghu egged me on to create a Flex chart frontend for it as well, and when Harish joined in, the fun really got started. The first problem was how to push the data from Python to Flex, and we use the oldest trick in the book – write it to a file. Next, Flex can read the same file as long as the file is in the same directory as the SWF (i.e. the Flash file) location. Then we parse the text to get back the original data, create a pie chart and point it to this data, and voila we have a beautiful chart:

big brother gui example

Now I can finally track what I actually end up doing the whole day, heh. You can download the files if you want to use it as well:

And who said meetings aren’t productive ;-)


Update:

  1. Chris J Andrews made a JavaScript GUI frontend.

  2. Theyagarajan modified the Python script to make it work on Linux.

Brazilian Portuguese Bytes of Python

Wednesday, June 14th, 2006

Samuel Dias Neto has translated “A Byte of Python” to Brazilian Portuguese.

Hats off to Sam!

Update on 2011-Sep-01: Link updated

Mukthi

Friday, March 17th, 2006

Today, I talked at Mukthi 6.03 at M S Ramaiah Institute of Technology.

First of all, M S Ramaiah is a huge campus. So huge that the students actually tell the teachers that they were late for class because they couldn’t find the class, and that’s a fact. I made sure that Srichand, the student who took me inside to the auditorium led me back to the front gate as well, so that I wouldn’t get lost.

The auditorium where the talk was scheduled was in the new building, so it was plush, comfy, and it wasn’t a big auditorium which was perfect. The talk (introduction to Python) went well, the students were alert and interactive (even though the talk was between 5-6 pm) and I was especially happy with the range of questions that came at the end of the talk.

After the talk was over, one of the students announced that Mukthi was originally planned as a 1-day event, but later they made it a 2-day event because I had informed them that I would be available only on 17th to present a talk and not on the 18th. Whoa!

Why won’t I be here on 18th? That’s where my next post comes in.

German Bytes of Python

Monday, March 13th, 2006

Yesterday, I got this mail from Christoph Zwerschke:

Thanks a lot for “A Byte of Python”. Since I thought it would be great if Python gets more popular in German, I participated in the German translation project at BerliOS started by Lutz Horn. Unfortunately, the translation progress stalled last year shortly before the work was finished since all of us were very busy. However, this weekend I found some time to finish the translation and cut a German release, which is now available at http://abop-german.berlios.de.

Greetings from Germany, Christoph Zwerschke

Hats off to Christoph, Lutz Horn and others who made the German version happen! Thank you guys :-)

Byte of Python is now a wiki

Wednesday, February 22nd, 2006

In a recent discussion on the byte-of-python list, an enthusiastic bunch of people were interested in seeing A Byte of Python available as a wiki so that readers can contribute directly as well.

So, I followed up and made this announcement on the list recently :

Hello all,

As we have discussed, suggestions that Byte of Python should be converted to a wiki garnered enthusiastic responses. I’ve finished converting the book to the wiki and is available at http://swaroopch.info/text/Byte_of_Python:Main_Page .

There are some Todos I’ve sprinkled across the book which I will be working on in the coming weeks. Few readers have taken the trouble in pointing out how to export a book from the wiki as well. Once I can work on the todos, I’ll work on a downloadable version.

A good advantage of the wiki is that my turn-around time to suggestions from readers have improved. For example, a user pointed out that ESR is not the one who coined the term ‘open source’ and I corrected it on the wikibook within 2 minutes.

If you want to add/remove/improve any text in the book, please feel free to register as a user on the wiki and start editing. However, if you only want to read the book, there is no need to register.

Help about how to use the MediaWiki is available at http://meta.wikimedia.org/wiki/Help:Contents .

MCC FOSS Day

Saturday, February 18th, 2006

Yesterday, I talked about Python at the FOSS Day at Mount Carmel College For Women.

I was not able to attend the earlier sessions in the day because my team (at work) is making a release soon and as expected, that means crunch time. I managed to make time for presenting my own talk and attending Shreyas’ talk (who spoke after me).

Before I started my talk, Surjo warned me to make my talk as non-technical as possible. I was informed that some of the earlier talks had not been well received by the audience since it was “too technical”. That reminded me of Guy Kawasaki’s notes from a Stevenote where he says it helps that Steve has a beautiful operating system to show off, and for me, it helps that I have a beautiful language to show off, heh.

Earlier in the day, I had reminded myself of Simon’s notes on public speaking where he makes two good suggestions:

  • Show, don’t tell
  • Never, ever put up a whole slide full of code

Following this advice, I had stripped down the content of my presentation (the same presentation that I have used earlier for beginner Python talks) to the bare minimum.

The mistake in my last talk at foss.in was that I had made the slides too detailed and I suffered by trying to “stick to the slides”. Since I had avoided that this time, I had a free hand in what I spoke and actually used the slides for what they were meant – a reminder of what topics to talk about and not a replacement for the speaker. As a result, my talk was better than I anticipated.

Since I was asked to try to make the talk non-technical and I had also perceived the audience to have a short attention span, I decided to make the talk more about interaction rather than about Python. Most of them knew about C, so I followed the principle of “always start from the known to the unknown” and kept comparing C to Python and that helped to keep them interested. I knew the talk was going well when I compared their 6-line version of Hello World in C to 1 line in Python, and when I demoed some simple statements and asked them “I just ran a program, but where’s the semicolon?” – that surprised them and they started clapping. From there on, it was all about keeping them enthused.

![100966772][Small][]

I asked them if they liked cricketers or film stars, and they gave an overwhelming response that cricketers were preferred. So, I wrote a Python list and added names of cricketers they liked (Irfan Pathan is popular indeed) and asked them how they would get the second and third cricketers names in a C array and compared that with slicing in Python and that received cheers as well.

One of the few mistakes I did was waste a lot of time in the last part of my talk trying to download FeedParser to demonstrate how to use it.

After the talk was over, I received some good feedback as well as questions, which is always a good sign. It’s good to know that I’m improving my speaking skills. I’ve come a long way from a kid who thought thrice before standing up in class.

Interestingly, this has been my 10th talk on stage.

ShowMeDo

Friday, February 17th, 2006

Ian Ozsvald and Kyran Dale have created ShowMeDo.com which is a hub for video tutorials. Very interesting idea! Currently, it has a special emphasis on Python. This should be helpful for beginners and perhaps teach experts a trick or two as well.

I found the Debugging with WinPDB video very useful.

Ian will be uploading some wxPython introductions shortly, and they’ve got matplotlib, PythonWin, PyDev and more planned.

Also, users can contribute their own videos as well.

Update : The wxPython videos have been already uploaded.

Disclaimer : I was asked for feedback before the website’s release, but I have no other involvement with the website.

Jump

Sunday, December 25th, 2005

Gopal, I’ve added the jump feature, but sorry, no UI for it :-)

Guido at Google

Thursday, December 22nd, 2005

Guido van Rossum now works at Google.