Google Custom Search and Wordpress Integration

Feb 11, 2008 @ 12:41 PM
Discuss: 3 Comments
Permanent Link: Save
Category: Web
Post to: del.icio.us

The default WordPress search engine barely qualifies as a search engine. It's results are not that relevant, the search page shows the actual blog entries instead of a list of links of resulting pages and the experience gets worse if the search query gets the least bit creative.

I think everyone should deprecate the WordPress search engine and move to Google Custom Search. There is simply no comparison. You can see the search results for AJAX on my website.

How-to for Google Custom Search Implementation in WordPress

Having recently implemented it on my site I don't think it gets much better than this. Implementing it in WordPress is trivial and the results are of the highest quality.

  • Head on over to http://www.google.com/cse/ and register for an account. Follow the prompts all the way until asked to select the kind of layout/code options.
  • The best Google Custom Search configuration I think is to select the iframe option with advertisements placed on the right. Secondly, you will want to specify the search results url as something like http://yourdomain.com/search.php. More on that in a minute.
    Google Custom Search Options
  • Subsequently you will be shown two textarea's. The first one is the search box code which shows the input field where queries are entered. You can paste this code in your header or index template (header.tpl or index.tpl in the wp-content/theme/ directory) depending on where you want the box to show up.
  • The second code box is for the search results page. To display the Google Custom Search results on a fresh page, create a file called search.php in the root of your web directory (this corresponds to the results url you entered above). Within this page you should paste both code snippets. The Google Custom Search box code will display the search box to the users once again so they can see their own query. The Custom Search results code will display the actual results below the box. This is what your search.php will look like:
    PHP:
    1. <?php
    2. // these two lines get the theme page initialization code and header
    3. require('./wp-blog-header.php');
    4. get_header();
    5. ?>
    6.  
    7. <!-- Google CSE Search Box Begins  -->
    8. ...
    9. <!-- Google CSE Search Box Ends -->
    10.  
    11. <!-- Google Search Result Snippet Begins -->
    12. ...
    13. <!-- Google Search Result Snippet Ends -->
    14.  
    15. <?php get_footer(); ?>

  • That's it, you're done.

Your page won't be instantly indexed and may take a day or two, but that's a small price to pay. And if you show your 5-10 most recent blogs in the sidebar then you're good anyway because users can navigate directly.

PTCL Nationwide Plan Cancellation Instructions and Fraud Details

Jan 23, 2008 @ 5:09 AM
Discuss: 0 Comments
Permanent Link: Save
Category: Pakistan
Post to: del.icio.us

Pakistan Telecommunications Company Limited has a subscriber base of 4.5 million users. PTCL in a recent revenue generation scheme enabled nationwide calling for all of it's 4.5 million subscribers without their consent. At Rs.199 per month per subscriber, PTCL will generate anywhere from Rs.800 million to Rs.900 million in the first month alone.

PTLC's plot to maximize customer retention into this plan is elaborate and operates at multiple tiers. Their business division and top business planners will probably get a nice bonus this year for devising such an ingenious plot to defraud customers.

The plot behind the fraud

  • PTCL has introduced a Nationwide calling plan which at a cost of Rs.199 per month provides 5,000 minutes of talk time to any city in Pakistan. The obvious contention is that PTCL has enabled this on all PTCL lines by default and most users are unaware they are automatically subscribed and being charged Rs.199 per month.
  • The bold print of the PTCL advertisement claims Nationwide is a free plan while the smaller print immediately following states there is a Rs.199 monthly fee for this plan. Which is it? The barely legible print of the advertisement states that the plan is limited to 5000 minutes. See the first advertisement
  • Another PTCL Nationwide advertisement claims there are no hidden charges and the fine print then clarifies there are no hidden charges only if the customer cancels out of this plan. It is akin to someone telling you that a car has no hidden charges if you don't decide to buy it. See the second advertisement.
  • The cancellation instructions are to call 1236 and I called the number about 8 times over the course of half an hour. If you follow the prompts the final prompt says press 1 to confirm cancellation. After you press 1 the phone line goes silent for 30 seconds. Most people will hang up before 30 seconds are up thinking they have now opted out. The elaborate plot by PTCL is engineered to misdirect it's subscribers. As I mentioned, the business division at PTCL have put their collective minds together to come up with this elaborate plot.
  • 20% of the time, in my experience the 1236 number has been busy. This results in lesser call volume and subsequently lesser cancellations. The persistent customer will keep trying but will still fail at the final prompt.
  • So you got through to 1236 and you pressed 1 at the final cancellation prompt and you waited 30 seconds and hoping you are now finally opted out. Actually 8 out of 8 times that I called, I got a message saying "The system is busy, please try again later". At that point I was ready to give up as will most customers. So finally the customer really has no way to opt out of the system.
  • This is not first time PTCL has done this. PTCL pulled the same stunt a year or so back with their Voice Mail feature which was activated on all phone lines by default. That scheme also generate tremendous revenues for PTCL.

