No it's not easy, but removing distractions helps keep you on track.
A lot of people on HN I've heard say they use a web filter on themselves. Only allowing most web sites for certain times of day, otherwise they're locked down to "productive" web sites.
Also, when you're looking for something new to learn instead of picking a new breadth topic, pick a depth topic you don't know about and learn about in one of your hand picked languages. Like if you're learning about networking or machine learning, use a language that you want to know better, but have "lost interest" in instead of one you already know well.
I think it's not that easy in all cases. However, I already practice the food use-case you've mentioned (I simply don't buy unhealthy food).