I'd break the suggested strategies into a few general categories. You can be so intrinsically motivated that you never really encounter this problem in the first place (1). You can play psychological games to try and make it harder to lose interest (2, 3, 4, 8, 9). You can alter the workload in a way that makes it more interesting, but may cause quality to suffer (5, some 7, 10, 11, 12). You can rearrange the work in a way that actually creates more work, but also helps it stay interesting for longer (6, some 7, 10, 11, 12).
I find that those last two categories tend to go hand-in-hand in programming, too. So finding ways to help yourself just muscle through the boring part really is preferable in a professional setting.
OTOH, for fun projects, both sock knitting (and mittens) and development, I tend to go for those latter strategies. The corollary here is that I try not to knit socks for others, and you probably shouldn't take a dependency on anything I'm not getting paid to write.