How to cancel

Luckily for me, after failing 8 times the ninth time I dialed 1236 and decided to check on my voice mail feature and through that prompt I was able to get through to an operator. To cancel you can quickly follow these instructions without waiting to listen to the instructions on the phone:

  • call 1236
  • Press 2 for english (1 for urdu)
  • Press 3 for voice mail setup
  • Press 1 for voice mail activation/deactivation
  • Ask operator to cancel your nationwide and voice mail if activated

Spread the word so that people can cancel. The last date to cancel without penalty was 31 December which means you are already too late.

Startup Meetup in Karachi

Jan 19, 2008 @ 9:38 AM
Discuss: 1 Comment
Permanent Link: Save
Category: Pakistan
Post to: del.icio.us

There were some interesting people at the startup meetup held recently at the offices of PixSense and sponsored by the Pakistan Software Houses Association and Green&White. For me it was a good way to get acquainted with the talent pool that exists here and hopefully this is the first of many to come.

Following the buzz online revealed the following bloggers speaking about the meetup:

Online Scrabble Clone

Dec 22, 2007 @ 3:25 PM
Discuss: 0 Comments
Permanent Link: Save
Category: Technophilia, Web
Post to: del.icio.us

A while back I started what I thought would be an easy little project for an Online Scrabble Game clone. It's now completed and launched as Beta. I am calling it Yabble because the other interesting *abble words are quite common on the web. My reason being that instead of bookmarking sites or remembering a URL I often only remember a keyword that will help me rediscover the website. With Yabble it's easier to get into Google's top 10 as compared to Dabble or Gabble which return way too many results.

I do not want to get into the design details in this post except to say that the game is written using PHP and AJAX and uses XML files to store game state on the backend. I also used the Prototype JavaScript framework and Leightbox.

I used YUI Compressor to minify the Javascript and CSS and get some code obfuscation as a bonus. If it demands enough attention, I'll take time out to add more features and refactor some code and design.

Mark Cuban’s Interview in Esquire

Dec 17, 2006 @ 11:44 PM
Discuss: 1 Comment
Permanent Link: Save
Category: Business
Post to: del.icio.us

This one was good enough that I wanted to blog it and have a copy in my archives. Following is Mark Cuban's take on media, technology and American business. It was featured in the December 2006 issue of Esquire.

Wherever I see people doing something the way it's always been done, the way it's "supposed" to be done, following the same old trends, well, that's just a big red flag to me to go look somewhere else.

I think the underpinning of transition right now isn't technology; it's the fact that there's so much money out there and there's so much pressure on public companies. Back in the nineties, the Internet was booming and everyone looked like a genius. You know, everyone's a genius in a bull market. But, of course, we're no longer in a bull market, so everybody is trying to create the next something. There's a lot of desperation out there. In my opinion, right now there's way too much hype on the technologies and not enough attention to the real businesses behind them.

Whether it's downloaded video, streaming, YouTube, or the Internet in general, there isn't anything new anymore. There's not anything right now that you can point at and say, Here comes a whole new rapid-fire change. To me, it's like this: When you've got 10,000 people trying to do the same thing, why would you want to be number 10,001? There's just no good reason. Now, if you have something superstrategic or amazing, great. But 99 percent of the time, it's just people lying to themselves.

Which doesn't mean that the Internet and all that technology is bad. When you have a hammer, everything looks like a nail. And today's hammer is the Internet, or digital. To me, it's like electricity. Once it was invented, it's great. I'm not going to all of a sudden stop using electricity. I'm going to continue using the Internet and all things digital--high def, digital cameras, new tools, whatever. But now that we have a society that's integrated all of that, you have to start asking the question: What's next?

