When you go to bed, your body wants to shut down and rest.
If you eat late, your digestion kicks in again, so your system doesn't properly shut down.
It's this internal activity that causes nightmares ...
... but only in some people. I quite often chow down on pasta late at night.
Tip 1 ... the faster your metabolism, the faster you will burn up your food, and so your body can rest. If you have done exercise during the day, your metabolism will be running quicker, so you might get away with it.
Tip 2 ... avoid things that take a long time to digest, espacially dairy products, which tend to line the stomach and slow down your digestion. The worst late night snack? ... cheese !!