thoughts, ideas, code and other things...

Sunday, November 29, 2009

Recursion limit in Python

Doing ACODE today, I realized that my solution was getting a runtime error. While I had tested the code on my system with simple hand typed cases. So even if I had typed out a 500 digit random number to test the code, still it wouldn't run on SPOJ. I then tested it with a real 5000 digit number, and there you go, a nice RuntimeError -
  File "", line 20, in rek
dp[a] = rek(a+1)
File "", line 20, in rek
dp[a] = rek(a+1)
RuntimeError: maximum recursion depth exceeded
Here is a simple solution to increase your recursion limit while doing SPOJ or Euler problems, observe -
>>> import sys
>>> sys.getrecursionlimit()
>>> sys.setrecursionlimit(6000)
>>> sys.getrecursionlimit()

So from now on, don't forget a sys.setrecursionlimit( ... ) before you make python dig the deep jungle of recursive function calls.

Labels: , ,

Wednesday, November 11, 2009

PyMos - Creating mosaics of your photos was never easier

PyMos is a Python script/module that helps you generate those fancy photo mosaics wherein a large image is made out of tiny thumbnails of other images. But from a distance, the mosaic looks like original image. Here is an example.
PyMos just started as an random hack which later turned into an impromptu hackathon as Yuvi puts it. Man it was fun to work together with someone for the first time, to learn so many new things, and to get more awesome ideas through discussion. Some of the noteworthy things I came through this project are - argparse, PIL, setuptools, some more git gyaan, that colorspace can be also treated like x-y-z vectors, logging in python, caching things using Pickle to save time, writing re-usable code, checking code against standards using pylint, rounding off corners and adding shadows with css, and what not.
I never wished to put too much in the blog about it. Just finished the project page for PyMos an hour ago - Get to know more about PyMos at its project page.

this is how it should look.

Besides that, while making the page I noticed a few things -
  • I happened to find a nice motive for PyMos' existence - these people who sell mosaics as a service. PyMos liberates you financially, intellectually and gives you freedom to mix-n-mash to make your own custom version... for it is a F/OSS
  • The project page would look nice in modern browsers only as I've utilized CSS3 @font-face to pull in some nice fonts.
  • I've also used CSS to save time doing round corners and shadows, so again you need a good browser that supports it, currently Firefox 3.5+ and webkit based ones.
  • By the way, PyMos project page is totally made on Linux, thanks to wine for letting me run Photoshop 7, I no longer have to look towards windows in any case, not even in times of creativity blues.
  • Since I'm not an advanced user of Photoshop, I hardly find any differences in cs3 or 7 as far as the way I use.
So, have fun making some cool mosaics with PyMos :)

Labels: , , , , , ,

Friday, November 06, 2009

Introducing GTweetBar (alpha)

This is my Xournal entry of April 27th 2009. It clearly speaks of how much time I take in between imagining and creating things. I need to improve a lot on that part, or maybe organize my time well, and hack myself away from that saturday-sunday syndrome where you feel like spending the weekend doing nothing for you've been already been wasting time for college for 12 hrs a day away from your system.
Oh sweet, this snap is when I had just upgraded to Ubuntu 9.04 :)

Been almost 6 months I guess :o. A couple of months back I was playing around with gtk, glade, etc which gave some confidence to work over making it for real. So here we have - GTweetBar - A GNOME Panel Applet that lets you update your twitter status on the fly. An omnipresent, super-simplified twitter-client for your linux desktop. (which is still in development)
I initially started writing this applet with PyGTK and glade. The tutorials for writing a panel applet on gnome are pretty limited and there is a shortage of simple examples for beginners as far as I think. I found an interesting problem during the development, the Entry box did not respond when the app is run as applet. I found it pretty weird, but that led into a better understanding of how signals and handled, why and when to use an Event box and the use of applet.request_focus(). All this had to be understood by reading a random pastebin entry! :)
There were more issues coming later, I got it tested from a few friends on twitter. It's pretty cool to find the Issues section on github. It lets users of your software communicate and talk about any problems they encounter. Pretty cool to have it along the project page. Github \m/
Testing it on Ubuntu 8.04 on my old PC helped uncover some more compatibility issues. It seems that gtk.gdk.Color("#93E9FF") isn't backward compatible. You can use gtk.gdk.color_parse("#93E9FF") instead to ensure it works.

Here are few snaps -

As of now, I have to fix a lot of bugs (pending after end sems). It's not working on Ubuntu 9.10 under applet mode. Working with YuviPanda on PyMos taught me a lot of things. I also used GConf to store user preferences. Man! Its dead simple to use.. So this calls for an extension of todo list :) -

[ ] alerts for failed tweets...
[ ] loads of exception handling here and there
[ ] new setup using setuptools
[ ] test portability of python_twitter or throw it as dependency in setup()
[ ] add logging
[ ] optparse/argparse
[ ] tool tips to show current status
[ ] beautify the code
[ ] a drop down list of tweets

So go ahead fork it, test it, use it - GTweetBar alpha.

Labels: , , , , ,

Sunday, November 01, 2009

On Death - from 'Norwegian Wood'

Haruki Murakami has an excellent view on Death in his Novel 'Norwegian Wood', here it is -
This had seemed to me the simple, logical truth. Life is here, death is over there. I am here, not over there.
The night Kizuki died, however, I lost the ability to see death (and life) in such simple terms. Death was not the opposite of life. It was already here, within my being, it had always been here, and no struggle would permit me to forget that.
When it took the 17-year-old Kizuki that night in May, death took me as well.
Not that I can relate to the death scene in the novel, but there are 100 of other incidents in the novel that I can relate to, and observations that I did not have words to express. Interesting read indeed...

Labels: ,