I was originally in a team of 4-5 programmers, but the company slowly got rid of everyone except me. At that point I tried to leverage the situation and institute some changes in the programming languages, web stack and workflow automation; most of them were rejected by the boss on the grounds like "sure, we could switch to something better - like say, Ruby - but Ruby programmers are much more expensive than PHP."
It took me a lot of work and pain to eventually leave. My two biggest mistakes:
1) Not noticing when was the best time to go. There was a moment when the old project ended and they wanted to get me into a next one. Building it solo. From scrapped bis of metal. I should have left right there.
2) Being too afraid of changing jobs. I know that with my skills I can land a new programming job very quickly, but the process of job interviews scares me.
Oh, and 3) Singing that exit-level contract that ended up with me working my ass off in the evenings to finalize some contracted components.