I really like your point about motivation.
I'm a freelancer and working from home, and I used to think that nutrition, physical activity etc has a lot to do with it. Yeah sure it does but recently I think at the end of the day, it's just about will power and deep, personal motivation. If you are not enjoying it, no diet will make you more motivated or energetic. It's about an ability to say firm 'no' to distractions. Especially the 'short' ones, because they never tend to be short [0].
Sometimes there is just shit that needs to be done. I mean ugly stuff, like code written by someone else and you have no idea how does it even work in first place or think that the the other programmer was drunk when coding it. Something that your mind says 'I didn't signed up for this shit!'. You just have to focus on it, and get it done. No 'just going to starbucks downstairs', or 'just a cigarette' will help.
Actually, I think one of the best indicator of maturity of software engineer is dealing with unpleasant tasks. Less mature developers try to delay it to the last minute (when bad comes to worse), or impulsively suggest re-writing everything from scratch, etc. Mature developers just get their shit together and get it done.
[0] Once I noticed that the biggest productivity killers are longer than 5min breaks because once you are away, it's so tempting to do one more thing, and then another. I blogged about it "It's all about the short breaks" http://blog.gedrap.me/blog/2014/02/09/its-all-about-the-shor...