The problem isn't that you can't focus at all, the problem is that you can't focus on things that aren't exciting, chess is way more exciting than most programming tasks. Everyone can focus on exciting things, but normally you can also focus on things you deem important even if they aren't exciting.
A workaround could be to try competitive programming, I bet that you could focus better there. It isn't really a solution to your problem but maybe it could help you build some skills to make those 30 minutes really count. It might not seem like a lot but 30 minutes goes very far if you have spent a few hours pondering about it before you start.