One explanation for this unusual behavior was offered in the Reddit thread discussing the gif:
Snake-owner here. One reason snakes do this is because they are agitated from getting too hot. Judging by the fact the snake is in the water bowl I would suspect this is the reason. EDIT: Snakes are cold blooded so their metabolic rate is controlled by how they regulate their body temperature, a hot snake has an increased metabolism and would likely feel hungry if it hasn't eaten recently, which could drive this behaviour. Turning off the heat-lamp and spraying them with cool water will cause them to spit themselves out. I hope in this case it was ok :(Another example was posted in 2009. For details about the mythical Ouroboros, see my 2008 post.