Showing posts from March, 2014

How to Write a Spelling Corrector...

…in 21 lines of code.In the past week, two friends (Dean and Bill) independently told me they were amazed at how Google does spelling correction so well and quickly. Type in a search like [speling] and Google comes back in 0.1 seconds or so with Did you mean: spelling. (Yahoo and Microsoft are similar.) What surprised me is that I thought Dean and Bill, being highly accomplished engineers and mathematicians, would have good intuitions about statistical language processing problems such as spelling correction. But they didn't, and come to think of it, there's no reason they should: it was my expectations that were faulty, not their knowledge.I figured they and many others could benefit from an explanation. The full details of an industrial-strength spell corrector are quite complex (you con read a little about it here or here). What I wanted to do here is to develop, in less than a page of code, a toy spelling corrector that achieves 80 or 90% accuracy at a processing speed of …

Why I like using Amazon Web Services

Amazon Web Services (AWS) are fast, cheap, and reliable. Usually you have to pick two out of three, but with AWS I get all three.One of my uses for AWS is a MySQL database for tracking customer sign-ups and log-ins in Poker Copilot. It is a simple way to monitor usage patterns.I’ve been moving around South America for the last ten weeks, running my business from hotel Internet connections. Every time I try to access this database, I find my access blocked, because access has to be granted to an IP address (or IP subnet) on a case-by-case basis. Each time I access the database from a different IP address I need to go into the AWS web-based console, and add my IP address (or to be precise, my CIDR/IP). Then, and only then, can I access the database.It’s annoying. Because it is secure. Well, part of a secure configuration. And I like it. If I set up an MySQL instance myself on a rented virtual server, I’d need to set up this stuff. And I’d do it wrong, because setting up and maintaining …

Learning by Teaching

Java 8 was released this week. I’ve been using an early access version of Java 8 for some months. Indeed, I wrote SeeingStars in Java 8.Java 8 includes many new features, APIs, and additional syntax. Best of all it includes lambda expressions. This is possibly the biggest update to Java ever.I’m finding it tough to learn and remember all the new stuff in Java 8. Then I recalled reading that when you teach a concept you become very knowledgeable on it. That is, teaching something is a good way to learn it very well yourself. So in light of this, I’ve restarted the Java Newsletter. For a while each week I’ll be covering a new feature in Java 8. If you use Java, I recommend signing up here.

Lessons from Apple's SSL Bug

There’s a summary here of Apple’s recent SSL bug in iOS.This sort of subtle bug deep in the code is a nightmare. I believe that it's just a mistake and I feel very bad for whoever might have slipped in an editor and created it.Here's a stripped down that code with the same issue:extern int f();int g() {
int ret = 1; goto out;
ret = f();out:
return ret;
If I compile with -Wall (enable all warnings), neither GCC 4.8.2 or Clang 3.3 from Xcode make a peep about the dead code. That's surprising to me. A better warning could have stopped this but perhaps the false positive rate is too high over real codebases?I fired up AppCode, the world’s best Objective-C IDE, which happens to also support C. I added the code snippet above, and it instantly and correctly highlighted the line “ret = f();” as unreachable code.Lessons I take from this:Use a state-of-the-art IDE that has excellent real-time code analysis tools. Don’t ignore the warnings it gives unless you have a really good …