Here is my take on productivity. Productivity is something everyone can achieve, even the laziest of people out there. Productivity is not a mind-set or some magical inner state you need to reach. Productivity is the act of doing actions.
You can be productive by doing a simple task such as making your bed in the morning. I like to call these actions push notifications. Making your bed in the morning is a mini achievement and can give you the necessary productive push you were looking for. You are giving yourself a push notification to “push” on. Constantly doing little tasks and achieving them is a self-rewarding process that further inspires more productivity. The more you are on the lookout to complete little challenges the more you will be productive.
Transfer this mind-set over to bigger more time consuming tasks. Just do it. Don't fool yourself. If you tell yourself that you will not go to bed before you have done a certain task, that mind-set will get you far really quickly. You will see results within days.
So, general approach:
How does this relate to coding? If you can be productive at life you can be productive at coding!