Sunday, October 17, 2010

The winner? Really?

Kind of read a tweet and even RTed it too. Something about which language is about to go hype next.

The author of the article neatly jots down so many languages, some of them I've never really heard of. But if you ask me. There is no one language that will make it. Or, if I were to rephrase it, almost all languages make it. This article kind of lead me into thinking how do we gauge the popularity of a language?

My views now prompts a simple answer: community adoption. And, I don't mean the community of people 'use a language' and 'make it popular'. It kind of goes on the lines of where the trend is going; what consumers are interested in. If it is more into mobile space, for e.g. say that consumers want to run heavy applications on their hand held devices, developers would look more into how to efficiently utilize the power of the processors, etc etc. Hence they'd look for a language or a product which would give them more productivity and the capability of writing complex software.

So these are just my views for the moment. Of course, other people definitely have other ideas. Please feel free to voice them.

Wednesday, August 4, 2010

MVC joke

So Model, View and Controller walk into a bar to have a drink. All the three get really high. Then the Controller slaps Model, in the face and leaves. View has her hands to her head.

What did Model say?


“I love View”

Wednesday, July 14, 2010

python: using simplejson to JSON serialize

When you search the web for how to json serialize you data you first encounter a module called simplejson. But using simplejson is the one exactly says how you can use it...

The simplejson library is fortunately friendly with python dictionaries. And hence here is a small example to start off with:
import simplejson

vals['user'] = 'deostroll'
vals['visits'] = 46
vals['date_of_birth'] = '10/27/1986'

print simplejson.dumps(vals)
This library sadly doesn't know how to serialize a class object. However the work around to that is quite simple too.
class a():
x = a() = 'Arun'
x.designation = 'Software Engineer'
x.department = 'Media & Entertainment'
x.age = 24

print simplejson.dumps(x.__dict__)
Hope you've understood how you can now use simplejson library. Happy programming

Thursday, June 24, 2010

Hosting from home

I was recently playing around with apache and my belkin wireless router. I got the hint that I can use my computer at home to host websites over the internet from hanging around in the apache IRC channel and interacting with people there. But I didn’t know what my router was actually capable of.

Stuff you need

You need is a web server. Any web server; it needn’t be apache – what I used.

You will need a broadband connection. The thing to take care here is that your connection should have only one static IP address. It means each time you connect to the internet it should be through this IP address only.

You technically don’t need a router! But having a router is advantageous. Most modern routers have a feature called port-forwarding. If a router is configured for port-forwarding port 8083 to port 80, it will literally “forward” those packets with port address 8083 to port 80, which is the default port most web server programs bind to.

A word about the web server

I did most of my experiments on apache. Once if apache is neatly installed and running on the machine we simply open a browser and type http://localhost , to see if it works. You’d mostly get a default message like “it works” or sometimes you might even get something more colorful. It depends on what is set as the default message for the installation. I am not sure about how all the other web servers work. But there is usually some default message.

Finding your IP

This is the easiest part of this whole exercise. Just browse to

Or you can call your service provider and ask them to find it for you.

That’s it!!!

Instead of typing localhost in your web browser, type the ip address: i.e. http://[your_ip_address]/

You should see the default message here. If you check the server’s log you should find an entry pertaining to what you’ve just typed in your browser.

For those who have configured port-forwarding on your router, simply type http://[your_ip_address]:[port_number]/ in the browser.

Final words

It is actually very simple to use your home computer as a web host. But it is not recommended. There are many reasons for this. Foremost your machine does not have the hardware that most web hosting providers have. Your machine does not have the level of virus protection professional hosting servers have. When I was excited that I was able to make my web server serve something via the internet to some other computer elsewhere, I posted it on twitter. I left it online about for 10 min to do various sorts of testing. I had close to 10-15 hits mostly from search engine crawlers and the like.

Next steps

The next post I am going to explain how you can host your own intranet website with just your router, and also how you can give it a more lovable name instead of an IP address.

Sunday, April 11, 2010

A stint at building a mobile web application

Spent a whole weekend trying to build a simple mobile web application using Google's AppEngine as my web server. Took this initiative to simply know what its like building a mobile web applications, how is it different from doing traditional web applications. I did spend time googling and learned about a couple of things:

a) How ajax was made more convenient for web developers?

There are several libraries which abstract the usage of the XMLHttpRequest object. On different os platforms we have different ways of instantiating this object. But most libraries abstract this leaving you to only concentrate on what service you call, what data you send, and what to do once you get a response back. There are many libraries, like jQuery, Prototype, and YUI libraries which hide complex details enabling the developer to make high-end ajax invocations by supplying classes.

$.get( 'sample.jsp', ResponseHandler);

But most of these libraries are bulky. They are designed for popular browsers like Firefox, Safari, Internet Explorer, etc. Do you think you can use these libraries for your mobile web page? Do you need such heavy libraries again?

b) How does the mobile platform differ?

