YMMV, but this seems to work more often when you have been going easy on the buds. Since marijuana has a range of effects on different users, it makes sense that light amounts of THC cause more mental stimulation than heavy use, which is more effective in sedation.

Perhaps the most common reason why it seems you get good ideas when you're stoned is that it removes your normal thought patterns and encourages you to think about a problem from another angle. Unfortunately most of those problems are your typical pothead problems like "How can I make a better paper-towel-tube-filter to hide the smell from my parents" or "What kind of cool bong can I fashion out of common household items to show off to my friends". Now, problems aren't limited to ones these simple. Someone could go further in depth and ask "How can I build a better, low power, fast, portable vaporizer?". But then again, these are by no means the only problems that you may find easier to figure out, It could even be a math problem or that elusive bug in the program you have been writing.

Music and poetry are other good creative outlets to flex your mental muscles, so I would suggest keeping a small notebook nearby so you can write and extrapolate on any fleeting thought that you grab on to. You might be surprised what you came up with after you come down.