Archive for the ‘Uncategorized’ Category

Insane regular expressions

Most people I respect will agree with me that for things like html, regular expressions are a boat load of epic fail. However, a clever regular expression is a wonderful tool to have in your arsenal of problem solving tools. One of my favorite evil interview questions is “Can you create a regular expression that can validate email addresses?”. Mainly what I’m looking for is an insight into how people think about a problem and how much they understand the problem domain. It is also an interesting tell as far as when people admit they don’t know how things actually work.

I’m not looking for someone to belt out an answer like this (from http://fightingforalostcause.net/misc/2006/compare-email-regex.php)

/^([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,6})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)$/i

But if someone did, I’d probably go down a different path of questions since they obviously have a very good understanding of how email addresses work.

Along the way, I began to think to myself…. if you really wanted to validate an email address, wouldn’t it be vastly simpler to create a grammar that you could use to tokenize an address into the @ components, and then simply do an MX record lookup for the domain? Then, if you wanted to take it further, you could attempt a delivery and see if it bounces, but that is hardly real time.

Regular expressions are cool and all, but at the end of the day, even the expression above is simply an elaborate parser that is simply asserting the validity of the format, not the validity of the address. I mean, if the domain isn’t even registered, then the address is invalid. For instance, joe@example.com is a valid email address in the sense that it is well formed. However, if you’re a big rfc nerd like me, you would be instantly saying “Ah, ha! Example.com is a reserved domain according to RFC 2606! No recipients that that domain are going to be valid!”

You would be correct. Maybe this is an obnoxious way for me to take my ‘validate an email address’ to the next level. In the right circumstances, it would be quite telling if someone did not understand the significance of mx records and their role in mail delivery.

Added UDP support

I added UDP support today. Next up is probably going to be a help file. Apple has a decent enough intro to how application help works up at their developer site.

Once I get the help guide started and functional, I’ll take another swing at tweaking the UI a bit.

A bit of an oddity. Cocoa has a type of NSBoolean. In your data models, you can define columns as ‘Bool’. You would think that you could do something like this:

NSBoolean b = [object is_something];

if (b){
//do something
}

That doesn’t work. The problem is that the object b is an object. So, you get a memory address, and unless it’s simply not there… it will generally evaluate to true.

What you want is something along the lines of:

if ( [[someObject is_something] boolValue] ){
//do something if it's true
} else {
//do something if it's false
}

I’m a little embarrassed to say that I spent a half hour trying to figure out what I was doing wrong before I read the NSBoolean docs.

Next PortKnox release

I have some ideas I’m hoping to prove out this weekend with regard to UI tweaks as well as adding support for udp knocks. I’m hoping that by sunday I’ll have a release out that at least adds support for UDP. Once that’s done, I figure I will make some announcements on the appropriate forums.

Port Knox is real

I had this week off. It was a wonderful chance to recharge my batteries and get around to some things I’ve had on my list for quite some time.

One of those things is finally sitting down and learning how core data works so that I can write a nice (ish) port knocking utility for my wife.

After several rewrites, I’m finally happy enough with what I have to call it a starting point.

So, here’s the first mostly functional release of Port Knox

Fresh starts

I decided to reboot the blog. I’ve been spending more time doing mac development and I figure if I talk about that more… I’ll have a place I can read my own notes.

Return top

Observations On Development

Mostly this is for me to refer to as I teach myself different technologies.
  • Loading...


    Loading...

    Login






    Register | Lost password?

    Register





    A password will be mailed to you.
    Log in | Lost password?

    Retrieve password





    A confirmation mail will be sent to your e-mail address.
    Log in | Register