For me personally it helps to just do something else and leave the problem alone. I have had many times where I was stuck during the day on a particular programming problem and during my bike ride home the solution just popped in my head. It sounds a bit contradictory but try to just take a walk outside for example.
Like the others already said it's important to have life outside programming. That sounds obvious and personally for me that's easy to do if things are going well, you are not struggling, banging your head against challenges or having a hard time getting things done before deadlines. But in my own experience I know if these things do start happening it's even more important to take time off. I'm much more productive if I work let's say 40-50 hours a week then 60-70+ hours. Sure in one week I might get more done but I have to stop working out, cancel on a friend etc. and that starts to take it's toll eventually. For me that's the key to not burning out.
And the times I solved programming challenges when I'm not programming or not even actively thinking about programming, it's too many to count.
I live in Amsterdam, so I’m there in December!
Right now I am working on a big (JavaScript) project with a really strict deadline. But still I find myself (and I have a tendency to do so) focussed on all sorts of 'meta' stuff. Refactoring, naming things, restructuring etc. For instance last week I suddenly thought to myself "Maybe I need typing in this project" and started looking at Flow/Typescript and kind of lost myself in it. Now it's easy to say of course just focus on only shipping features, but there are some 'meta stuff' that is important (at least for this project) like unit & integration testing because it handles a lot of sensitive data.
Since this is a community of shippers, I'm curious if you have any tips. How do you balance between shipping features, getting things done before a deadline and maintaining your project in a good state?