Posts

Stunned by STUN using Python and Java.

Over the last two days I have been researching on P2P yet again :). Last time I was working on it I got stung by STUN . I just could not make head and tail of the RFC and I was unable to find any usable implementation online. Rather I never really searched hard enough and I left that project mid way. This time around I found a really clean implementation of STUN in python another in C# and one in Java. Sure found a lot of implementation and its quite simple unless you are on a symmetric NAT setup and that is where things start getting trickier. Also realized how simple or difficult it is to create a simple P2P application. Also read up stuff on STUNT, the extra T is for TCP. STUN works on UDP and not TCP.

Activate GPRS on Airtel Postpaid connection

This one works for Airtel Punjab not sure if it works for other states and territories. SMS GPRS299 to 121 and it will be activated in 6 hours. To deactivate it SMS DGRPS299 to 121 . To get the settings SMS MO to 52567 . The customer care exective I talked to also told me that if I deactivate it in 2-3 days I will just be charged for those days though I am not sure if was right about that.

Killing two birds with one stone

The thing I am working on today is more like killing 5 birds with one stone. Like I wrote last week I started with Python , but due to the work load over the last two weeks I could not do much. This Friday I got an invitation to Google App Engine and the only language they support as of now is Python. This in a way pushed me into learning python. Last month I had written about a bridge for Facebook and Open Social applications. With many new things I devised a clever plan I have started off with a facebook application for the open social platform in python using the google app engine. That is 5 technologies covered in one single shot. I started with PyFacebook but, soon realized that the library urlib2 uses sockets and PyFacebook won't work for me. I could start with a new library or hack PyFacebook and since I am an expert in Python (with less than 2 days of experience) I resorted to hacking the PyFacebook library. I have never really programed in Python and the fact that the li...

Keeping up with the fitness regime

After finally deciding to do something about by increasing waistline I have been able to control a lot and in the last 3 months have got back into shape. Thought I am a long way from reaching my goal I am a lot better than I was just a few months back. I had no idea I would be able to get things under control and surprisingly I am surprised at my devotion. I started by walking everyday for a good 3-4 Kms and recently I joined the gym. I have a lot more energy and stamina. The best part is that I wake up at 5:30 in the morning and thats something I have been trying to achieve for a while. The last week was really hectic in every possible sense with just a few hours of sleep every night. I was trying to handle so many diverse things at once. I finally started learning how to drive :), I somehow could never get the reason to learn driving but I guess its time. Most of my day is jam packed and I like it. I hardly have time to do anything else. Thought the only problem I have faced is that ...

Can cellphones cause headaches?

Ever weekend whenever I would woke up I normally had a headache and I could not see any reason why I had it. This would normally stay with me for nearly the complete day and inadvertently my weekend would end up sleeping. The funny thing was that this never seemed to happen to me on weekdays. The only reason I could see was that I slept late on weekends so possibly my sleeping for a longer time was 'causing it. Well coming back to the cellphone, I normally had it right next to my pillow when I sleep. I used it as an alarm and to see the time at night. About two weeks back on the weekend I forgot to keep the phone next to me and also for some reason I had switched off the WiFi in my room. The next morning I woke up fresh and had no headache what so ever even thought I had slept till late. I tried the same thing next day and I was again fresh this time around, with no signs of a headache. On Friday night this weekend I was expecting a call and I kept the phone next to my pillow. I ne...

Getting down and dirty with Python

I have spent the better part of this weekend getting down and dirty with python . Also I found the GUI library I was looking for in venster . Last night I was reading about the different GUI GUI development options available for Python. There are the the usual libraries like wxPython, GTK, QT, Tk, FLTK, Swing, SWT, Swing and .net forms. All of them are good but the main problem with most of them is that they are huge and the others which are small don't look or feel native. Out of all of them I like SWT but then again if I am going to use SWT then why not just use Java. Venster looks like a very good project but seems to be dead for the last 4 years and if I can get some time I might want to work on it. The library is tiny and does not add much weight to the over all deployment package. But then again its still my second day and I've barely scratched the surface. The tutorial I was using was a little sketchy about classes in python so I still need another reference for classe...

Finally learning Python

I've tried my hand with Python a couple of time but it could never really hold my interest. But over the last few years its matured a lot and its available on multiple platforms and also one of the only languages which seems to have a binding to nearly every new library that comes out. Lets see how far I go on this adventure. And for how long python will be able to hold my interest, will I go beyond the basic "hello world" programs.

