def in_jupyter_notebook():
    """
    http://stackoverflow.com/questions/15411967/how-can-i-check-if-code-is-executed-in-the-ipython-notebook
    """
    try:
        cfg = get_ipython().config
        #print('cfg = %s' % (ut.repr4(cfg),))
        #x = cfg['IPKernelApp']['parent_appname']
        # might not work if using jupyter-console
        if cfg['IPKernelApp']['connection_file'].count('jupyter'):
            return True
        else:
            return False
    except (AttributeError, NameError):
        return False
http://stackoverflow.com/questions/15411967/how-can-i-check-if-code-is-executed-in-the-ipython-notebook