I've been recently working on a personal project, and what works for me is defining a relatively small feature that I could implement, implement it and then stop here. For exemple yesterday was parsing. I focused on parsing "let x = <an integer>;", and that's it. This helps me have a sense of progress and build confidence. This is also an application of the technique where you stop working when you're in the flow compared to when you encounter a stopping point. This also helps reduce my anxiety about having to do it again since I know that until now I've been able to complete what I wanted, and again, builds confidence.
I also try to take my sleep seriously, which I think helps. My diet and exercise regimen are lacking, but improving them would probably help too.
> Sometimes, however, I spend a lot of time just staring at a keyboard, unable to type what I want to type.
TDD helps here. I find that often the most difficult thing is to start, and starting by writing a test is way easier for me than starting by writing the implementation.