I need to remember not to code right up until I go to bed. When I do that, I tend to dream about code, which usually wakes me up in the middle of the night (as it did last night) because my mind is racing, trying to solve some problem that's half real and half dream.
My usual solution is to watch TV for about 30 minutes before I go to bed in order to numb my brain.