Generating regular expression at runtime in javascript

I have never been good with regular expressions. I normally search for the regular expressions online and use it, I can never seem to get them into my brains. Lately I've been working on things where I've had to generate a regular expression at runtime. It is a trivial thing but I was unable to find it when I look for it. So in case you are looking for generating a regular expression at runtime this code snippet might help you out. var data = "This is a string and I want to replace all the a's"; var re = new RegExp("a", "ig"); alert(data.replace(re, "m")); This post is more like a reminder for me.

This time I can get Nineteen Million Five Hundred Thousand United State Dollars

As if the previous million dollars wasn't enough I have another 19 Million waiting for me. Well this mail landed in my Inbox and if I wasted 5 minutes going through it I normally put it on my blog as a reminder of wasting time, also this mail is funny with facts and fiction mixed together. Only read it if you have a lots of free time. Good Day, Thank you very much for your response, and your interest in this transaction. Let me start by introducing myself again.I am Mr. PATRICK K.W.CHAN I work with the Hang Seng Bank Ltd.Before the U.S and Iraqi war our client Colonel Sadiq Uday who was with the Iraqi forces and also businessman, made a numbered fixed deposit for 18 calendar months, with a value of Nineteen million Five Hundred Thousand United State Dollars only in my branch.Upon maturity several notices was sent to him, even during the war which began in 2003. Again after the war another notification was sent and still no response came from him. We later found out that the Colone...

Open Social Container and my first Facebook Application

Its the last day of my easter vacations and five days of good work. I had initially planned to go out somewhere for these holidays but as nothing really worked out I ended up staying at home. So instead of wasting my time sleeping and watching TV (which I still ended up doing) I thought of finishing my ever growing list of personal projects. But instead of starting work on one of the pending projects I ended up starting yet another project. I searched around for an open social container and I found one but it was in Java and since I don't have any server which would allow me to host the project I ended up working on my own open social container. Well I worked on it for two days and it at least works with most of my samples I created for open social and also a few other gadgets. As of now its completely in JavaScript so in terms of security there is none to speak of, but by the end of it I did make a container and learned quite a lot. The code still looks way to hacked up to put on...

Are you smarter than a 5th Grader?

Image
After writing about the Indian version of the show I took the test on the fox network site. And I have the certificate to prove it ;). Thought I don't live in New York and I took the test in 2008 and not 2007. Apart from those mistakes I am so much smarter than a 5th grader, or am I? Just made me realize how little I know or care about social studies and history. I always ended up taking questions about science and maths. The two three times I choose social studies or history I ended up giving the wrong answer. The concept of the show is nice and would go well with the Indian audience who seem to be having an overdose of the reality tv shows, and one more would not hurt.

Kya aap panchvi paas se tej hai?

UPDATE: You can play the game online at http://www.fox.com/areyousmarter/features/ . I played it and here are my results . कया आप पांचवी पास से तेज हैं? / Kya aap panchvi paas se tej hai? is an Indian version of Are You Smarter than a 5th Grader? and would be hosted by Shahrukh Khan. Now I am not really talking about how great the program is going to be or going to harp about the host. I just like the clever marketing technique by the company developing the show in India. In most states in India lottery is illegal, but paying money using premium SMS is not. These days they have this clever little advert on the Star Network channels which asks users to SMS the answer to a simple question to get on the program. Now the adverts been playing for a month with a new question everyday. And they entice you with a million dollar prize. You need to send the SMS on a premium number, so its almost like an underground lottery with dreams of a million dollars. Even if they get a million SMS's ...

A better alternative to window.onload

This code can be used as a better alternative to window.onload . We use main as the function from where the execution begins. We also have a __app_started varible which tracks if main has been called so that it is not called more than once. Basically by this technique main gets called the moment body has been completed. If you use window.onload it waits till all the images and CSS have been loaded and in most case that can really be a while. var __app_started = false; if(document.addEventListener) document.addEventListener("DOMContentLoaded", main, false); else { document.write("<scr" + "ipt id=__ie_onload defer src=javascript:void(0)><\/scri" + "pt>"); var script = document.getElementById("__ie" + "_onlo" + "ad"); script.onreadystatechange = function() { if(this.readyState == "complete") main(); } } window.onload = main; // If all else fails function main() { ...

#include or include a file in javascript at runtime

