If you generally know what your doing and get stuck on something for more then an hour; walk away. Go for a walk; take a shower; take a nap; play a video game, something not coding. Your mind will work on it in the background and you'll figure it out.
In other words; I'm way to old for that stuff anymore, lol...