A javascript decision on the use of jQuery on PHP WordPress PHP (JSON, Raw HTML or Javascript)

Recently, I have been focusing my programming efforts on mainly Poise.sg. Poise.Sg is built using WordPress as the backbone, the choice of which I stated in a previous article (choice of platform for a new concept). To date, my choice using wordpress has proven to be a sound one. I have been able to achieve the 3 following objects through the use of wordpress

  • Ensuring conformity in look and feel
  • Accomodate multiple different layouts
  • Maintain role based access control to specific views
  • Incorporating new external Javascript and PHP libraries into WordPress as a plugin

Now as the project progresses, I am faced with a software architectural issue. This has to do with the way the jQuery library is ultilized. Due to the fact Poise.Sg is a heavily Ajaxed system, there are many instances of the client browser doing an off the screen call back to the server via an Ajax Post method.

Due to the flexibility of the jQuery Library, there are three different methods available I could handle data transfer between the server and the client browser. They are

  1. To return raw HTML from the server and append the parent HTML DOM node via the method
    jQuery.post(‘server.php’, {data:”something”}, function(data){

    //data is a raw HTML
    jQuery(“#parentNodeID”).append(data);

    })

  2. To return javascript, to be executed in the function that will handle the response data
    jQuery.post(‘server.php’, {data:”something”}, function(data){

    //data is a series of javascript
    eval(data);

    })

  3. To JSON object to be interated in the function that will handle the response data
    jQuery.getJSON(‘server.php’, {data:”something”}, function(data){

    //data is JSON Object and can be iterated through with a for loop
    jQuery(data).each(function(index){

    var value = jQuery(this).val()

    })

    })

After having tried each method, I have come to realize there are Pros and Cons to each of the three methods.

Method 1 was is an easy and straightforward method to employ. However, it results in data and presentation being mixed in the response. A change presentation layout would translate into the need to go back and edit the codes sitting in the server end. It does not cater for the eventual possibility of data source reuse due to the tight coupling between data and presentation. The repercussion is the need to create a different ajax server method each time a server call needs to be made from a different view from the client end.

Method 2 is a somewhat less straightforward method to employ as compared to method one. It is a doubly bad option. Not only does it face the none data source reusability issue described in method 1, it also face the possibility of PHP introduced javascript error, in the event whereby PHP inserts invalid characters into the javascript string or integer location.

Method 3 does allow for flexible reuser of data source, since the styling is handled at the client side Javascript level, while the server side is only responsible for generating valid JSON responses. This means multiple different views with drastically different layouts could share the use of the same data source. The only downside to this method is similar to the PHP introduced error as described in the method 2. The main difference is that instead of PHP introducing invalid characters to disrupt the javascripting, it introduces invalid characters in the value JSON fields thereby rendering the JSON response invalid.

For the sake of system extensibility on Poise.sg, I opted for method 3. The down side is that while the content will be mainly user generated as similar to ThingsToDoSingapore.com, there will be instances when the result will not be displayed as generated by the user due to their use of invalid characters.

These are my thoughts for today. Being the workaholic as I am, I have over the course of a few hours today (a Sunday) finished the search form on Poise.sg and will now take a break till tomorrow.

FUCK THE 5Cs!!! My personal reflections on the film “Singapore Dreaming”

After sourcing for hours, I managed to acquire the viewing of this movie “Singapore Dreaming” on Tudou.com. To me the whole notion of the value system portrayed in the movie seemed at once familiar and strange. I wonder how much of what is portrayed in the movie is actually true to real life. I do know from hearsay that Singaporeans are obsessed with the 5Cs, car, condominium, cash, credit card and country card. However if the actual level in society for such an obsession is indeed accurately in portrayed in the movie, this would be a very dangerous act on a social level as well as a personal level.

Such a level of obsession for  superficial appearance imposes not only undue stress on the self but also on those immediate relations around the self. Also this obsession, if examined under the framework of wealth as proposed by Robert Kiyosaki, is a big no, no. The choice of expending resources, in this case money, on items to appear wealthy such as the 5Cs, instead of on investments in systems that would potentially generate an incoming cash flow, is a fool’s decision. The ugly situation is further compounded by the attempt to achieved a fool’s decision through borrowed money. In the cash flow sense, it is getting further in debt with no possibilities of any potential cash flow gains in the long run.

In my opinion this obsession with the 5Cs is as much an adaptation of the American dream, as it is an inherent tendency amongst the Han Chinese races from the southern coastal cities of China (the origins of the current day Chinese immigrants in Singapore).

As observed, the American dream is a illusion that is both unsustainable on a national level as well as on a global level in the long run. America is currently in debt by trillions of dollars. America currently ranks number 2 in the list of carbon emitting countries worldwide, recently overtook by China. International conservation organizations have all come to the consensus that consequences will be dire in global warming progresses by another 2 degrees.

Quoted from Achim Steiner, Director General of the World Conservation Union “The Kyoto Protocol was an important milestone, but it is simply not enough. This conference must find new ways to achieve more serious emissions reductions after 2012 when the Kyoto Protocol expires.” 2012 is less than 365 days away. Even Mr Lee Kwan Yew himself had attested against this excessive materialism in his interview in his interview (see from section 1.05seconds of this video on YouTube)

My personal opinion would be for fanatics of the 5C dream or its variants to relent and desist, opt instead for a more sustainable life style and value system, if not one that is worldly ascetic. Such an alternative value system and philosophy towards life will restore the world to its natural balance over time as well as have the human soul centered. Such might in fact free the mind of distractions thus grant the person freedom to pursue his calling. Those who are religious might see it as a return to God, or the continued pursuit of Nirvana. Those who are free thinkers or agnostics will see this as living a simple and uncomplicated life. Those who are artist with their heads in the air, or air in their heads will see this a pursuing the bohemian lifestyle. Whichever the case choose a path.

Nevertheless, I think my worries are ground, already the signs of the forth coming Age of Aquarius are manifesting themselves. Fingers crossed, December 21, 2012, might just be the day of our salvation or the end of the world as we know it.

On the conceptualization of Poise.sg

Thus far functions that allow for the creation of accounts for the three user roles have been created. People coming to Poise.sg will be able to login to Poise.sg using their facebook connect details and create an account type of their choice. There are basically 3 defined account types.

  • Models & Talents (Male & Female)
  • Agents
  • Media Houses / Production Houses / Advertising firms / PR firms

Functions accessible by Models & Talents are well defined.

Thus far there is a lack of differentiation between the user roles of Agents and Media Houses system wise. There is almost no difference between these two roles with the exception that when media houses attempt to contact models directly, the notification gets routed to their agents as well as the models.

This is the main issue of concern which I have been pondering over these past few days. I will need to identify the key value an agent contributes to this process other than just being the middle man whose sole purpose is to pass information along the channel. From a superficial perspective an agent is one that simply contributes by passing information along. However in this new system that will be known as Poise.sg, information will be made transparent, thus eroding the role of agents as information transferrers. As such an agent might in fact come to see Poise.sg as a threat to their role in the supply chain, thus resist the adoption of the use of the Poise platform.

However from an industrial perspective, why is it that Media Houses / Production Houses / Advertising firms / PR firms choose to engage the agents on some occasions and by pass the very same agents during other occasions? There must indeed be a defining difference between these two decision outcomes, therein lies the true value of agents.

Ideally when Poise.sg is eventually launched, this platform should safeguard the interest of all three parties. The only way I could envision this to be possible would be to ascertain the core value adds these three roles contribute to the supply chain and enhance the effectiveness of their roles by providing them with supporting software functions. Thus far I have approached 3 modelling agencies of which I am closely acquainted with for feedbacks and insights into this issue.

  1. Esther from Ezen Models
  2. Justin from Style House
  3. Kirk from Perspective Models

Hopefully the insights, I gain from this round of interviews would lead me to the solution of this wall I hit.

Choice of platform for a new concept

After some delays, I finally started work programmically on this new concept I have in mind. The first step was to choose how to start.

I have 3 choices in front of me:

  • Start by creating a platform from scratch as I did for ThingsToDoSingapore.com
  • Start by using the Joomla Content Management System as I did for Name1price.com
  • Start by using the wordpress Content Management System as I did for WinterInVenice and PixieMagicalland.

The following are the basis on which I made my decision:

  • Conformity of look and feel across pages
  • Fast loading
  • Ease of programmability
  • Flexible deployment of plugins
  • Ability to leverage on existing codes

The main reason as to why I choose WordPress over building one from scratch is because it allowed me to ensure conformity of look and feel across pages. It does however take away somewhat from the ease of programmability department, since I will need to program in the functionality via the hookup system that is the inherent core of wordpress

The framework of Joomla is somewhat more rigid as compared to wordpress. It scores even lower in the ease of programmability department. It scores the same in the conformity of look and feel department. The main downside of Joomla as compared to wordpress is that each page is limited to just one main component and multiple modules. As this concept of mine is still in its infant stage, I will require flexibility in that department as well. A hookup system will thus fit my requirements nicely.

All said I will now start working on the initial landing page which allows for registration of 3 different types of accounts.

Techniques for data migration across hosting servers

Just these few days I had the opportunity to handle the migration of data for a few web sites. Some were running on the fat cow server. Others were running on the host hi server. All of them were to be ported over to the Vodien server.

The fatcow server has over the past few months proved to be a disappointment, while the hosthi server has all along been a disappointment. Often do I get complains from customers that there web servers are either not loading or their sub domains are showing errors. Come next year I will allow both the fatcow and hosthi accounts to expire. I guess the moral of the story is that if some service providers promise unlimited something, there must seriously be a limited something else somewhere.

While migration of files across servers are easy, the migration of databases and email accounts are somewhat more complicated.

Large MySQL Database migration process

There is an instance where I had to migrated a database that is 100mb in size. To do so via the standard database admin panel called the phpmyadmin would have took forever. Hence I wrote a php script that to fetch a file via a handle

$fp = fopen(“databasedata.sql”, “r+”);

instead of reading in the whole file at one shot.

file_get_contents(“databasedata.sql”);

The latter method would have used up all the allocated resources in a normal php installation unless of course I went ahead and changed the configuration in my php.ini file. However this latter method is not at all a very elegant method to handle the task.

To further expound  on the prior method, I coded the script to parse the $fp  stream line by line and consolidate them into one big line everytime the latest line does not end with the string chunk  “;\r\n”. In the event this chunk was detected, I will that this consolidated line and execute them to the database.

while (!feof($fp) && $counter<100 ) {
$query .=”\r\n”.trim(fgets($fp));
if(substr($query, -1) ==”;”){
//echo “query = “.$query;
connect_query($query);
$query = “”;
//$name = fgets(STDIN);
}
}

while (!feof($fp) && $counter<100 ) {

$query .=”\r\n”.trim(fgets($fp));

if(substr($query, -1) ==”;”){

execute_query($query);

$query = “”;

}

}

Lastly to free up unnecessary resources, I closed the stream $fp which I did not need to use anymore.

fclose($fp);

var_dump($myvar);

Thus the problem of database migration is solved easily with minimal throughput required on the web server. Of course, if I had configured my php installation, it is possible to run it from the command line.
Email Account Migration from webmail to google mail server.
This is another tricky situation I had to resolve. Apparently one of my clients used her webmail account rather extensively. In her webmail account she created various folders in which to store her emails. She wants all her mails migrated over to the new Google Mail server and at the same time have her email folder structure preserved.
What I did to fulfill this requirement was to create an imap stream to the server the original webmail account lies on to retrieve all the folders. Since I have not configurated her webmail to use any security ticket I added the line novalidate-cert. This line is very important and I noticed quite a lot of developers faced this problem when try to access their webmail via the use of PHP scripting.
set_time_limit (600000);
$mbox = imap_open(“{imap.yourwebhosting.com:143/novalidate-cert}”, “userid@somedomainname.com”, “password”);
$folders = imap_listmailbox($mbox, “{yourwebhosting.com:143}”, “*”);
For each respective folders that exist, I created an imap stream call to retrieve all her emails. For each respective email, I retrieved all the header information, subject and email content and reconstructed an email packet.
Next due to the fact that the google mail server has been configured to block all emails from sources with a domain name,  ip address mismatch, I had to create another email account (Account B) somewhere else so that I could send my mails to from my local web server. There after I configured the new google email account to retrieve those mails from Account B.
This in a nut shell is how I migrated both the database and the email accounts.

My constant failures in my pursuit of philosophy

Each morning I wake up with gratitude knowing that I have been once again presented with the gift of life for another day. Each day I strive along my path. Each night I sit in regret knowing I have once again failed.

Until the day comes when I could live each and every second of my life unstained by personal egotism, all I have done along the pursuit of my path will amount to nothing. Until that day comes, each and every of my action will translate immediately into failure at the very moment of their manifestation. Until that day comes, I can only live in gratitude that I have been once again presented with the gift of life and regret that I am unworthy of that gift.

When that day comes, my works and efforts will no longer be a manifestation of personal egotism and vanity, something I have personally come to despised and look upon with regret. When that day comes, my works will be a tribute in its purest sense unstained by my failings due to the animal within. When that day comes, I will truly see myself as a man and not a abomination of nature that is half man and half animal.

Testimonials from a dysfunctional

I saw a text message notification a few days ago. It was from Rodney, a Christian missionary from America currently in his 60s. I got to know him 4 years ago in Melaka. I was on my sabbatical then. My sabbatical was a necessity. I had delved too deeply into the night scene of Singapore prior to that so much so that I felt spiritually and emotionally drained by the superficially, decandence and hopelessness I witness around me. It was ironical how my devotion to bring about success in the tasks set before me brings me recognition from my peers while at the same time proportionally amplifying my sense of self loathe quietly hidden away from the sight of all around. This self loathing which over time grows into a deep hatred for self, a hatred that would most likely have resulted in suicide had I not drop everything material gained thus far and left. In retrospection doing a pyschoanalysis of self, it is tragic to see this cycle repeated over and over again in this life of mine, to have success grow proportinately with self-loathing.

I was in the late stage of this self-destructive cycle of mine when we met in Melaka. He was leading a band of Christian musicians then. It was strange that he noticed and approached me of all the people he saw walking in the streets of quiet town Melaka. We talked late into the night then and I travelled with them for another 3 days before leaving the Christian band to proceed further up north on my own journey which eventually lead me into the hearts of the Golden Triangle where the militias would hold in their hands a sub machine guns while collecting their bribes from you. I guess one must really have a death wish to venture into such places. Maybe I did, maybe I didn’t. Knows to who? What I did know was the urge to just keep pursing the direction of North. It was only when I finally found peace in that abandoned war torn church in Mong La did I decided it was time to head home.

It has been quite a while since me and Rodney last time met. If I did not remember wrongly it was more than 2 years ago. This time we met on Friday morning at Plaza Singapore for breakfast. Rodney hasn’t changed much, he was as jolly looking as ever. I was told over breakfast he have had for himself 2 operations since our last meeting. He proclaimed that while he was still young at heart, he was physically no longer that young anymore.

Unknowingly Rodney stirred our conversation that morning towards the clash of values. He related that one of his protege a student from Malaysia who recently went over to US for studies got involved with a Swedish girl who was also a student. He talked about how strange it was to the Swedish girl his boyfriend had to send money home every month ever since he graduated to his parents, when parents and off springs live somewhat financially independent lives in the west. This topic on value clashes did struck a chord. However in my opinion, what he described was a relatively simple two polarity scenario where all one had to do was to find a position between the stated two extremes as his own. What I have in mind is a multi polarity issue which to date I have yet found an answer to. Things would have been simple if things could be sorted so easily into right and wrong, good and evil. However the current situation is such that these values which I hold to be right and good are contradicting each other. Right and wrong does not exist, neither is there good and evil. I do not foresee I will resolve this issue that soon.

Milestones and more milestones

From the statistics shown in Google Analytics, the changes made to the web application thingstodosingapore.com over the past few weeks has thus far had a positive impact on on the length and depth of incoming visits.

  • Average length of stay has increase a 100%, from a pathetic 53 sec beginning of last month to 2 mins and 30 secs
  • bounced rate has  dropped to an average of 6% from the previous 12% beginning of last month

The results could be attributed to the following changes:

  • Migration of web hosting server to Singapore where up to 70% of the visits are coming from, a choice resultant from analysis of data available in Google Analytics, Alexa.com as well as valuable inputs from end users.
  • Ajax auto count of items in each category when visitor scrolls to a new section of the map resulting in preempt of information users could browse through. (A feature adapted from YouTube.com)
  • In the event whereby a visitor arrives in a page other than the main page, the starting category will be set to the one this content belongs to. The pheriperal markers will also be from the currently selected category. This results in increased relevancy in contents presented (A feature adapted from Google.com).
  • The migration from in map content presentation to the use of the Thickbox library. Users can now browse through the current content with more ease and less irritation. This is a choice resultant from the series of usability analysis I conducted.
  • Auto population of Event contents from Facebook.co. This is a feature inspired by Facebook’s newly launched Graph API and the existing Google Map API. The process is made more comprehensive by an ever growing internal dataset of locations specific to Singapore. After months of experience dealing with the Google Map API, I have concluded that while the Google Map Geocoding feature is pretty extensive, it has problems detected locations in the event whereby the location is referred in the local jargon.

Over the past few days, I have had the great opportunity to correspond with a few corporate event organizers and in the process receive some feedbacks. One of the features, resultant of my correspondences, will be the visitor analytics which event organizers will find useful.

Another set of features related to the first set will be the viral feature which I will hope to implement over the next two weeks, it will be somewhat inspired by one of the prototypes we have had the opportunity to build in Silicon Valley during the Techcrunch Hackathon. This second set of feature will be designed to increase foot track to events by organizers happening in Singapore, increase visibility of such events to the general public as well as aid in the process of customer retention.

Considering the fact that Singapore is in the midst of positioning itself as business hub where multiple international conventions will take place, the infrastructure for the online social media support for events is thus far minimal, if not non-existant. This might in fact be a niche that is uncompetited for and in demand.

Not only does ThingsToDoSingapore.com concentrate on providing valuable information to people interested in attending events happening in Singapore, it also complements these events with information on related facilities at nearby premises.

Another thread of work to be done is the android application. I have had the opportunity to bring the HTC desire I recently acquired out for a test run and have identified some issues of concern which I will have to that into consideration when building the Android Application that will allows users to gain access to relevant information on ThingsToDoSingapore.com while on the road. Thus far these are the issues identified:

  1. Content Synchronization vs Bandwidth Lag
  2. Content Synchronization vs Android SqlLite memory size
  3. Content Synchronization vs Battery Life
  4. Content Presentation vs Screen Size
  5. Content Presentation vs Relevance to User Experience

The options available for the Android Application are as follows:

  1. Map
  2. Listing View
  3. Grid View

While the above issues are important, there is a more fundamental underlying area which begs for my attention. I will need to identify the use cases that will be relevant towards the Android Application User experience when exploring Singapore on foot. This presents a difficulty for me at the moment as I have yet gathered a comprehensive set of data, enough at least to determine which features are critical to a Singapore explorer and which are not. The option available for my pursuit at the moment is that I do trial runs using other peoples application to determine the painful spots not covered as yet. However even, the resultant set might be biaised as it due to my personal experiences as Ricky once said. Hopefully this biased could be resolved via the feedbacks gathered from my test users (guinea pigs) after the initial prototype is developed.

The path ahead is still long. There is much to be accomplished.

It runs in the blood

“Sure, no problem, I will do it for free…” thanks to my Chinese upbringing  is one of the usual responses I would give with a smile when asked to do something for free. However to blame is the very same  Chinese upbringing for my omission of the second part of my response “…when I am free and when I feel like it. However if you absolutely must have it, please pay the price then.”

This phrase Alena said a long time ago still etches deeply in my mind ” to be Chinese is be somewhat hypocrite.” We never really do say what we mean or mean what we say but we really do expect the opposite party to understand what we mean and misjudge not the meaning by what we say. Conversation is thus very contextual. To a person from a culture where conversation happens on a more contextually independent level, the Chinese thus comes across as as a race that is highly deceitful and untrustworthy one. A person who truly understands the rules of the game in this part of the world would in fact come to appreciate this “face saving” gesture given in response to a seemingly unruly request, thereafter depending on the quality of his upbringing resolve this is conflict in disguise with a more appropriate offer.

Of course there always exist the odd one out whom despite, being born and raised in this highly contextual culture, choose to ignore the social norms and push ahead mindlessly/greedily his own personal agenda. Such fools are usually the ones who end up with a bad reputation, smiled at by most but ostracized by all.

Much as I hate it, and usually function out of this mode when I am in the other parts of the word, this practice has became so deeply etched in me, it is hard to discard when I get back to this parts of the world. A typical example could be seen from how my dad treats the helpers for his stall.

There is helper A whom when free would drop by in the stall to help out. My dad would insist of treating him to breakfast, as well as passing him some money and left over goods from the stall after the stall closes for the day, despite helper A’s insistence that he does not want anything in return. Harmony is maintained and bonds are strengthened.

There is helper B who draws a salary, is alway late for work, slow in action and consumes more goods than he should  from the stall during working hours than he should. He finally crossed the line when a few hundred dollars went missing from the cashier counter during one Chinese New Year. Dad finally let Helper B go thereafter saying business was not too good and he could not afford the continued hiring of a full time help. Grace is saved, however relationship has broken down beyond repair. It need not be mentioned by due to his natural disposition, he has been avoided much by people from his social circle.

Application of the framework from the Tipping Point

David K.K. a friend on facebook got my attention when contacted me two days ago stating his interest to have his events published on ThingsToDoSingapore.com. I instructed him that by simply signing in as a member on ThingsToDoSingapore.com, the system will automatically poll his account and his friends’ accounts for newly created events  every 24 hours. Just for curiosities sake I went and did a manual polling for his account after getting his account id. To my surprise his account itself contributed close to 300 new upcoming events. To gain more understanding of this phenomena, I went and did a study on David K.K.’s facebook profile. Results showed he is one of the top ten members who have the most number of friends on ThingsToDoSingapore.com. This fact brought immediately to my mind a key point which I ever came across from the book “The Tipping Point”.

All individuals are not equal by nature, the differences could be attributed to their character, personality and natural disposition, as such when analysed in the context of the social network, some people are spokes (connected with just a few main people) while other people are hubs (connected to many people). According to the theory preached in the tipping point, to gain wide coverage for a message, it is important to gather the support of people that are hubs in a particular section of a social network as ambassadors of a sticky message.

After gaining this new insight, I modified a section of my codes to prioritize the polling of members accounts for events based on their number of friends.