For HDNet, I'm just looking for programming that I think is going to be memorable, that is going to impact people personally, and stuff that people will think is funny--kind of like a baby HBO from a content perspective. Most companies, most media companies or public companies, are geared toward earnings per share, and that drives everything: hitting the numbers, hitting the quarter mark. But to me, it's not about that. It's about: Can we have an impact? If it's Dan Rather or Dennis Rodman, it doesn't matter--I don't care, as long as it's something unique. Everybody else does nothing more creative than following the trend. It's like: Let's do another poker show. Now let's extend that to blackjack. Now let's mix blackjack with poker. Now let's pimp my ride, let's pimp my house, let's get tattoos, let's get bounty hunters. If everybody else is doing it, I don't want to do it. Rather than trying to grovel for an extra share of viewers like most media companies do these days, I'd rather just throw it up against the wall and take some chances.

If I had more time? I'd get into places where people are so afraid right now that the economics dominate the common sense. I'd get into a business like newspapers--local newspapers. Newspapers are a perfect example of how economics dominate common sense. Contrary to popular belief, newspapers aren't dying. Newspapers are making tons of money; they just aren't keeping their shareholders happy, they aren't meeting the expectations on Wall Street. The problem with newspapers is that they're trying to grow like they're Internet companies in 1999. Their shareholders are bitching at them about not showing growth in share prices. The minute you have to run your business for share prices, you've lost. It's over. They've focused on that and so they've lost. What they should do is step back and ask, "What makes us special?"

I don't care how Internet savvy you are or whether you're in ninth grade or college, you're not going to read twenty-five pages of text online. In newspapers, you read more pages, you read more words. There's no way around it. But newspapers don't see their own value. They just don't get it. So they do dumb-ass shit, like they can't figure out who their customer is, they can't figure out what business they're in. They have all these news-wire reports, these breaking stories, but anyone who's Internet savvy knows that breaking stories, sports events, all that stuff is available on the Internet thirty seconds after it happens. The people who are in tune to wanting stuff immediately are going to get it online. But when you read The New York Times or you read the L.A. Times, you read the Chicago Trib or The Dallas Morning News, when they break a story that is unique, not just first, but unique, a story that you can't just pick up on the wire, you have to read it. And if it's geared toward different demographics, fine. Like, businesspeople have to read the New York Times business section--even though from personal experience I know they're wrong a certain percentage of the time. You still have to read it, just in case something clicks. Like for me. If I want to keep up with what's going on in Dallas, I have to read the local paper. So newspapers aren't dying; they're just undergoing an identity crisis. They don't know who they want to be.

We've got our iPods, we've got our PDAs, we've got our e-mail. Those are our time killers. You've got to realize: That's the role they fill. These things are not the be-all and end all--I don't think people think that through. They just think: Oh, everybody's doing it; that must be where everything's going. It perpetuates itself. It's just small-minded. ? With the Internet, life's become an open-book test. You don't need to know anything. There used to be value for memory. Now you can just Google it.

In running a private company, if I'm making money, I'm happy. If we are profitable, great. If I make more than last year, great! It isn't like, Dang, I've got to grow 15 percent this year. If I'm making money, if I'm paying my bills, I'm happy. Save a little bit, all the better. What's fucked up is, the people who run public companies don't think this way. They're just trying to get rich. The idea of running a public company isn't "Wow, I can run a company." It's "Wow, I might be able to get rich!" Not just a-couple-million-dollars rich, but a-couple-million-dollars a-year, fuck-you-money rich. The guy who has a $50 million gold en parachute is thinking, How can I get them to fire me? That fucks up a lot of things when it comes to business.

The number-one job of the hedge fund manager is not to make sure that you can retire with a smile on your face--it's for him to retire with a smile on his face.

No balls, no baby: That's what I like to say. It's so true. Most people don't want to cross that line. There's safety on one side, uncertainty on the other. Most people don't take that step. And it's not even so much that they're afraid to take the step; it's that they know deep down that they didn't do the work necessary to be prepared, and that's the big difference. Most people think, Oh, I have a great idea, and the only thing missing is that I don't have the connections, I don't have the access to money. But that's the biggest bunch of bullshit. The minute anyone says that to me, I know they're a failure. Because if you're prepared and you know what it takes, it's not a risk. You just have to figure out how to get there. There is always a way to get there.

