I've recently tried meditating to attempt to be more focused, though I don't think it is really helping.
What has helped (during work anyway) is using the Pomodoro Technique. I have the clock in front of me all the time, and you'd be amazed at how quickly 25 minutes counts down. I treat each Pomodoro like a mini-sprint. I am only allowed to work on one feature during a Pomodoro. I am only allowed to write in one language in a Pomodoro. That forces me to write my tests, and my feature and run the tests etc. etc. I'd much rather be doing that than sitting there staring at the screen because I won't allow myself to surf HN or FB.
As far as being forgetful and being more detail oriented, I haven't found a solution for that yet. I am trying herbal supplements like St. John's Wort, and I think it calms me down a bit (I definitely sleep better and don't grind my teeth as much), but sorry, don't have a good answer for you on that part.