I have tried on multiple occasions, on anything from local trains to high-speed long-distance trains. Works very well for me. The landscape passing by is very calming and helps me focus.
I feel you, I couldn't stay awake during lectures and seminars even if it were for my life. Even in small seminars, sitting right next to the professor, i managed to fall asleep for a couple of minutes.
It still sometimes happens that I fall asleep during a meeting. Fact is, meetings ARE boring.
Medical Tests never came up with anything. One thing that did help me, though, was diet changes. Make sure your blood sugar levels remain stable, eat food that releases it's energy slowly and steadily, instead of roller-coaster like. Personally, intermittent fasting helped me getting over the food-coma and hangriness problems.
About the codebase problem, i guess it's just tough to be thrown into large codebases. It takes practice and experience, and it's not necessarily something that university teaches you. Thus, I wouldn't beat myself up over it. It comes with time.
From a practical standpoint, maybe try to find a job in a smaller company with smaller codebase? Or, try to find something where you are involved in starting a project from scratch ? Obviously that requires a bit of luck, but I'd say it's well worth a try.
And the better you get, the less forgiving people are about your small quirks (like, falling asleep in a meeting).