You can find any type of discussion group across the Net that is finite enough to make you a hero. It might just be three people, but in that group, you're your own David Koresh. And I think that gives people a false sense of wisdom. And I think that's kind of a hassle right now.

The Unwarranted Hyperbole Surrounding Vista

Dec 5, 2006 @ 5:56 AM
Discuss: 1 Comment
Permanent Link: Save
Category: Technophilia
Post to: del.icio.us

Seattle Times story "Why Vista might be the last of its kind" reflects a sentiment shared by many regarding the impending loom and doom of Vista. A lot of this foretelling is misdirected and regurgitation of the same old rhetoric that's being pulled back under the spotlight to create a sense of anxiety: The desktop is dying and online is the wave of the future; Users have been anxious with the wait and anticipation for 5 years; Vista is a failure even before its out the door; It's the last of its kind.

At the employees only Vista launch party held in the underground garage of building 26 on Redmond campus, Bill Gates (who flew in by helicopter straight from the airport upon returning from Europe) expressed only relief saying something to the effect of "I'm glad it's out" and went on to talk about the task of security and servicing that lay ahead. Even though the media seldom sees it, internally we are quite self-critical. Time is money and this delay cost Microsoft a lot of money.

But Vista was an ambitious undertaking and the problems encountered are not exclusive to Vista. Engineering undertakings of this magnitude have a certain level of risk attached. Sure, the whole thing left a bitter taste but fear of failure did not stand in way of ambition. The first plane to fly was preceded by countless failed designs and deaths. Many died trying to get to the moon. The Titanic crashed and the Hindenburg burnt. Our ambitions have always exceeded our capabilities and that is what moves us forward.

The remaining arguments are nothing new and most of them hyperbole packaged to be easily digestible by the naive onlooker. Online services may some day replace desktop applications. In theory it's completely possible because essentially it's your monitor attached to a computer located in some distant place. But that day is far, far away. An application like Adobe Photoshop or Visual Studio won't be replaced by an online version anytime soon. In fact the complexity of desktop applications will continue to grow and online services will always lag behind in many areas while excelling in others. The forthcoming model will be toward hybrid online+offline applications--rich desktop applications complemented by thin Internet counterparts that allow for mobility.

No matter the cost of Vista, as Bill Gates put it at the launch party: "it's a gift that keeps on giving". The platform enhancements in Vista and other changes under the hood are something that will reveal their worthiness over the upcoming years.

Microsoft's next operating system is code named Vienna.

What is the Value of Demographic Data?

Nov 16, 2006 @ 5:07 AM
Discuss: 1 Comment
Permanent Link: Save
Category: Web
Post to: del.icio.us

The group I am working in at Microsoft has to do with business intelligence and advertising displays--this is a very interesting space to be in at the moment as it is central to the monetization strategy for the MSN division (now Windows Live). It's something that has been forced upon all Internet players.

In the pre-Google era, advertising-based services were a failed model--to use the then oft-quoted quip "there is no such thing as a free lunch". That changed when Google proved that ad-based services can make money and they did this through state-of-the-art datamining and simple two line text-based ads which marked a complete shift in the conventional thinking. It was very innovative and it undercut premium services like Hotmail which eventually followed suit. It is the driving force behind Google's billions (2.7 billion in revenue for their most recent quarter).

Recently I got a an internal newsletter inside which I stumbled upon a few Microsoft bloggers in this space and spent a bit of time reading through some interesting posts. What prompted me to write this post was Mark Jacobson's point regarding user profiling and how Google lacks demographic data on its users. You have to ask yourself, why is it that Google is not interested in this information and how much of a disadvantage do they have? Do they know something we don't?

If you sign up for Hotmail or any of the Passport services, one of the forms you encounter will require your birth date, gender and location. Google on the other hand doesn't ask you for any of this information--their form is extremely minimalistic in that regard.

Why Demographic Data

Most conventional marketing and research is based on targeting demographic profiles. If you are a 29 year old male living in the 90210 zip code (Beverly Hills) it would indicate that you are in the 1MM+ income group. That helps in targeting ads to you. Your very first ad could be for a new Porsche or a Versace suit. This is traditional marketing and while I don't know how optimized those heuristics are, but on the web you can--and should--leverage a lot of the newer metrics it has to offer.

