Expanding foam insulation is amazing stuff for sealing gaps. The hazard is that it can, as it expands, distort the door or window frame you're trying to seal, which is why they sell low-pressure, low-expansion variants for that application.
Moving in the other direction is an expanding foam called PolyLevel. The stuff is designed to intentionally move whatever's adjacent to the gap it's being sprayed into. Specifically, heavy concrete slabs that have settled over time and are in need of raising. The following video shows how dramatically effective this is. (Warning, turn down your speakers if you're in an office environment.
As designers, we ought be curious about how the world around us is constructed—and how materials can fail over time. To learn about how concrete slabs can fail, check out this video:
Via The Awesomer