I had written about require or #include in javascript and it works but sometimes you don't want it to be added it using DOM. This function uses DOM incase the body has been loaded or uses document.write to load the file. function $include(url) { if(document.body) { var script = document.createElement("script"); var head = document.getElementsByTagName('head').item(0); script.src = fileUrl; head.appendChild(script); } else document.write("<script type='text/javascript' src='" + url + "' ></sc" + "ript>"); } If you look carefully the name of the function is $include . It just makes it stand out other than that you could name it whatever you want. This just makes the code really clean and no more messy html files with 10 script tags to load all the files. It just makes life simpler if you have too many script files to load.

"Hello World" ruby and python on dreamhost

After having dropped all my plans for a vacation I have nothing better to do so I started with the stupid idea of trying to run different languages on my dreamhost account. Let me start with ruby first. Open up your favorite editor and copy paste the code below. Save it as testruby.cgi on your server. Change the permissions for that file to chmod 755 testruby.cgi . #!/usr/bin/env ruby require "cgi" cgi = CGI.new("html3") cgi.out("text/plain"){"Hello World"} If all goes well you should see hello world. I tested it here . Once you've tested it out you know that your account supports ruby. Now moving on to python. Copy paste the code below to a file testpython.py and change the permissions for that file to chmod 755 testpython.py . #!/usr/bin/env python import cgi field = cgi.FieldStorage() print "Content-Type: text/plain\n\n" print 'Hello, world!\n' If all goes well you should see hello world. Here is my python hello world...

Let me decide what WFM

Its really rare to see anyone who can actually think out of the box without their fixed set of ideas. If a person knows a "x" language or technology making that person think beyond it seems like an effort. Specially when you look at technology of any kind we have the language nazi's who will make every effort to protect their language as if they would die without it. So lets take an example of a Java programmer programming in JavaScript he/she will try and make sure that JavaScript works and feels like Java. There is no harm in it as long as that is not being preached as the only way of working. I tend to do that a lot (program like "x" language in "y") but I will never say that this is the only way of doing it. It just WFM , and I tend to learn from looking at other peoples code and changing my practice whenever I see something that I feel is better. Then we have the Mac, Linux and till a certain point Microsoft fanatics. They seem to have their fixed...

There is always so much to learn

After every few years I feel I know everything there is to know but along comes something new and my myth is shattered and I come back down to earth. In most cases its not even something new just something I've never bothered to look but something which actually changes my perception. Most of the times I work on multiple projects at a time and in the end the result seems to be zero. There is always that one thing that seems to hold back the complete project. Be it something small or something really big. But there is something bigger than these projects that I seem to get out of these personal projects and that thing is experience. I end up learning things that I normally think I know or seem too trivial to learn. This weekend I was working on CSS and trying to get a native look and feel on a web page. I searched all over the net. But in the end the whole information was sketchy at best. I ended up learning a lot and finally figured out how little I knew about the topic and how li...

Just an ordinary day

Image
Today began as just another day and somehow is ending that way. Nothing exciting or interesting, still have my TODO list which never seems to get completed. Just hoping that tomorrow might turn out to be a little more interesting. The last two weeks have been hectic in every possible sense. First was my birthday which is normally a non event but this year for a change went out with friends and had a lot of fun. The photograph was clicked at the lake which I went last week. Have also been busy at work with tons of work to complete and somehow did complete it by the end of the week.

Birthday blues and all that crap

Wow its the third post in the series . I am always grumpy on my birthday. So for a change this year I want to be optimistic and hope for the best in the coming year. I have had some good and different experiences this year. The one good thing that I realized is that I always seem to underestimate my self in a certain area. And over the last few months I have been proven wrong and that is one good thing I have learned. In terms of programing I am leaning towards Java and have written or at least started posting links of whatever I am searching for these days. That should give you some idea of what I have in mind and what I could be working on these days. On the other hand I have also been working on a project and wanted to launch it today on my birthday but I guess it will have to wait for another few days before I can launch it. Its just a little over midnight and have to wake up early and probably go out for a walk. At least I want to try to go out but not sure how well it will work o...

Thank the lazy people for the progress.

Today a friend sent me a SMS, a quote by Henry Ford , " Progress is not made by early risers or hard workers, but by LAZY people, trying to find easier ways to do the same. " That just makes a lot of sense. Most of the inventions we see today are built out of necessity. Which in most cases is about doing the same job in a more efficient way.