I like to think that most officers are decent folks doing a job. Sometimes they may have to enforce laws they may not personally agree with. However that's not always the case unfortunately, and sometimes you'll get one that has a point to prove or an ego to gratify. The key is to be polite, know what the laws concerning your ride are, be polite, and don't have an attitude (even if they do).
...and of course, offer the officer the chance to ride it for a block or so and then tell them where/how to get the parts to do one up for themselves when they come back grinning from ear to ear.