I second sunshower on the sleep, also eat well, and another possibility for the next time you feel like this can can't focus, go play video games for a bit - really. Sometimes your brain really needs to stop tasking on certain things and, if trying to think is like kicking a dead horse it really means that you're brain is running out of the neurochemicals that it needs in that region and that your brain really needs a rest.
If you ever get stuck in a position where you really can't sleep or lime the feeling off, break the task into components and start working on the most mindless mechanical aspect of it that you can. At least doing that much will help keep you from trying to process more than you can (which, from my past experience, I think I actually did brain-damage during the days where I thought I could make myself do anything with enough bullying). I currently have a job where, often enough its slow but when it rains it pours and there's no place to run at that point. I try to save mental energy for those times and I realize that I have monitor my thoughts and emotional state a great deal to keep my ATP, dopamine, serotonin, etc. within budget. Otherwise - the whole outside of my forehead can start tingling and from there it only goes downhill.
_________________
The loneliest part of life: it's not just that no one is on your cloud, few can even see your cloud.