I can code on ketamine as long as I'm not doing anything novel nor dealing with something that requires a global, holistic view of a system and its interactions. Once you've done something for long enough it becomes subconscious, so as long as I'm still able to type code in and see what I've typed (to correct all the mistakes lol) it's possible to program while under the influence.
It's like being a junior developer again, blundering through the codebase to fix some problem, which I do through brute-force coding, laser-focused on the goal, heedless of any broader considerations :)
LSD has the opposite problem where it's too easy to go down a refactoring wormhole or just get sucked into the internet because you read something on Medium and needed to know MORE.