add utility function to check whether code is run inside an ipython notebook

See https://github.com/astropy/astropy/pull/2789