A couple weeks ago I needed to easily convert HTML entities in a string back to their normal representation, but I didn’t really find anything nice, and wound up just using str.replace(/&/g, "&").replace(/'/g, "'"); since those were the only characters I was having a problem with at the time.

But today I went searching again for something better, and found a really great way to escape and unescape HTML entities. Not sure why I didn’t find his post the first time, I guess my Google-fu was weak that day.

Anyway, I’ve wrapped his methods up in a little helper class, and it works great:

package com.grooveshark.utils
{

    public class HTMLEntityUtils
    {
        import flash.xml.XMLDocument;
        import flash.xml.XMLNode;
        import flash.xml.XMLNodeType;

        public function HTMLEntityUtils()
        {
        }

        public static function htmlEscape(str:String):String
        {
            return XML(new XMLNode(XMLNodeType.TEXT_NODE, str)).toXMLString();
        }

        public static function htmlUnescape(str:String):String
        {
            return new XMLDocument(str).firstChild.nodeValue;
        }
    }
}

Hope it helps someone else!

Things that Work: Slicehost

February 4th, 2008

I just wanted to give a little shoutout to my VPS provider: Slicehost.

I used to have a couple of shared hosting accounts with Hurricane Electric. Now, if you just need a basic shared hosting account, I highly recommend them. In all the years they hosted my sites, I never had any problems, and I really appreciated their no fuss, no muss approach. Yeah, no cpanel or plesk or whatever, but I didn’t need those things, and in my experience, those all-in-one control panels are usually more trouble then they’re worth, and in the end you wind up with fewer options and less control over your site than if you had it hosted somewhere without them.

So I was very happy with HE.net, except that if I wanted to set up any more domains, I’d have to sign up more accounts, and honestly, none of the sites I wanted to build were really worth paying more money per month just to play with. Plus, I wanted an opportunity to learn more about how to set up a web server in the first place. So I started looking into VPS and dedicated server solutions. None of them particularly grabbed my attention until a friend found a link to Slicehost.

Both their philosophy and their prices caught my eye. They say that they’re a VPS provider for developers, by developers, and so far I’ve seen nothing to the contrary. They offer a variety of Linux flavors that you can install on your slice, and experimenting is encouraged - worst case scenario, you log into the admin panel and click the button to rebuild your slice from scratch. Five minutes later, you have a brand new shiny root password and a fresh start. Their wiki and forums are full of advice, guides, and tutorials from fellow slicehosters, so even if you’re new to linux server administration, you’ll be able to figure out how to set up the environment of your choice, regardless of whether you prefer PHP, Ruby on Rails, or even Django. They’ll even take care of your DNS for you, with a handy-dandy web form that makes adding records a snap, even if you’ve never done it before.

So I can’t recommend Slicehost enough. I’m saving money, getting to host whatever sites I want, AND learning all at the same time. Win-win.

Slicehost Works.