How good are your sleeps? Are you drinking enough water?
I know that I get brain fog if I sleep poorly or forget to drink enough water.
For coding, I try to explain to myself exactly what I am trying to solve using the most simple explanation possible.
Usually, the program will perform a series of steps. I work on each step, in code, until I solve that step. Then I move on to the next step. Divide and conquer.
Like the other person asked, have you sought out professional help for any possible medical issues? If you have ADHD then a professional can give reliable guidance on how to compensate for the main ADHD symptoms.
Good luck! You CAN do it!!!
In 1999, I bet he was running Gentoo.