As an aside, ads on television networks also have a lot of room for improvement in the ad relevance arena as we step into the digital age, however, there are technical hurdles (harder to datamine videos; harder to show different ads to different people).

Context is Critical

So I am a 19 year old whose zip code is in the university district and you can show me ads about a Dave Matthews concert in the area but how likely am I to click it based on my age and zip code? The probability that I am a student is pretty high because I'm the right age and in the right zip code but that also assumes you have prior research to deduce user profiles for that demographic data. And now you still need to know if I like rock, heavy metal or house music. You also don't know if at that very moment I am very busy researching symptoms of an illness or researching my next big investment move in a particular stock and don't give a hoot about some concert.

On the web you are what you read. It's about contextualization. What should matter to advertisers is what I am looking at, at any particular moment because that is what is most relevant to my interests at that very moment. With demographic data you are targeting most 21 year old students for most of the concerts most of the time (up until the concert is sold out or the marketing campaign ends). All the while you are hoping to cast the biggest net possible to grab a tiny audience of concert-goers in that region. There is a lot of wasted effort. Most of the people don't care about the concert. The clickthrough rates will be very low. In fact, this model was so bad that nearly all services I can think of that were built around ads failed with this business model around the dot com glory days.

If you shift your focus to contextualization for achieving higher clickthrough, you get a lot more out. I am on a page looking at the discography of U2 and you show me an advertisement to purchase the U2 iPod Nano or a U2 CD. Those ads are agnostic to demographic data. This means that you cannot show me an ad for a U2 concert in my state because you don't know my zip code. However, as an advertising company you can only so show many ads on any page and the U2 concert ad is better left for the Seattle radio station website where locals visit. Local ads on localized content, adult ads on adults content, children's ads on children's content, rich ads on luxury content and so on.

When you have good contextualization, the value of demographic data falls considerably. That said, demographic data obviously has its uses. A page like msn.com which is generic does not represent the mood of the reader since it's dynamic and very general. On a page like that, knowing if your user is male or female helps promote the right kind of ads.

Anatomy of a Well Designed AJAX Login Experience

Nov 14, 2006 @ 6:29 AM
Discuss: 1 Comment
Permanent Link: Save
Category: Web
Post to: del.icio.us

AJAX in itself is a very simple technology, especially with the availability of the right tools. You make a request and pass some parameters, get a response and you render appropriately. The only thing is that the entire process is tedious and if you are the kind of person that likes to do their own plumbing, things can take time. I recently started a web 2.0 project and am nearing completion of the login page. If you are at the beginning of the web2.0 learning curve (barely familiar with JSON, REST, and Prototype) you will find this post interesting. Or, if you have ever designed your own login page, you might find some details here quite useful.

Get Equipped

First things first, find the right tools for the job.

You need a cross-browser Javascript framework to overcome the discrepancies in different browsers and simplify your life. You can skip all those AJAX tutorials out there and just take things for granted when you adopt the Prototype framework. It's small and has a clean cut library. Though, I should add, I felt the absence of a cross-browser attachEvent but this here script filled that void. As with all things open source, there are different camps and I considered joining the JQuery camp, however, Prototype has a better roadmap and larger community due to its Ruby on Rails endorsement so I went with that.

Next up is client-side validation to help you conserve server load and precious bandwidth by avoiding trips to the server just to validate the password field is not empty. Andrew Tetlaw's validation.js is built on top of Prototype so it fits the bill quite well. It's small and I really love the way it tackles validation using CSS classes. For example, the validate-email class verifies the field has a valid email address (I was also able to define my own custom validators and error messages very easily):

HTML:
  1. <input type="text" size="30" id="email" class="validate-email" />

And what would an AJAX application be if you didn't sprinkle a few animations and effects. I simply wanted to fade text in and out (for usability reasons I will mention later). Be warned though, it is easy to get tempted by all the cool effects and I wouldn't be surprised if all sorts of fancy effects start showing up as these FX libraries trickle down to the lower echelons of web enthusiasts. At first, I went with moo.fx because it's supposed to be superlightweight. However, I ran into some issues with it in IE and switched to Script.aculo.us. Contrary to my initial beliefs, Script.aculo.us is just as small as moo.fx when compressed and possibly better in other arenas.