Mobiles phones possess limited computing power. The processors inside phones are designed to make optimum usage of memory and other resources. A simple operation like adding might take more cycles than a normal desktop computer CPU would. More the number of cycles means more energy is consumed. Hence programs written for mobile phones must be written/used in such a way that they utilize less power.

c) Designing your web applications so that your phones take less power

This essentially means making your mobile phone processors do minimum work to the core. But developers don't freak about and measure cpu cycles to know if their web application is running fine! Instead they simply serve more html. For e.g. if its some kind of report you have to serve to a mobile browser; html-ize it. If there is some “work” that has to be done at the client end for this report – minimize it.

d) AJAX does help those who support it.

There are some mobile phone browsers that don't have AJAX capability. Web applications for such phones have to be designed to utilize a postback model of serving requests. Almost every request is an HTTP POST; hence the browser has to refresh the screen, and then load new contents, etc. This obviously consumes more power. Such levels of consumption can be drastically brought down if those requests were served in an ajax-ed manner.

e) Do remember all those poor GPRS networks...

This contradicts with point c. Although its ideal to serve as much as html, one has to realize the time it would take to for that data to reach the browser. Most GPRS networks have very limited bandwidth, and hence sending a lot of data for the page to load isn't all that a good idea. So in this light we must send minimum amount of data to the browser. In fact JSON could do a great deal in this sphere. But then its up to the developers fair judgment to find the right balance. And once you learn it, it won't be all that difficult.


As far as points c & e are concerned I just feel that the first law of thermodynamics can be neatly taken note of...

Happy programming :)

AJAX and social networking

I just remembered this blog is also about things on the internet that I find fascinating.  And if you are a total computer dummy, ajax might sound like a xenophobic term to you already. In the web space ajax is a buzz word. To make a long story short, ajax is just a simple technique by which your web page can be made to look more interactive. The expansion of AJAX is (brace yourself) Asychronous Javascript And XML. In my opinion it is a bundle of many technologies. You probably might even hear the word JavaScript frequently. But something you don't hear, but somehow involved in the whole internet fabric is the W3C. I am cutting short all the history; it isn't difficult to google and find out however. The main focus of this post however is how ajax has influenced social networking and proxy browsing. And if any of you people decide to build social networking sites here are some points that you might want to implement in the beginning stages.

Do you remember the first social networking site that got popular? At least in this part of the world I feel it was orkut. There are other sites more advanced and user friendly than orkut, yet orkut remains to be a classic example of a social networking site. I still love the idea behind leaving a scrap. So simple. Less noisy. Beatific. But orkut has been privy to many cultural & privacy problems. It was blocked in Iran because the Islamic community there had strong views about dating, etc. After the Iranian government blocked the site, there have been a lot of proxy sites which allowed you to access orkut. Proxy sites allowed for anonymous browsing of orkut pages. During those times orkut pages were fairly simple I guess. Later google disallowed anonymous browsing over its secured http page. Actually google did a lot of things. The most prominent thing you might always miss is the Loading... part.

