Fixing Mountain Lion and Homebrew issues

Hiya. Like many of you I’ve just installed the brand new OS X version, Mountain Lion, but to my surprise it borked my Homebrew installation, and with it my ImageMagick and even my git. After hours fighting I’ve found the solution to all my problems in a gist…