I try to channel my thoughts into something productive and write those thoughts down. I used to keep a notepad beside my bed. There were times that I'd get up from a sound sleep and write for hours on end. The best deal I ever formed was when I was in my 20's, and it was written on notebook paper over a couple of days... when I didn't sleep at all (long periods of not sleeping produce a sort of euphoric state). But if you can't control that sort of behavior, it's likely the first step toward insanity. And if that's the case, I think the best thing to do is to just embrace your crazy. Go with it. Get in tune with it.
Uh... gotta go now. The voices are telling me that the dog wants to be fed.