I was asked questions ranging from whether I am affiliated with Hezbollah to why I was developing encryption software (and one time there was even a technician who asked me about its technical aspects), and specifically detained for questioning more times than I can count.
I was never refused entry, but I just wanted to attest that this man's story is completely credible to me, right down to the fine details he describes.
Possibly an interesting side-story for HN folks: By astronomical coincidence, I bumped into David Petraeus at a strange social event in D.C., after being harassed at the border every single time, and told him conversationally, casually, about my background and what I work on, just to see how he would react, if his reaction would line up with the knee-jerk reaction at the border. He smiled, raised a glass of champagne, and said, "cheers."