Take it from a pro:
Drink caffeine, but don't overdo it. Otherwise you're too restless to get any actual work done. Learn and keep in mind your tolerance. A cup of coffee every few hours ought to do the trick. Caffeine is still not the sole resolution. The mental idea of "I'm drinking coffee, I'm staying well awake" is more important than the chemical reaction alone. Sometimes caffeine feels almost counterproductive and it's quite easy to go to sleep straight after an energy drink or something.
Keep your environment cool. Your brain works better and you won't feel drowsy
Eating food is a lot more powerful component in building a day rhythm than caffeine. Keep eating normally. Staying awake, especially at night time, requires a lot more energy than sleeping, so you have to eat to keep the energy levels up. Don't eat too much at once though, that should go without saying.
Drink. Water, coke, juices, whatever you usually drink. It's important to keep the energy levels up. This kind of goes hand-in-hand with the eating, except you should constantly have something to drink next to you.
Do not do anything that belongs to your regular going-to-sleep -ritual: brushing teeth, wearing what you wear when going to bed. Whatever you tend to do within an hour or so before going to sleep... Don't do any of it. Even if it seems not that big of a deal, it can have major mental and subconscious effects.
In interrelation to the previous: Do things that you would do during the day. Feel like cooking something easy at 4 AM. Just do it. Wear your regular leisure clothes you would during the day
If you smoke cigarettes, you'll be even more likely to smoke when you are tired and/or need/want to stay awake. Smoking does it's own things, but going out for a couple of minutes every now and then works wonders. It's really effective, and people who don't smoke underestimate the power of fresh air, no pun intended. Take short breaks outside.
If you're familiar with the Flow [http://en.wikipedia.org/wiki/Flow_(psychology)]-concept, do your very best to get into that. Immersing yourself within the task at hand and the bombardment of ideas and handling them is perhaps the most effective method of staying awake. Do whatever improves your concentration.
Keep an active mind. Don't move to watching a simple comedy while you eat. If you're only observing, you're brain is not far from sleeping. Active thinking, coming up with ideas and bouncing them around works wonders, and often has a positive avalanche-effect. This is important as well. If you're
Do not touch your eyes. Do not rub them. Don't do anything to them, even if they feel itchy or irritated, just no. They're so sensitive that basically every touch just irritates them more. That might sound a bit silly, but it's true. And anyone who has ever fought against falling asleep knows that it's the eyes that go first. You might even feel energetic enough otherwise, but seriously, stay away from the eyes. Taking a shower takes its toll on the eyes too. Wouldn't recommend taking showers anyways.