Skip to content

Instantly share code, notes, and snippets.

@psychemedia
Last active June 2, 2017 18:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save psychemedia/4a5137cf9a4eddba65c8ff673d19abf2 to your computer and use it in GitHub Desktop.
Save psychemedia/4a5137cf9a4eddba65c8ff673d19abf2 to your computer and use it in GitHub Desktop.
nbdiffex - nbdiff-web extension for Jupyter notebook
// call "nbdime" and compare current version with new version in new tab
define([
'base/js/namespace',
'jquery',
'base/js/events',
'base/js/utils'
], function(IPython, $, events, utils) {
"use strict";
/**
* Call nbdiff-web with current notebook against checkpointed version
*
*/
var nbCheckpointDiffView = function () {
var kernel = IPython.notebook.kernel;
var name = IPython.notebook.notebook_name;
var path= IPython.notebook.notebook_path
var base_url=window.location.protocol + '//' +window.location.hostname
var abspath='/vagrant/notebooks'
var hostport='35101'
var guestport='8899'
var url = base_url+':'+hostport+'?remote='+abspath+'/.ipynb_checkpoints/'+utils.splitext(name)[0]+'-checkpoint.ipynb&base='+abspath+'/'+path;
var command = 'import subprocess; subprocess.run(\'nbdiff-web --port='+guestport+' --ip=* \', shell=True)';
kernel.execute(command);
window.open(url);
$('#doCheckpointDiffView').blur();
};
var load_ipython_extension = function() {
IPython.toolbar.add_buttons_group([
{
id: 'doCheckpointDiffView',
label: 'Display nbdiff to checkpointed version',
icon: 'fa-list-alt',
callback: nbCheckpointDiffView
}
]);
};
return {
load_ipython_extension : load_ipython_extension
};
});
Type: IPython Notebook Extension
Name: Checkpointdiffer
Description: Calls nbdiff with current notebook and checkpointed version
Link: readme.md
Compatibility: 4.x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment