You're hammering away at a particularly hairy bit of code (or any other problem). You know exactly what you want it to do, but are just struggling to translate it into the right language. After hours of wrangling with convoluted logic and endless cycles of edit-build-debug-rinse-repeat, you throw your hands in the air, give up and walk away.
And then suddenly, while cooking dinner, or watching a movie, or in the shower thinking of what manner of pasta to snarf down for lunch, or simply just on the can focussing on your business -- it hits you. A brilliant solution to the hair-puller-outer, so elegant and so bloody simple you wonder how you never thought of it in the first place.
You scribble a quick note in your head (or Evernote, or a notepad, or whatever) and suddenly nothing else will do except firing up vim and set things straight right away. You do it.
The final turn on the safe -- maybe something audibly goes "click" in your head -- and it's done. You step back and marvel in the beauty of it. You can feel the mystery briefcase glow on your face, a la Pulp Fiction. All is right in the world again. You are the master of all you survey - there is no mystery you cannot solve, no stream you cannot ford.
You are also not me.
Maybe I am slowly gathering up enough work experience, or maybe I'm just getting older and my mind is atrophying, but while the initial frustration and subsequent elation are still very firmly in place, the "eureka!" appears to be happening a lot less these days. Instead, what I find works most of the time is just plugging away at the issue, continuously breaking it down into smaller bits, and gradually piecing the solution together from these little digested chunks.
"Solution epiphanies" strike about two or three times out of ten, down from 6-7 out of ten from back in the day [when we wrote our code with styluses on papyrus and prayed to Ra to compile it into machine code via heliography]. The adrenaline and oxytocin rush is still phenomenal, but I find myself needing them less and less, since I can be more objective about the side effects and just more productive overall.
I still end up getting celebratorily hammered over the next weekend though.