The best thing to do is to just not give them any reason at all to become interested in you. The way you do that is pretty simple - just tell the truth.
I never got actually locked up like this guy, but I did have to sit in the lobby while they went through our van and had to answer tons of questions. If you're telling the truth it's not really a problem. If you're lying though, you'd better be a damn good liar because they are trained to try to trip you up.
To be fair, I wasn't put in a jail like the author was; I was sequestered in a very small room, door closed, and asked rapid-fire questions by two CBP agents for 2+ hours.
I was telling the truth the whole time, which is why they ended up letting me travel that day. But let's just say that the next time I crossed the border, I had a mountain of paperwork that proved that I was employed by a Canadian company, that I was paid in Canadian dollars, that I had a return ticket booked & paid for as well as lodging, and a letter of work and an agenda indicating what I would be doing in the US while I was there.
I never got actually locked up like this guy, but I did have to sit in the lobby while they went through our van and had to answer tons of questions. If you're telling the truth it's not really a problem. If you're lying though, you'd better be a damn good liar because they are trained to try to trip you up.