1) You could try doing TDD. Each passing test will give you instant gratification. You could even try doing Acceptance Test-Driven Development. Basically you start by writing end-to-end test and implementing minimal code to make it pass. After that you will go one level deeper etc. I would suggest reading "Growing Object-Oriented Software Guided by Tests", this will give you a good overview of the method.
2) Also, if you can choose language to work with, you can try languages that allow you to work in the REPL. That way you can have instant feedback loop and feel satisfied even when you get some small functions working.
3) Pomodoro technique.