JavaScript snippet: Remove base URL from link

I needed this function this morning so I thought I’d share it in case someone else does too.

function RemoveBaseUrl(url) {
    /*
     * Replace base URL in given string, if it exists, and return the result.
     *
     * e.g. "http://localhost:8000/api/v1/blah/" becomes "/api/v1/blah/"
     *      "/api/v1/blah/" stays "/api/v1/blah/"
     */
    var baseUrlPattern = /^https?:\/\/[a-z\:0-9.]+/;
    var result = "";
    
    var match = baseUrlPattern.exec(url);
    if (match != null) {
        result = match[0];
    }
    
    if (result.length > 0) {
        url = url.replace(result, "");
    }
    
    return url;
}

Steer Well Clear

This morning a friend told me about this article, all about a new advertising campaign run by Steers, a South African fast food chain.  The article is all about the gross misuse of grammar in the campaign and musings on corporate irresponsibility.

I’d like to take this opportunity to share my thoughts on the humble, often-neglected, apostrophe and the evolution of language.

Read More →

Gentle Editing

Like many programmers, I’ve come to love Stack Overflow and the rest of the Stack Exchange network. Its unique Wiki / Blog / Forum blend creates a fantastic platform for knowledge sharing.

Thanks to its Wiki-like editing capabilities, quality sticklers like myself can get stuck in and help to smooth out some of the rough edges of the content base.

Unfortunately we geeks sometimes allow our egos to get the better of us, resulting in reasonably common, dreaded, edit wars.  To avoid these, I’ve come up with what I feel is a very gentle and respectful editing style which I’d like to share with you today.  My edits always take a fair bit of time, but I feel it’s worth the investment in the interests of the greater good.

Read More →