This question may be considered subjective (I got a warning) and be closed, but I will risk it, as I need some good advice/experience on this.
I read the following at the 'About' page of Fog Creek Software, the company that Joel Spolsky founded and is CEO of:
  Back in the year 2000, the founders of Fog Creek, Joel Spolsky and
  Michael Pryor, were having trouble finding a place to work where
  programmers had decent working conditions and got an opportunity to do
  great work, without bumbling, non-technical managers getting in the
  way. Every high tech company claimed they wanted great programmers,
  but they wouldn’t put their money where their mouth was.
  
  It started with the physical environment (with dozens of cubicles
  jammed into a noisy, dark room, where the salespeople shouting on the
  phone make it impossible for developers to concentrate). But it went
  much deeper than that. Managers, terrified of change, treated any new
  idea as a bizarre virus to be quarantined. Napoleon-complex junior
  managers insisted that things be done exactly their way or you’re
  fired. Corporate Furniture Police writhed in agony when anyone taped
  up a movie poster in their cubicle. Disorganization was so rampant
  that even if the ideas were good, it would have been impossible to
  make a product out of them. Inexperienced managers practiced
  hit-and-run management, issuing stern orders on exactly how to do
  things without sticking around to see the farcical results of their
  fiats.
  
  And worst of all, the MBA-types in charge thought that coding was a
  support function, basically a fancy form of typing.
A blunt truth about most of today's big software companies! Unfortunately not every developer is as gutsy (or lucky, may I say?) as Joel Spolsky! So my question is:
How best to work with such managers, keep them at bay and still deliver great work?