What if you only have image URL, but you need attachment ID or different size of image? WordPress by default don’t have a function for retrieve attachment ID from Image URL, but with a few lines of code you can solve it
If you want to detect which menu item has children, this snippet add a class to a menu item if it has children items.
When you work with pages (or posts), sometimes you want to find a top parent ID of a current page or post. This can be useful, for example, if you want to show sub navigation in sidebar.