Archive for the ‘Programming’ Category

Picasa wordpress sidebar widget

Saturday, June 2nd, 2007

When I saw cool random photo display gadget at wela’s blog, I also wanted something like that. Earlier I had a gallery2 installed, but when Google released picasa, I found it much easier. It actually optimizes the photos and then uploads. So, I switched to picasa. Fortunately, picasa have RSS feeds for each album :).

At first I thought of writing a normal wordpress plugin, but then since it’s in the sidebar, I thought of writing a widget. My blog was running wordpress 2.1 and either I had to install the widget plugin or install the new wordpress 2.2(Wordpress 2.2 comes with the builtin support for widgets). Since there are some bug fixes in version 2.2, I upgraded to that.

Then, after coping about three lines of codes into my theme, I widgetized it. Then, finally it’s writing the widget.

Actually, the widget was fairly easy to write because the wordpress itself has a rss parser. Even though, it doesn’t completely parse the RSS given by picasa, I managed to use some regular expressions and get the necessary values.

When I finished writing the widget, I realized that there is no point of downloading the RSS each time when someone requests the site. So, I put a download delay time and the stored the parsed RSS results as a wordpress option.

If you want to try this, click here to download. Copy the file into wp-content/plugins/widgets directory. Then, activate the plugin and add that to the sidebar from Presentation -> widgets. (You should have widgets plugin installed)

Development of AcSO - From A to Z

Sunday, May 20th, 2007

Last month we got selected… oh! In case you don’t know about that, just read my previous post. “And Then” the next phrase - Development.

AcSO is basically academic information sharing site, which will be run by the users (Web 2.0 concept). So, it has some amazing features, but no so hard to code. However, since we have four fellas in the team and we want this built well, we need to come up with a nice site structure.

There was an ASP.NET built in login system. It’s very easier to use. But there were some problems, by default it uses some kind of weird database and replacing it is not so easy. So, we argued about two days whether we shall use it or not and finally decided to code our own one which only took about 15 mins :P

First what we decided was to use portlets; basically, web parts. After developing sevaral portlets, we again reran an evaluation and decided that we don’t need portlets.

Then we had an exam paper and after all we have 3 and half days to build the application. So, we just started coding raw pages, and we used some base classes written for the web part application and here is the final result : http://team4366.webdev07.imaginecup.com/

There was one big problem when we are developing the site, “version controlling”. Keshan and Me replaced each others codes several times. So, after all we used manual version controlling mechanism. Before updating code, I always took a backup of the current site. Believe me, I have more than 300 MB in backup files. But, it along didn’t solve the problem. So, we started to working at shifts ;-).

Since these pages have put together in three sleepless days, there are lots of features missing. And we also didn’t have much time to put the validations, etc. Basically, we haven’t fine tuned the site. But anyway we are happy with the current progress of the site and if we go to the next stage, we should start development at least about a month before the deadline.

Microsoft Imagine Cup

Saturday, March 31st, 2007

I never thought I would have to add something called “Microsoft” in my tag list, but it’s happening. After going through a lot, we our two proposals, one for Software Design(GeoLink) and other for web development(AcSO), went to second round. OMG.. Imagine a doing two imagine cup projects.. damn.. it’ll be hell of a lot of work… let’s see. I’ll keep this up to date.

IOI Site is back

Tuesday, March 13th, 2007

Today, after going through a lot, I managed to get the ioi site running. Just drop in there if you are interested in programming.

The grader is written in C++, and the interface is written in PHP using AJAX. This whole project is open source, you can download it from the sourceforge project page. Current release version is bit old, hopefully I’ll upload the current working version tonight.

Another eye candy gadget to my linux box - Installing Cairo-Dock/Gnome-Dock in Ubuntu Edgy 6.10

Wednesday, February 21st, 2007

After install all those eye candy stuff, beryl, gdesklets and everything else, it looked quite nice. Amazingly, there weren’t any memory killers or frequent crashing apps. However, there is no doubt that apple Mac OS was/is the best eye candy OS ever. I don’t have to tell you that one of the most appealing applets is the icon doc at the bottom of the screen. So, since lot of people have their eyes on this, those are ported to many platforms (rather recoded not ported).

Now, It’s time for me to go for something instead of modeling the gnome panel itself. cairo-dock, it’s my choice. Installing cairo-dock quite easy if you have all the development libraries. There is no need for me to explain all the steps there - Just follow this link : http://ubuntuforums.org/showthread.php?t=302570. He has explained it step by step. The installation/compilation will go smoothly.

However even after you compiled the application, unfortunately there will be some errors. The first one is icons. Probably, what you’ll get will be some blank icons. The SVG files inside the tar ball doesn’t show up correctly. You might be already knowing that SVG files are text files. So, what you have to do is open the icons in ‘vi’ or ‘gedit’ or whatever, then just look at the source of the image. Most probably around the bottom of the file, there will be a link to a PNG file. Actually there will be two links linking to the same file. Just change the link to a valid path for a PNG image. Then you are ready to go.Recompile the application, then just run it. Then with any luck you’ll see the icons ;-)

Ah! I forgot to tell you about changing the icons/launchers. You have to change the g_aIcons array. It’s at the beginning of the file. The first parameter is the image, then the Text displayed, and finally the command. Make the display text as short as possible, otherwise those will overlap with each other and it’ll look kinda fuzzy or more to the point ugly.

After all things you have a working cairo-dock. Then the next step is to add it to the startup. I used the gnome session control panel, but however since I’m also loading beryl at the startup, cairo-dock used to crash. So, I removed this from the startup, and changed the beryl loading script(Look at my beryl installation post). So, the final script looks like this.


