« August 2010 | Main | October 2010 »

September 21, 2010

Sanitize String for Regular Expression

I recently came across a need to use a user supplied input in a regular expression. To prevent any special characters in the user's string from being treated as a regular expression control character I stumbled upon this solution. Alas I can't remember where I found it but wanted to share.

/**
* Convert a random string into a format that will make sure it doesn't
* impact a regular expression when inserted into it.
* @param string String to sanitize.
* @return Sanitized string
*/
public function sanitizeForRegExp(string:String):String
{
    if (string == null)
    {
        return null;
    }
    return string.replace(new RegExp("([{}\(\)\^$&.\*\?\/\+\|\[\\\\]|\]|\-)","g"), "\\$1");
}

Tags: as3 flex regexp

September 9, 2010

The Disappearing Spoon

The Disappearing Spoon: And Other True Tales of Madness, Love, and the History of the World from the Periodic Table of the ElementsThe Disappearing Spoon: And Other True Tales of Madness, Love, and the History of the World from the Periodic Table of the Elements by Sam Kean

My rating: 4 of 5 stars


An engaging exploration of the history and stories behind the periodic table. Each chapter focuses on different groups of elements that share a common theme, such as the scientists behind their discovery or some unique property. The notes and errata are a must read and offer a wealth of references to other books and articles if there is a particular element you want to learn more about. At times the science explanation is a little light instead favoring the telling a good story about the element. Overall one of the most enjoyable science books I've read.



View all my reviews

Tags: books science

September 5, 2010

Being Geek

Being GeekBeing Geek by Michael Lopp

My rating: 5 of 5 stars


This book contains many astute observations about the life of a software developer combined with practical advice about how to approach your career. The book touches on aspects like interviewing for a job, office politics, transitioning to new responsibilities like becoming a manager, how to manage your time, dealing with crises, and thinking about when it's time to find a new job. I found the book did a great job of helping me think about the three questions it lays out at the beginning: What am I doing?, What do I do?, and What matters to me?.



View all my reviews

Some notes I took while reading:

  • What am I doing? What do I do? What matters to me? What do I care about? [6]
  • Technical direction. Growth. Delivery. [9]
  • It's OK to quit a job with people you like because there are a lot of people to like out there. [8]
  • ... do I know what I want to do? [23]
  • We must not ship crap. [60]
  • 1:1 agenda: What are you worried about? Here's what I'm worried about. And discuss.... [109]
  • staff meeting agenda: Operations (Where are we?), Tactics (What are we going to do about that?), Strategy (No, really, what are we going to do about it?). [110]
  • All of Chapter 23 (a.k.a. Nerd 101) [165-172]
  • Where do I want to go? What do I want to build? And how do I want to build it? [262]
  • Have you failed recently? Is there someone within throwing distance who challenges you daily? Can you tell me the story of something significant you learned in the last week? [298]

Tags: books life

September 2, 2010

Urban Warfare Game

A former co-worker of mine just announced an awesome new Facebook game that they built with Flex, Swiz, and AS3Signals. It's called Urban Warfare, plays like Civilization, and can be found at http://apps.facebook.com/urbanwarfaregame/.

Tags: flex game