I once worked for a company who called our department into a meeting on a friday afternoon and spent an hour telling us what grand plans they had for us. Monday morning, we came in and the whole department had been sacked.
I once worked for a company who had an IPO and within six months was back in the same financial straits that it had been before. There were rumors about vendors not being paid and paychecks bouncing. I saw the writing on the wall and left, just in the nick of time. The department of Labor padlocked the doors a couple of months after I left. Lots of friends were ruined. I was lucky.
I once worked for a company who had a contract with a government agency. The angency loved the team, but corporate management decided to use that as ammo to raise the rates to the agency. All the bosses came out, told us what great jobs we were all doing and the next thing you know, the entire contracting staff was out on our ears. Got twelve weeks severance though so...
I've been programming professionally for 32 years now and have only been fired once, for demanding that I receive what was owed me (they gave me what they owed me on the way out haha). I have been laid of a few times. Usually you can tell when it's coming because the day to day activity deviates from the norm.
Your otherwise hectic schedule frees up.
No new work comes your way,
you are asked to document everything.
You are asked to train someone.
You are moved to an obscure place or just a less suitable place.
You can't get a straight answer to simple questions.
Your boss won't look you in the eye.
You start to feel isolated.
You get tasks that you know cannot be accomplished within the constraints given (ie six week task in two weeks)
One of your boss's bosses pat's you on the back and tells you you're doing a great job.
Beware of mergers and reorganizations.
Live well below your means.
Stay current with programming technologies.
Never fool yourself into thinking you aren't expendable. Trust me, you are.