This is what google did to render proxy browsing useless. So here is a little about how orkut page gets loaded. After you provide your username and password to log-in to the site, you are taken to the main page (Home.aspx#Main). From a web designers perspective this is nothing but an empty page with place holders (like your friend list, upcoming birthdays, friend updates, etc) where data & images are supposed to sit. These place holders are not marked to be visible to the user. Hence the net effect is a nearly blank page except for the background color and all. (You are welcome the view page source of the orkut main page to testify this fact).

I am guessing that even the "loading..." part is also invisible; it is made visible via means of scripts which execute once this basic data viz mentioned above is loaded. Of course there are some complex google javascripting involved here. Now as the "loading..." placeholder is visible, it initiates a series of call (simultaneously may be) to many google web services (in this case orkut application programming interfaces aka orkut apis) to fetch social data. This data can be suitable formatted in JSON or XML which is then again processed by the javascript on the page, and routed to the appropriate place holders. The net effect of this is visible content.

It is not difficult locating where the javascript on the page is...the scripts are not indented to be readable by humans readily. There is a particular way of writing your javascript, wherein you minimize the unnecessary spaces between two statements, and between the expressions. This process is called minification. It serves 3 purposes. One, it compresses the page size. Two, is your browsers are able to parse the javascript better and faster, as there are no spaces, and three, well, the obvious, to make it 'not easily readable'.

So you might be wondering how does ajax figure in all of this? Ajax is the technology via which the orkut main page makes simultaneous calls to the orkut apis to fetch social data.

So how does security actually figure in this? How does it incapacitate proxy/anonymous browsing? This is where you need to understand how proxy browsing works and how a normal browser works. And brace yourselves, this might sound too technical.

Usually when a web page is requested by a browser, its source code (html markup) is downloaded. The browser reads the content and renders it accordingly to the user. Internally in the application's memory space there is a data structure which represents the source code of the web page. Why the data structure? That too in the computer's memory? Suppose if there were scripts (like javascript) for e.g. on the web page, and it did some modifications, like say, change the font of a paragraph of text, the browser will "walk" this structure, find out where in the whole data structure this change has to be affected, applies the new formatting rules (in this case changes the font to a different one), re-renders how the page should look. So what the user sees is an unobtrusive change. AJAX works like how normal javascript should, except it is able to change the above mentioned data structure with data it has fetched asynchronously via the internet. But what happens to the initial source code which was downloaded by the browser? It doesn't change.

Proxy browsing involves a browser program which runs on the web server. Since its a web application it has no user interface to be exact. It doesn't need one. All it does is that it downloads data (ie the markup) from a different web server, and relays that content back to the person who is trying to anonymously browse. There is no execution of javascript here. Hence what is initially downloaded is simply relayed. There are more complex programs which scan the contents, parse the hyperlinks, etc, so when you click on a link on the proxied web page the navigation request is routed via the proxy server it self, and not to the actual server. The advantage to proxy browsing is that you are not compromising on your location to the target web site. The disadvantage it none can be trusted. Proxy browsing is not safe. You are compromising your account credentials to a different server.

I won't say proxy browsing can be obviated completely. It is still very possible. But its a hell lotta work. Sometimes it better people simply enjoy the site rather than hacking it.

Wednesday, April 7, 2010

ubuntu: starting your favourite word program from the run dialog

This can in fact be done on most linux distros. Most machines will come with a default office suite called Open Office. But starting up this word processor program isn't as simple as it is on windows where you can simply type in a command in the run dialog to start the program!!!

But fortunately, this is something a little shell scripting, and symbolic linking can fix.

I simply create a shell script ( to do the necessary starting up of my word processor program. The command to startup Open Office's Word Processor program we've to simply type:
ooffice -writer

You could append the above command with a word document you already have on your file system; so it will open the document as the application loads.

Below is how the script looks like:
if [ $1 ]; then
ooffice -writer $1
ooffice -writer

You should probably save this file in your /usr/bin path. Now give necessary execute permissions for the above script file.
chmod +x

Now if you type in shell, your application should show up. Now simply create a symbolic link to it and store it in the same path above.
ln -s writer

Now if you simply type writer in shell or in the run dialog your word processor program should startup.

Happy ubuntuing...

Note: most of the above command should be run as root

Monday, February 15, 2010

list/array processing in sql server 2000

Remember, this is just another technique. The other techniques have their own pros and cons depending on how they are implemented, and the scenarios they are designed to solve. But most of the other techniques I know never discuss how you can do such processing via an application which connects to the database. But the idea ain't something new.

This approach involves creating two things: an extra table where you need to store the unique ids of items (may be order id, or user id, etc) your are trying to process. And a stored procedure to do your lengthy data retrieval. By lengthy data retrieval I mean the sql query used to fetch a final report/data may be huge that you'd find it cumbersome to include it in your application's code.

The trick is in utilizing your connection's unique id. Observe the below t-sql statements:

TrainerID int,
SPID int


INSERT INTO TrainerList (SPID, TrainerID)
SELECT @@SPID, '25364';




/* Doing a simple retrieval operation */

SELECT * FROM TrainerSessions



We make use of @@SPID variable. In the application we generate an insert statement like the one I've shown above and execute it. Then we execute the stored procedure. @@SPID value will be unique for a connection. We simply execute the insert statements and then the stored procedure in the same connection.

This might not help in every scenario. If you have a lot of items to process, and you want to avoid passing csv as argument to your stored procedures this is a viable alternative.

Sunday, January 17, 2010

Mourning winxp & Getting along with ubuntu 8.10

My windows xp os is FUBAR-ed because of the Windows Genuine Authentication Program. I wonder why it happened so late though? Got my pc somewhere in 2007. A year passed. In an attempt to understand how partioning works, I formatted my whole machine by reinstalling os. And somewhere around that time I had successfully installed ubuntu 8.10 onto a second hard-disk I had. But my bios was configured to boot xp which was in the 1st hard disk. I think it was that reformatting which kind of delayed/offset the chaos to happen at a later date viz a few weeks back.

Now I've set my bios to boot ubuntu. It aint all that a great os, but I am slowly getting used to loving it. After much googling I've successfully installed tweetdeck on my gnome desktop. I was wondering how to launch it from the run application dialog today. It aint all that complicated as I thought it was...

Most of your executables are soft linked or symbolically linked. Its just like shortcuts in windows. All you have to do is place a link in one such place your Run Application dialog will look into. That one such place is /usr/bin. So to place a link there you need to navigate to that folder and create the link there.

$ cd /usr/bin
$ ls -s [path-to-ur-fav-program] [shortcut-name]

Now if you invoke the run application dialog (using Alt + F2 viz similar to run command in windows) and type your [shortcut-name], you can run your fav program.

Happy ubuntuing...