Archive for March, 2011


Brick walls

This is one of my favorite quotes of all time:

Brick walls are there for a reason. The brick walls are not there to keep us out. The brick walls are there to show how badly we want something. Because the brick walls are there to stop the people who don’t want something badly enough. They are there to keep out the other people.

– Randy Pausch

This quote is a good reminder for me today and everyday. It’s my encouragement when things are hard. Instead of getting frustrated, I try to use my stubbornness to my advantage. From rock climbing I’ve learned that I can get up just about anything if I stick with it long enough.

Randy Pausch was a Carnegie Mellon professor who passed away in 2008. Before he left us, Randy gave one last inspiring lecture on Achieving Your Childhood Dreams. It’s worth watching if you haven’t seen it already.

  comments

Detecting subdomains & effective TLD’s using publicsuffix.org

How do you detect if a domain contains a subdomain and then return that subdomain? At first it seems like it should be a simple problem. Just write a regexp that looks for the first period and return everything up to that point, right?

example.domain.com

But then you remember that subdomains can have multiple levels:

another.example.domain.com

And then you have those effective top level domains like co.uk to consider:

another.example.domain.co.uk

Hmmm, maybe this isn’t going to be so simple after all.

There are a couple ways to look at this problem. One way is to ask: how you know which part of a domain is the registered domain? Once you know the registered domain, you can figure out the subdomain.

One way of finding the registered domain is to do a whois lookup on the entire domain. If the whois comes up empty, strip the leftmost subdomain and try the whois lookup again. Continue this process until you get a match and that is your registered domain. While this method works, it comes at the cost of multiple network lookups.

Thankfully, there is a better way. It turns out browser vendors need to be able to parse domains too. The Mozilla Foundation started a cross-vendor initiative called publicsuffix.org that is a list of all the effective top level domains. This information is particularly important to browsers to be able to restrict cookies to a given domain. For example, without the public suffix list, anyone on a co.uk domain would be able to read the cookies set by any other co.uk site.

To figure out the registered domain, you need to know all the possible top level domains (like .uk) as well as all the effective top level domains (like .co.uk). There are some great libraries available that make it easy for you to parse the public suffix list to find a registered domain. Google has one in Java and regdom has libraries available in C, Perl and PHP.

While it feels a little inelegant to keep a list of effective TLD’s that has to be updated every now and then, it really is your best option for now. Using this list, it’s trivial to get a subdomain from a domain. For example, using the PHP library from regdom, the code to check for and return a subdomain is simple:

function has_subdomain($domain) {
    return ($domain != getRegisteredDomain($domain));
}

function get_subdomain($domain) {
    if (!has_subdomain($domain))
        return false;
    $registered_domain = getRegisteredDomain($domain);
    return str_replace(".".$registered_domain, "", $domain);
}

The public suffix list is incredibly useful and there are probably many more applications for it that I haven’t considered. I’m surprised it doesn’t get more attention from developers. If you need to do anything that requires you to know a registered domain, the public suffix list is the best place to start.

 2 comments

Why charging for developer tools is stupid

I saw today that Apple has started charging for Xcode. For the non-developers out there, Xcode is a tool from Apple for building software for the Mac, iPhone and iPad. It used to be free, now it costs $4.99.

Seeing this reminded me of a Microsoft focus group I was invited to be a part of a few years ago. As a CTO who had decided to build everyone on top of free software, they wanted to know what it take to make me to switch to a Microsoft stack. I told them they were 10 years too late. You see, I made the decision to use LAMP stack not because it was cheaper, but because it’s what I knew. And the reason I knew LAMP stack was because that’s all I could afford when I was 15. The question for Apple isn’t whether businesses or experienced developers can afford their development tools, it’s the teenagers they should care about. And while $5 is still well within the average teenagers reach, it’s still a lot more friction than free. This is especially true since many teenagers don’t have a credit card of their own. What kid wants to take the time to explain to mom why he needs to borrow a credit card for something called Xcode, when he can jump over to Google and get Android tools for free?

Apple already charges $99/year to be a member of their developer program which you need to be able to distribute applications on the App Store. While this pricing hasn’t seemed to hurt them much so far, it’s short sighted even if the effects aren’t immediately apparent. I’m a huge Apple fan and I hate watching them repeat the same mistakes Microsoft made years ago.

 12 comments