def snip(tag="",start=-2,write_date=True):
    """ 
        This function records a previously execute notebook cell into a file (default: ipython_history.py)

        a tag can be added to sort the cell

        `start` defines which cell in the history to record. Default is -2, ie. the one executed previously to the current one.

    """
    import IPython
    i = IPython.get_ipython()
    last_history = i.history_manager.get_range(start=start,stop=start+1,output=True)
    with open("ipython_history.py",'a') as output_file:
        for l in last_history:
            global _session_description
            output_file.write('\n\n\n'+('#'*80)+'\n')
            if _session_description != "":
                output_file.write('#\n'+_lines_as_comments(_session_description)+'\n#\n')
            if tag != "":
                output_file.write(_lines_as_comments(tag)+'\n')
            if write_date:
                import datetime
                output_file.write('# '+datetime.datetime.now().isoformat()+'\n')
            output_file.write('\n\n# In ['+str(l[1])+']:\n'+l[2][0])
            _last_inputs.append(l[2][0])
            _tagged_inputs[tag] = _tagged_inputs.get(tag,[])
            _tagged_inputs[tag].append(l[2][0])
            output_file.write('\n\n# Out ['+str(l[1])+']:\n'+_lines_as_comments(repr(l[2][1])))
This function records a previously execute notebook cell into a file (default: ipython_history.py)

        a tag can be added to sort the cell

        `start` defines which cell in the history to record. Default is -2, ie. the one executed previously to the current one.