Lately, I've started doing Khan Academy's "World of Math" while I wait for builds or tests or deploys. It's basically over 1000 exercises that encompass all of math you'd learn if you weren't a math major: from counting up through differential equations. Some of it is absurdly easy, some of it is a nice refresher, a few things I forgot how to do and there is of course a perfect explanation included. It's possible to make meaningful progress in a minute or two, so perfect for those little build breaks.
Generally when I get stuck I go into emacs org mode and just use it to brainstorm about what to do next. If that doesn't work I close my eyes and try and meditate for 30 seconds before trying again.