Posts

Showing posts from March, 2008

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 clas

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 Colo

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 o

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'

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 he

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 fix

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 l

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.