#!/bin/sh
beryl-manager
sleep 7
beryl&
sleep 7
/media/sda5/Software/cairo/cairo-dock/start-cairo-dock.sh

Now try restarting the Xorg, it’ll work like a pro. Even, it works as it should be, there are few problems regarding this. I usually use Alt + F4 to quit applications. So, when I keep quiting applications, if I pressed one more additional Alt + F4, damn… the cairo-dock will get closed and also if you pressed the “Show Desktop” button the cairo-dock will get minimized.

So, what do we do now? Don’t worry I have a small(small as in very small) hack to get rid of that problem. Open cairo-dock.c in vi(or whatever). Search for “gtk_window_new”(There is only one instance. It’ll be around the line 1180-1190). Change the second parameter of the function to “GTK_WINDOW_POPUP”. So, the line should look like this :


pWindow = gtk_window_new (GTK_WINDOW_POPUP);

Then, recompile the code and restart the dock. And finally you have another cool gadget to impress the people :D.

Enhance Apt-Get downloading using an external download accelerator(axel/prozilla/aget)

Wednesday, February 14th, 2007

The Apt-Get in debian systems use their own downloading system to download packages from the internet. It supports file resuming and pipelining. However, it doesn’t support downloading using multiple threads, and it won’t allow you to external applications to download.

However, the http downloader is a separate application(/usr/lib/apt/methods/http) from apt-get, and the apt-get spawns the executable to download the files. Those two programs communicate via stdin and stdout. I have written a new downloading application which can communicate with the apt-get. So, I just copied the executable to /usr/lib/apt/methods/http. The new application spawns another program(In my case a shell script) with two arguments; the url and the local file.

So, after all my shell script calls a python script. My program doesn’t call the python script directly because when the python scripts gives some output to stdout/stderr the apt-get program crashes. So, my shell script redirects the all output to /dev/null. Then, the python script will get the url, do a HEAD request, get the file size. If the file size is less than 100K, it’ll execute wget, if not it’ll execute axel. So, the files will get downloaded and apt-get will install the software.

The apt-get update command fetches many small files from the same server. Since the original downloader uses pipelining, it’s much faster. I have to modify my code to do something about pipelining.

Files :

scripts.tar.gz

apt.tar.gz

Downloading DVD iso

Wednesday, January 31st, 2007

Yesterday, I tried to download debian DVD images from their site. One image is about 4 GB which is bigger than 2^32 bytes. So, here is the problem; since all the download accelerators use 32 bit integers for the file size, it doesnt work at all. I tried prozilla and axel. Then I also tried to wget the file into my server, split it and download the files. Wget doesn’t work either.

I sent an email to LKLUG and one of them suggested to use jigdo. But It takes hell of a lot of time to download it file by file. The other solution is to use bittorrent, but I have port limitation problems. So, the only solution left is to download and modify the source code of an accelerator. I downloaded the axel code, but It’s seems bit messy to change it. So, I decided to code my own one to download it. It’s time to start coding again.

IE String arrays

Monday, January 29th, 2007

I was doing a japanese shopping site and coded a small escape function in javascript which is also works for shift-jis encoding. The native function screws up the encoding. It worked prefectly, and I went on coding. I was doing all the development in firefox and suddendly the login function stopped working in IE(Actually not stopped working, It never worked in IE). The problem was that I used the javascript string as an array of char but in IE, it doesn’t support that. If I want to access a character I have to use the charAt function. When I searched in the Internet, I found that this is so common but just blogged it anyway.

Learning python

Thursday, December 28th, 2006

Last few days, I was sleeping at home enjoying the lazy days of Christmas vacation. Except sleeping, went on a trip to nuwaraeliya, and more interestingly after Anjana pointed out some key features of python, I decided to give it a try, so started learning it. After spending few hours, I managed to learn the syntax which was well managed so that easy to learn. However, the syntax itself doesn’t make python special; so I went little deeper down to the python lib. That’s what makes a real difference. Python comes with a large collection of libraries, and those are damn powerful and easier to use.

Learning is not only reading and going through the example source codes. It’s actually writing something, writing a real world application. So, I started to write a web log analyzer. First I separated the log file by the date, and calculated the statistics for each day and saved them in different files. After that I wrote a small php script when the two days are given, it collects statistics and generates a xml file. After that it’s all about the interface; My ajax interface process the xml file and gives a nice output of what I have calculated, of course with some graphs(plotkit did the graph magic with javascript). However it needs some cleanups (I originally hard coded the log urls/search engines/etc), and the config file support should be added to it. Once I’m done with those, I’ll upload the source code soon… Yes, it’s distributed under GPL.

Google prime number problem

Tuesday, December 19th, 2006

Few years ago google placed a bill board in Silicon Valley (Well, I haven’t seen that but read the googleblog post). The board was about a small programming problem.

Somehow, that blog post became one of the top stories in digg recently; after seen it, I decided to give it a try. I just used the straight forward brute force method and it was surprisingly easy. It was just like a old days doing an IOI code, and more to the point, runtime doesn’t matter, memory limits doesn’t matter, and coding time doesn’t matter, so, what make it an IOI code is that code quality also doesn’t matter.

I just code like I always did… just coded… coded… coded… never bothered about the coding standards… and finally two small programs (e.zip). First I generated factorials up to 100, divide 1 by all those and saved the result (upto 500 decimal places) in a file. Then from the next program I added all those things together and checked for a prime. Pretty simple. The answer was 7427466391