Speaking of compression, it's probably a good idea to use a reliable JavaScript compression tool before going live with the website. I haven't done this yet and I am certain I'll run into a few other bugs but I'm also certain someone else has already compressed the popular libraries and shared them out. Since all my libraries have relatively big communities, I should be safe here.

Lastly, to exchange data between the web service and the client side Javascript, there are two camps: JSON or XML. I like JSON (JavaScript Object Notation) because it's very lean compared to XML and much faster because it doesn't need any complicated parsing. Instead of using <firstname>aleem</firstname>, JSON simply passes { 'firstname':'aleem }. And then, instead of parsing the XML using XPATH or whatever, JSON simple calls the eval() function which treats the string literal as an object. The only reason to go with XML is if you want to exchange that data with other non-AJAX services. Even so, JSON is well-formed so it's likely you can convert it to XML (there might be tools out there already to accomplish this). Prototype does the client-side parsing and on the server side I chose JSON.NET which takes .NET objects and converts them to JSON for Javascript consumption. It's open source so I can optimize the library and very easily get rid of functionality I don't need.

A Simple Form: Username, Password and Submit

It seems deceptively simple but if you want it done right, there's quite a bit of plumbing to do. Let's begin with the client-side plumbing. Using my validation tools I ran the following client-side validation:

  • Username: should be non-empty, minimum of 5 characters, maximum of 15, alphanumeric and must start with an alphabet. The regex looks like this: ^[a-zA-Z][a-zA-Z0-9]{4,14}$
  • Password: should be non-empty

Further, every time the user hits the submit button, the error messages fades back in. The reason for doing this is because the user will not know the form has been resubmitted using AJAX so the fade-in provides a visual cue that a new action was performed.

The same validation needs to be repeated on the server side. This redundancy is necessary for obvious security reasons--anyone can bypass the form and submit directly to the server. Assuming the validation goes well, the server can respond in any of the following ways:

  • Username does not exist. Display the error on the client side in red and set the focus() to the Login field for convenience.
  • Password does not match. Display the error in red, set the focus() to the Password field and select() the password field text. The reason for selecting the password field is so that the user can start re-typing the password right away. This is not necessary for the Login field however, as it is not asterix'd like the password field and can be corrected visually. Also, select() is better than resetting the field since it gives the user the option to deselect and do the correction.

I did run into Javascript quirkiness here. The order in which the event handlers are executed is convoluted and seemingly non-deterministic in IE. I took me time figuring this out and discovering this is a known issue. Remedying it was simple though--I stuck with only one event handler when order of execution was important. This problem came up during form validation--attaching client side validation and server side validation to the form and having them run in order so if the first failed, the latter would not be executed.

The Server Side

On the server side I am using ASP.NET and wrote HTTP handlers using ASHX files. I also turned off AutoEventWireup which is excessive and unnecessary--it automatically wires up event handling functions to the page. The AJAX framework passes requests over HTTP using GET and POST in general. This is the REST approach and if the Wikipedia explanation seems confusing, just ignore it and grasp the following HTTP request:

HTML:
  1. POST /ods/serviceall.ashx HTTP/1.1
  2. Host: localhost
  3. Content-Type: application/x-www-form-urlencoded
  4. Content-Length: 30
  5.  
  6. r=login&username=FOO&password=BAR

That's the request that gets sent out when the AJAX framework makes the call to the server. The thing to note is the last line which contains key/value pairs with three keys: r, username, password. When the server gets this, it parses this and makes a call to login("FOO", "BAR") and sends an HTTP Response back:

HTML:
  1. HTTP/1.1 200 OK
  2. Server: Microsoft-IIS/5.1
  3. Date: Tue, 14 Nov 2006 03:19:38 GMT
  4. X-Powered-By: ASP.NET
  5. X-AspNet-Version: 2.0.50727
  6. Set-Cookie: ASP.NET_SessionId=cefnyt45pspxr1uiy34lyrj4; path=/; HttpOnly
  7. Set-Cookie: .ASPXAUTH=C3134DF74BDCD48131A084AFFA794C970C0F9998A244B8A707844EF5A8260C40E2164A4B98FD7AE2B6D52D40DD05391B19BEFC8F9D5BA4C627CF4D3C0864F42C6703C7525AA4A3F80DBB2A4774D43388; expires=Tue, 14-Nov-2006 03:49:38 GMT; path=/; HttpOnly
  8. Cache-Control: private
  9. Content-Type: text/html; charset=utf-8
  10. Content-Length: 4
  11.  
  12. true

Ignore the X-Powered-By and other obviously useless headers (I intend to drop them from the server response). When the client-side AJAX framework gets that response it first looks to see if the content contains "true" (last line). If it does then authentication succeeded. For the sake of standardization I will switch to JSON and respond with something like { 'result': true } and then simply use: if(result){...} in my Javascript code. However, I use Enumeration types on the server and JSON.NET does not support serializing Enums to JSON, so there's some work for me here. Anyway, so I grab grab the entire Set-Cookie header and pass it to document.cookie to set the authentication cookie on the client. This cookie is used to verify that the user is authenticated and the login process is now complete.

End of the Beginning

Understanding the guts of the system is not critical to getting the job done but if you want to get intimately familiar with Web 2.0 underpinnings you might want to consider using WFetch or the Live HTTP Headers plugin for Firefox which is terribly useful. The Venkman Javascript Debugger is indispensable if you are into any kind of Javascript development.

I have had a recent inclination toward ASP.NET even though PHP has been very good to me. If you are comfortable with ASP.NET and Visual Studio then you certainly want to use it for learning. PHP will not allow you to set breakpoints, inspect the stack or make runtime modifications. If you are using PHP though, be sure to turn on error reporting if you haven't already.

My login form still needs a "remember me" checkbox and it needs to handle timed out users so after re-login they can be redirected to the page where they timed out. Once the login experience is all squared out, I will move on to designing a quick and simple sign-up experience.

5/29/2007 Update: I wrote Prototype.js does not offer a cross-browser attachEvent, but Event.observe offers just that. For some reason I overlooked it at the time of writing this post.

Why Microsoft and ASP.NET Cannot Threaten the PHP Moat

Nov 7, 2006 @ 7:52 PM
Discuss: 3 Comments
Permanent Link: Save
Category: Web
Post to: del.icio.us

ASP.NET does not aspire to PHP but it has good reason for envy and the two are undeniably in competition. The ASP.NET platform is quite something when you contrast it against PHP which doesn't even have a development platform worthy of note. It has a clean cut architecture, easily discernible roles for each component and object oriented support. The Visual Studio .NET development environment alone is enough to persuade people to switch to ASP.NET because it's that good--not only for development and debugging but also as a learning tool to understand the flow of the application, inspect the stack and heap, request and response, the current state of objects and other advanced features.

Why then is ASP not giving PHP a good run for its community and user adoption?

Timing

ASP was a late bloomer. PHP was one of my first obsessions with programming (discounting BASIC lessons I took when I was 13 and fell out of a year later because I took to playing games) along with the then rudimentary JavaScript. ASP was no where to be seen primarily because it was not free and endorsed mostly by the professional community. Visual Studio Express attempts to remedy this, though the thought of what could have been if it had been introduced around the time PHP3 was making its rounds would certainly makes some executives flinch.

Platform Strategy

Not all of it was timing. Arguably, even if all the tools made available in Visual Studio Express suite (SQL, Visual Web Developer et al) had been offered earlier, ASP might not have achieved mass user acceptance. A product like WordPress (which powers this site) could never have gained the same level of support if built in ASP.NET. ASP.NET gives protection to the source and is most conducive to building proprietary solutions. You could write a charting library, wrap it up as a DLL and put out a trial version to everyone. Since it runs on the web, enforcing licensing is much easier by having it ping a licensing server. Monetizing it is easy. In PHP this is not the case. The source is there for everyone to read and anyone can and probably will write a free version of any WordPress plugin that you would want to charge for today.

Further, the development ecosystem is scattered with tools and libraries attached to viral licenses that oblige developers to share any derivations arising from these tools. When the ecosystem is built on an open-source, share alike license its difficult to build on the shoulders of the community without giving back to the community. The community has a built-in, self defense mechanism that ensures its survival and results in rapid growth. WordPress and Firefox have quite literally every plugin you could possibly ask for. Installing the plugins is trivial and hacking or extending them isn't too hard if you are a developer.

No comparable WordPress equivalent exists in the ASP.NET world wherein an option is available to keep the source protected and more often than not, the option gets excercised, locking out community engagement in turn. ASP.NET has typically been aimed toward the professional not the amateur though it is now trying to find some middle ground to increase user adoption but I doubt it will ever get there for the fundamentals reasons mentioned here.

Costs

The monetary costs, as well as the cost of adoption are both higher for ASP.NET from my experience. Hosting an ASP.NET application on a Windows Server requires higher licensing costs for the hosting providor which in turn are transferred to the customer, resulting in more expensive hosting for ASP.NET applications.

The cost of learning for ASP.NET is also higher. Visual Studio .NET does provide all the plumbing and template for starting off but the underlying plumbing is quite complex. The ASP.NET page life cycle is not trivial and if you aren't comfortable with a debugger you'll find it harder to experiment with it. PHP's scripting model although crude, allows would-be developers to simply dive in. My first PHP page was as simple as saving the file with a .php extension and wrapping the code in php tags with a print statement. No includes, no headers or strong typing, no nothing. ASP.NET will require building out an entire solution if you follow the prescribed development route and though automatic, it still makes it harder to just dive in.

The lower cost of initial adoption results in a wider user base falling into the PHP funnel.

Communities

PHP has a feedback loop built around good karma. Some random people helped me overcome my hurdles with PHP and in turn I learned to empathize with other new comers and offered my support and experience. I find that ASP.NET does not have the same level of community support which scares some people away and doesn't provide the confidence of crowds. The network effects of a larger community also means that there are more people along each stage of the learning curve. Whether you are just starting off or you are making the switch from PHP4 to PHP5 or you are trying to hack some low-level module, the likelihood of someone else tackling the same problem around the same time is much higher and this kind of peer support is a good motivator.

My Sentiments

I am a long time PHP fan and love the fact that WordPress is a product of it. However, if I were to build a web service or website for my own purposes I would be more inclined to go with ASP.NET. Some of my old ticks are still there and I prefer to do much of the underlying plumbing by hand as I find generic solutions are excessive. I also get a greater understanding and consequently feel more comfortable with the application.

Microsft's partnership with Zend should be a win win for both communities. Imagine loading your PHP solution in VS.NET and having auto-complete--writing WordPress plugins would become a breeze.

Mind Over Matter

Oct 24, 2006 @ 11:47 PM
Discuss: 2 Comments
Permanent Link: Save
Category: Humans Being
Post to: del.icio.us

Scott Adams is the man behind Dilbert Comics--one of my favorites. 18 months ago he lost his conversational speech to a rare condition called Spasmodic Dysphonia. Recently he reported having miraculously regained his speech. The strange thing about this condition--and how the mind works--is that he could sing and give professional speeches but he could not carry out casual conversations since different types of speech are processed in different regions of the brain and follow different neural routes.

Interestingly, he recovered his speech by talking in rhymes and trying to blur the line between rhymes and regular speech. How does the mind know what rhymes and what doesn't? What is the difference between "Yellow" and "Yellow Fellow"?

Neural networks are a complex collection of neurons which talk to each other through chemical signals generated from electrical impulses within the brain. Like a current running through the wire, information flows across the neural network through a series of chain reactions much like a ballet, where each performer responds to a cue from another performer and the chain reaction of responses accomplishes an act. So a particular neural mapping is the path followed by a chain reaction, however, if a certain mapping is damaged then the physiological function accomplished by that mapping is lost. In lab rats for example you could tap a certain part of their split open brain and cause their leg to move. However, if that part is damaged altogether it might so happen that they would not be able to move their legs anymore. In Scott's case it was conversational speech he had lost. However, the chain reaction required for rhymes follows a slightly different path and that neural mapping was still intact.

One can only speculate on how things work but it appears that Scott conditioned his mind to reinforce the functioning neural maps responsible for rhymes and manipulated them in slight iterations (by using rhymes to lean toward conversational speech) to find a new mapping to accomplish the the same function of conversational speech. It's almost as if when the mind is searching within itself for a rhyme, it ends up at a different state in the neural network map from where it then proceeds to deliver that rhyme as speech through a still functional mapping.

So going forward if you can land your mind in that state by consciously making an effort to concoct a rhyme (or conditioning your mind so that subconsciously you always consider a rhyme) you can then proceed from there to deliver regular speech instead of the rhyme--akin to taking a detour and making that detour your regular route.

Gives a whole new meaning to the simple mind over matter issue.