1. Keep your phone on silent (or shut off) in a different room than your office (or wherever you're trying to work)
2. Install an app like Refine on your phone and block all social media and sites that you open up frequently (HN would possibly be an example)
3. Keep your phone in a different room before going to sleep.
4. If you like listening to audiobooks, consider getting an Amazon Echo. I like to listen to audiobooks before falling asleep and with the Echo you can set a sleep timer and then play an audiobook and it will stop playing after the sleep timer expires.
5. On your laptop (assuming you use Mac or Linux) add social media and other frequently visited non-productivity related sites to your /etc/hosts file.
Personally I try to avoid drugs for these kinds of things. In my view it's a matter of self improvement and self-discipline which are things that can be developed with effort.