Tuesday 27 December 2011

My thoughts on Steve Jobs, and life in general

    After reading about Steve Jobs in his biography by Walter Isaacson, I am really captivated and touched by his story. To me, he is like my favorite fictional character, Sherlock Holmes, who is a genius at solving crimes, yet as great as the man he is, he is a drug addict, at one moment he is doing something unthinkable that amazes us, yet at another moment he can be just like one of those out on the street, wasting his life away.


    What is more important is that, thru reading the book, I reminded myself that most of the time we, living in a reality full of faults and problems, so much so that we tend to forget, that God has given us unlimited powers, to achieve whatever possible or impossible, limited only by our dreams and believes. It doesn't take an angel, or luck to succeed. It is our visions, our will, our persistence in wanting to succeed, that can bring us to achieve and be labelled a 'success' in the society.


    We have but only one life, ignoring the fact that we can be reborn, which is something that is not a totally proven fact, and not something everyone on earth believes in. And if we do not take this one opportunity to 'make a dent to the universe', it is not just a loss to ourself. It is a loss to mankind in general as well. We who are at least given a chance to try to prove what we can be. Many others do not have the opportunity ... those sperms who have lost their race to the ovum, aborted babies, those who passed away very young for various reasons. That we, given the opportunity, can consider that as a great gift and achievement in itself.


    At this point of time, we can be lost, we can be useless, or even a failure, but that does not mean we do not have a chance to prove to the world and touch the live of others, for, many successful person endure more defeat and made even bigger mistakes compared to us. The Oracle of Omaha, Warren Buffett did not earn his name being right all the time. He earned it, as he rightfully say so, because he made a few right decisions that made him way ahead of the pack.


    In the end, mistakes can be forgiven, wrong decisions can be corrected and wounds can be healed. But if we give up, lose faith and are afraid to make decisions, that will be the biggest mistake of all. For, the fear in us should not be the fear that the sun is not rising tomorrow, or we might not live another day, or we might fail. The real fear is that we ourselves have lost hope and closed the door that leads to the true feelings in our heart, so much so that, the world might have lost a potential hero, without anybody knowing it. Let's not give up and continue to do what we believe in, as success can be just around the corner, much more closer than we think it is. We get out of life what we put into it.

Sunday 16 October 2011

My thoughts on ORM

I used to be fanatical about performance. Every database access must be raw SQL, or smart system generated SQL which are optimized so that I do not have to worry about performance, or at the very least, I know how to tweak the SQL to solve performance issues.

However, the buzz of ORM (Object-Relational Mapping) made me explore a few options such as JDO and JPA (I was using datanucleus implementation at one time as that is what Google AppEngine uses). At first I was quite frustrated due to the difficulties I faced to setup correctly in the initial stages. But after a while, I got more comfortable.

Once, I remember developing a Data Synchronization System early Year 2010, which is a JSP + JDO solution that synchronizes data between two databases based on preset rules (defined in JSON, which is in my universe, the king of complex data structures). I had to port this system to MySQL from Microsoft SQL Server, and my limited knowledge of MySQL really got me worried about how difficult this would be. However, it turns out to be just a snap. Generate the DDL (Data Definition Language), to create the database schema, and that's it. I might face a problem or two, which were so minor I cannot remember them, but all I know is, it is magical. The masking of Database tables as Classes and SQL in some different query language, it makes things so transparent. Not only did I not notice any performance impact, but not needing to maintain separate SQLs or DDLs means I do not have to worry about more modifications in the future if I am to add support for, say PostgreSQL. Amazing!

Fast forward to today, as I am playing with Django Framework for Python, I found that ORM are not only abstractions for database independence, but they actually mean you can play around with code more, to put the validation logic into the classes, as well as modifying them to your heart's content, which feels so much more natural than changing the database design, as well as changing the SQL separately in a program source code. Below is the source code for a simple model, enjoy!


class ServerActionHandler(basemodel.CreateUpdateInfo):
    nameRegEx = re.compile(r'[a-zA-Z][a-zA-Z0-9\.]+',re.DOTALL)
    name = models.CharField(max_length=128,unique=True)
    state = models.CharField(max_length=1,choices=basemodel.DEFAULT_STATE_CHOICES)
    method = models.CharField(max_length=256)
    def clean(self):
        if not self.__class__.nameRegEx.match(self.name):
            raise ValidationError('ServerAction name must start with an alphabet and can only contain alphanumeric and dot (.).')
    def __str__(self):
        return self.name

Friday 12 August 2011

SubEthaSMTP: Store email as files before sending out

I have written a simple handler for SubEthaSMTP that will save emails to specific folders before sending them out. First the main function to setup stuff (SMTPServer.java)

You can download it from here. (Note: There are three source class in there, with their Class Name properly highlighted).

What it does is to start an SMTP server (standard SMTP Port) in the workstation/server you are running it on.

You will need to configure SMTPMessageHandlerFactory to set the appropriate smtp host, smtp port, smtp user and smtp password to send the email to.

Whenever a mail is received, it will write the contents of the mail in folder: outbox/{fromemailaddr}/{date}/{time}

It will work for normal mail (HTML/plain) and mail with attachments, but not message/rfc822 type.

Also, because I am not able to read BCC headers from the mail received via SMTP, instead of processing the TO, CC, and BCC in the mail content, I will send out the mail to everyone separately, putting them in the TO field for each email sent.

Please help to test out and comment accordingly. Thanks.