One of my main complaints about cs in university is that they didn't teach how to put their effort and energy into their projects in a healthy and sustainable way. Many students ended up learning the 'magic binge' approach you're talking about. It depended on that seemingly random lightning bolt of inspiration combined with almost manic mental energy to work crazy hours to get it done. If you've ever worked through t…
Experiment with coffee. Most commonly I see bingers drinking a LOT of coffee, that's what fuels and in part causes the binge. If that's the case, try going to zero coffee and then every other day, try increasing your coffee intake just a little, with a rest day of no coffee in between, until you find out what actually works best for your productivity. You're looking for optimally consistent, not max output in one sitting. It's got to be consistently repeatable.
Try meditating. I recommend the app headspace if you've never done it. Basically a large part of meditation is deliberate awareness of your thoughts and emotions, the goal being to better understand yourself and what makes you tick. If done consistently, it seems to help people guide their thoughts and emotions in a positive way, which can really help with something like programming.
Exercise. We all know the benefits, a zillion studies have shown it helps you feel motivated, relaxed, improves mood, and think clearly. Seems helpful to me.
Decide to take the pressure off of each work session, regardless of what's going on. Even if it's crunch time and the sky is falling, tell yourself this is not the be-all end-all, that you won't remember this in 5 years let alone 20, and to relax. Choose to be calm, and just focus on making the project a little bit better than when you started.
Go for walks. I separated this out from exercise, because the best benefit of walking is that it takes very little thought, freeing up your brain and giving it space to run around. Sometimes I just let it go bananas, the equivalent of a dog zooming around a back yard. Other times, I'm just washing out everything else by listening to a podcast or an audio book. Or, just putting on music and letting myself feel more and think less. All of these are like a pressure release valve for your mind.
Make a list. Follow that list strictly. Nothing is less emotional than a cold hard list. Not something I recommend all of the time, it can make your thinking rigid, but a very simple and effective tool when that's what you need.