Delete all comments in your code and make all subroutine and variable names meaningless (or meaningful only to you.) When possible, port your code to a language that no one knows and no one will learn, like Haskell.
I work only for startups. One of the myriad benefits is that I'm not going anywhere until I want to or the business dies. The first in under my control, and the latter is usually seen from a distance easily.
That, and having healthy savings and several other options when I'm fired. Losing a job is inevitable, and I look at it as an opportunity do things I can't do when I'm working full time.
Hare's a very good resource regarding you question: http://mindprod.com/jgloss/unmain.html.
It works for me! No way I'm getting laid off, it will take years for a good programmer to understand the mysterious ways our system works. Although, I can't really take credit for it, I even made it a less of a mud-ball it was.
Other option, that should work, if you have sensible management - be a better programmer than the other employees.
god bless you sir, that essay is {hilarious = hilarious + 1}
In C:
seen people do similar stuff
they get fired/laid off first
it's called "not being a team player"
welcome to $REALITY