Nowadays I've taken to creating a to-do list before setting out to code and I always make sure to add a couple of tasks that are somewhat simple and I'm sure I can usually complete before bedtime. That way, even when I haven't run through the entire list, I feel like I've gotten something done and the day has not been completely useless. It usually takes some of the edge off any worries I have.