In [5]:

import pandas as pd
#%matplotlib inline
import matplotlib.pyplot as plt




In [6]:

vis = pd.DataFrame({
'cells': [116,117,120,1,52,79,109,27,85,51,78,55,26,39,107],
'photo': [60,67,64,8,13,63,63,2,46,27,43,24,10,28,56]})




In [7]:

graph = []
def graph_all(graph): [g() for g in graph]




In [8]:

def scatter(): return plt.scatter(x=vis.cells, y=vis.photo, color='g')
graph = [scatter]
graph_all(graph)




In [9]:

x_range = vis.cells.min(), vis.cells.max()
y_mean = vis.photo.mean(), vis.photo.mean()
def mean(): return plt.plot(x_range, y_mean, color="brown")
graph.append(mean)
graph_all(graph)



The equations for the slope of the regression line can be constructed as:

$$\hat\beta = \frac{ \operatorname{Cov}[x,y] }{ \operatorname{Var}[x] }$$


In [10]:

slope = vis.cells.cov(vis.photo)/ vis.cells.var()
slope




Out[10]:

0.57225117604575371



The equation for the intercept of the regression line can be construted as:

$$\hat\alpha = \bar{y} - \hat\beta\,\bar{x}$$


In [11]:

intercept = vis.photo.mean() - (slope * vis.cells.mean())
intercept




Out[11]:

-2.2487165973726917



So we can construction the regression line by solving for our expected y:

$$\hat{y} = (slope * x) + intercept$$


In [12]:

vis.expected = (vis.cells * slope) + intercept
vis.expected




Out[12]:

0     64.132420
1     64.704671
2     66.421425
3     -1.676465
4     27.508345
5     42.959126
6     60.126662
7     13.202065
8     46.392633
9     26.936093
10    42.386875
11    29.225098
12    12.629814
13    20.069079
14    58.982159
Name: cells, dtype: float64




In [13]:

def regression(): return plt.plot(vis.cells, vis.expected)
graph.append(regression)
graph_all(graph)



SStotal:



In [14]:

def SStotal(): return [plt.plot((vis.cells[i], vis.cells[i]), (vis.photo.mean(), vis.photo[i]), color='black') for i in range(len(vis))]
graph.append(SStotal)




In [15]:

graph_all(graph)





In [16]:

def SSreg(): return [plt.plot((vis.cells[i], vis.cells[i]), (vis.expected[i], vis.photo[i]), color='red') for i in range(len(vis))]
graph.append(SSreg)
graph_all(graph)



recall that to calculate SStotal we use the formula:

$$SS_{total} = \sum\limits_{x=i}^n(y_{i} - \hat{y})^{2}$$


In [17]:

sum_of_squares = {'total' : ((vis.photo - vis.photo.mean())**2).sum()}
sum_of_squares['total']




Out[17]:

7684.9333333333334




In [18]:

sum_of_squares['regression'] = ((vis.photo - vis.expected)**2).sum()
sum_of_squares['regression']




Out[18]:

974.25824207999085



now r squared is just..

$$R^{2} = 1 - \frac{SS_{regression}}{SS_{total}}$$


In [19]:

r_squared = 1 - (sum_of_squares['regression']/sum_of_squares['total'])




In [20]:

r_squared




Out[20]:

0.8732248934607989




In [1]:




var element = $('#4775530f-2513-4094-b681-81ba109ba052'); var cmd = IPython.keyboard_manager.command_shortcuts; var edit = IPython.keyboard_manager.edit_shortcuts; var def_cmd = IPython.default_command_shortcuts; var def_edit = IPython.default_edit_shortcuts; // get the code mirror editor of a curently selected cell function C() { return IPython.notebook.get_selected_cell().code_mirror; }; // Change the mode of all current and future CodeMirror instances // Emacs users can use this function as just to('emacs') so long as they've // required/loaded emacs.js from CodeMirror function to(mode) { var mode = mode || 'vim' // first let's apply vim mode to all current cells function to_mode(c) { return c.code_mirror.setOption('keyMap', mode);}; IPython.notebook.get_cells().map(to_mode); // apply the mode to future cells created IPython.Cell.options_default.cm_config.keyMap = mode; } function getCSS(path) {$('<link/>', {
rel: 'stylesheet',
type: 'text/css',
href: path,
}

// I messed around with trying to get requireJS going here, but gave up and
// just using this answer from SO
// http://stackoverflow.com/questions/11803215/how-to-include-multiple-js-files-using-jquery-getscript-method

$.when( // Grab the CodeMirror vim keymap$.getScript(p + "../keymap/vim.js"),
// also make search work via /
$.getScript(p + "search/search.js"),$.getScript(p + "search/searchcursor.js"),

// TODO: hook-up gq to perform a harwrap
$.getScript(p + "wrap/hardwrap.js"),$.getScript(p + "selection/active-line.js"),

$.getScript(p + "display/fullscreen.js"), getCSS(p + "display/fullscreen.css"), getCSS(p + "dialog/dialog.css"),$.getScript(p + "dialog/dialog.js"),

$.Deferred(function( deferred ){$( deferred.resolve );
})
).then(function success(){

console.log('Great success');

IPython.CodeCell.options_default.cm_config.foldGutter = true;
IPython.CodeCell.options_default.cm_config.gutters =  ["CodeMirror-linenumbers", "CodeMirror-foldgutter"];

IPython.Cell.prototype.at_top = function () {
var cm = this.code_mirror;
var cursor = cm.getCursor();
if (cursor.line === 0) {
return true;
}
return false;
};

IPython.Cell.prototype.at_bottom = function () {
var cm = this.code_mirror;
var cursor = cm.getCursor();
if (cursor.line === (cm.lineCount()-1)) {
return true;
}
return false;
};
// on all code mirror instances on this page, apply the function f
function all_cm(f) {
// apply f to every code mirror instance. f takes one parameter
IPython.notebook.get_cells().map(function (c) { f(c.code_mirror); } );
}

to('vim');
function vim_up(event) {
var cell = IPython.notebook.get_selected_cell();
if (cell && cell.at_top() && cell.code_mirror.options.keyMap === 'vim') {
event.preventDefault();
IPython.notebook.command_mode()
IPython.notebook.select_prev();
IPython.notebook.edit_mode();
return false;
};
}

function vim_down(event) {
var cell = IPython.notebook.get_selected_cell();
if (cell && cell.at_bottom() && cell.code_mirror.options.keyMap === 'vim') {
event.preventDefault();
IPython.notebook.command_mode()
IPython.notebook.select_next();
IPython.notebook.edit_mode();
return false;
};
}

var m = '(vim) '
var edit_shortcuts = {
'k' : {
help    : m + 'up a line, even across cells',
help_index : 'AA',
handler : vim_up
},
'j' : {
help    : m + 'down a line, even across cells',
help_index : 'AA',
handler : vim_down
},

};

var command_shortcuts = {
'c' :  {
help    : m + def_cmd['y'].help,
help_index : 'AA',
handler : def_cmd['y'].handler
}

};

// N.B. This code looks fairly simple, but it took me forever to
// figure out how to do this,
//
// there's a problem here, Ctrl-[ is already handled by CodeMirror by the time we
// (IPython.keyboard_manager) get it CodeMirror issues signals on mode change,
// so we have to hook into that to get Ctrl-[
edit.remove_shortcut('Ctrl-[');
edit.remove_shortcut('Esc');

CodeMirror.commands.leaveInsertOrEdit = function (cm) {
if ( cm.state.vim.insertMode ) {
// do magic here to get out of insert mode
CodeMirror.keyMap['vim-insert']['Esc'](cm);
} else {
IPython.notebook.command_mode();
IPython.notebook.focus_cell();
}
};

//C().options.extraKeys['Ctrl-['] = 'leaveInsertOrEdit';
all_cm( function (cm) {
cm.options.extraKeys['Ctrl-['] = 'leaveInsertOrEdit';
cm.options.extraKeys['Esc'] = 'leaveInsertOrEdit';
if ( CodeMirror.defaults.extraKeys === null ) {
CodeMirror.defaults.extraKeys = {};
}
// TODO: make this change permanent
// this part seems to be ignore when adding a new cell
// - alternative solution would be to listen for NewCell events and rerun the CM function on it
// - it could also be the case that when we instatiate CodeMirror, we somehow leave out CM.defaults.extraKeys
IPython.CodeCell.options_default.cm_config.extraKeys['Ctrl-['] = 'leaveInsertOrEdit';
IPython.TextCell.options_default.cm_config.extraKeys['Ctrl-['] = 'leaveInsertOrEdit';
IPython.CodeCell.options_default.cm_config.extraKeys['Esc'] = 'leaveInsertOrEdit';
IPython.TextCell.options_default.cm_config.extraKeys['Esc'] = 'leaveInsertOrEdit';
})

// On blur, make sure we go back to command mode for CodeMirror (in case user clicked away)
// TODO: Make this permanent - how to get CodeMirror to do this for new cells created after
all_cm( function (cm) {
cm.on('blur', function(cm) {
// TODO: I wish I understood a better way to do this, but fake pressing Escape work
CodeMirror.keyMap['vim-insert']['Esc'](cm);
CodeMirror.keyMap['vim']['Esc'](cm);
cm.setOption('styleActiveLine', false);
if (cm.getOption("fullScreen")) {
cm.setOption('fullScreen', false);
// fullScreen the newly selected code mirror (doesn't work)
//setTimeout(100, function() {
//    console.log(IPython.notebook.get_selected_cell().code_mirror);
//    IPython.notebook.get_selected_cell().code_mirror.setOption('fullScreen', true);
//});
}
});
cm.on('focus', function(cm) {
cm.setOption('styleActiveLine', true);
});
});

// 'i' by default interrupts the kernel (what Ctrl-C does at the terminal)
cmd.remove_shortcut('i');

// not quite what we want - 'i' requires a double-tap
cmd.add_shortcut('ctrl-c', function(e) { IPython.notebook.kernel.interrupt(); return false});

function focus_last(e) {
var cells = IPython.notebook.get_cells();
cells[cells.length-1].focus_cell();
};

function focus_first(e) {
var cells = IPython.notebook.get_cells();
cells[0].focus_cell();
};

function combo_tap(combo, action) {
var that = this;
var timeout;
function f() {
console.log('f called once');

// redo this so that when an action is performed, we restore the original combo
function() { console.log("doing action", combo); reset(); action(); timeout.clear();} );
timeout = setTimeout(function () {
console.log('resetting f');
reset();
}, 800);
}
function reset(e) {
//cmd.remove_shortcut(combo[0]);
console.log('reset called');
//if (timeout) {
//    console.log('resetting aborted');
//    clearTimeout(timeout);
//    timeout = null;
//}
//that(combo, action);
}
console.log("combo tap for", combo);

reset();
};
combo_tap('gg', focus_first);

// XXX: the way combo tap is currently implemented, this won't work
// need a more generic mechanism for combo-taps with common prefixes
// combo_tap('gq', f();
//cmd.remove_shortcut('d');
// cut
combo_tap('dd', def_cmd['x'].handler);

// copy
combo_tap('yy', def_cmd['c'].handler);

// paste

// undo

// Join (merge down with cell below)

CodeMirror.prototype.save = function() {
IPython.notebook.save_checkpoint()
}

function focus_last(e) {
var cells = IPython.notebook.get_cells();
cells[cells.length-1].focus_cell();
};

function focus_first(e) {
console.log('focus first called');
var cells = IPython.notebook.get_cells();
cells[0].focus_cell();
};

combo_tap('gg', focus_first);

// get rid of the default Ctrl-W binding
// this only works for Firefox
$(document).ready(function() {$(this).bind('keypress', function(e) {
var key = (e.keyCode ? e.keyCode : e.charCode);
if (key == '119' && e.ctrlKey) {
return false;
}
});
});

var press = jQuery.Event("keypress");
press.ctrlKey = false;
press.which = 27; // escape
$(document).trigger(press); event.returnValue = "\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; event.returnValue +="\nX Chrome sucks at captruring Ctrl-W, sorry X"; event.returnValue += "\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; }); // update the keyboard shortcuts IPython.quick_help = new IPython.QuickHelp(); //IPython.CodeCell.options_default.cm_config.styleActiveLine = true; all_cm( function (cm) { cm.setOption('foldGutter', true); cm.setOption('gutters', ["CodeMirror-linenumbers", "CodeMirror-foldgutter"]); cm.options.extraKeys["Ctrl-F"] = function(cm){ cm.foldCode(cm.getCursor()); }; var wrapOptions = {column: 78, killTrailingSpace: true, wrapOn: /\s\S|[^\.\d]/ }; // XXX: add a hardwrap-range to this as well cm.options.extraKeys["F2"] = function(cm) { cm.wrapParagraph(cm.getCursor(), wrapOptions); }; //cm.options.extraKeys["["] = function(cm) { cm.setOption("fullScreen", !cm.getOption("fullScreen"))}; IPython.CodeCell.options_default.cm_config.extraKeys['Ctrl-F'] = function(cm){ cm.foldCode(cm.getCursor()); }; IPython.TextCell.options_default.cm_config.extraKeys['Ctrl-F'] = function(cm){ cm.foldCode(cm.getCursor()); }; // todo - do this for new cells as well // support this a :only? turn off full screen on blur cm.options.extraKeys["F11"] = function(cm) { cm.setOption("fullScreen", !cm.getOption("fullScreen"))}; cm.options.extraKeys["Ctrl-A"] = function(cm) { if (cm.getOption("fullScreen")) cm.setOption("fullScreen", false); }; //all_cm( function (cm) { }); //setTimeout(function() {IPython.notebook.get_selected_cell().set_input_prompt('vim');}, 200)$("#ipython_notebook").find('img').remove('#vim');
$("#ipython_notebook").append('<amp-img layout="responsive" width="500" height="300" id="vim" src="http://www.vim.org/images/vim_on_fire.gif"' // XXX: add it to the distribution // /static/custom/vim_on_fire.gif" + ' style="' + 'position: absolute; left: 51px; top: -10px; height: initial;">')$("#vim").click( function () {$(this).hide()}); // XXX: Autowrapping is kind of broken - you can write a line that will have // its last word (if it's 1 or 2 characters just go back and forth between the // current and the next lines) //all_cm(function (cm) { // var wait, options = {column: 78, killTrailingSpace: true, wrapOn: /\s\S|[^\.\d]/}; // cm.on("change", function(cm, change) { // clearTimeout(wait); // wait = setTimeout(function() { // console.log(cm.wrapParagraphsInRange(change.from, CodeMirror.changeEnd(change), options)); // }, 300); // }); //}); }, function failure() { alert('le sucks, something went wrong'); }); // at_top and at_bottom methods for ipython-vimception /** * @method at_top * @return {Boolean} */ Cell.prototype.at_top = function () { var cm = this.code_mirror; var cursor = cm.getCursor(); if (cursor.line === 0 && cm.findPosV(cursor, -1, 'line').hitSide) { return true; } else { return false; } }; /** * @method at_bottom * @return {Boolean} * */ Cell.prototype.at_bottom = function () { var cm = this.code_mirror; var cursor = cm.getCursor(); if (cursor.line === (cm.lineCount()-1) && cm.findPosV(cursor, 1, 'line').hitSide) { return true; } else { return false; } }; var element =$('#7eac1a79-e82a-4f6e-8c7a-db36ec77d2ec');

var cmd = IPython.keyboard_manager.command_shortcuts;
var edit = IPython.keyboard_manager.edit_shortcuts;
var def_cmd = IPython.default_command_shortcuts;
var def_edit = IPython.default_edit_shortcuts;

// get the code mirror editor of a curently selected cell
function C() { return IPython.notebook.get_selected_cell().code_mirror; };

// Change the mode of all current and future CodeMirror instances
// Emacs users can use this function as just to('emacs') so long as they've
function to(mode) {
var mode = mode || 'vim'
// first let's apply vim mode to all current cells
function to_mode(c) { return c.code_mirror.setOption('keyMap', mode);};
IPython.notebook.get_cells().map(to_mode);
// apply the mode to future cells created
IPython.Cell.options_default.cm_config.keyMap = mode;
}

function getCSS(path) {
$('<link/>', { rel: 'stylesheet', type: 'text/css', href: path, }).appendTo('head'); } // I messed around with trying to get requireJS going here, but gave up and // just using this answer from SO // http://stackoverflow.com/questions/11803215/how-to-include-multiple-js-files-using-jquery-getscript-method var p = "/static/components/codemirror/addon/";$.when(
// Grab the CodeMirror vim keymap
$.getScript(p + "../keymap/vim.js"), // also make search work via /$.getScript(p + "search/search.js"),
$.getScript(p + "search/searchcursor.js"), // TODO: hook-up gq to perform a harwrap$.getScript(p + "wrap/hardwrap.js"),
$.getScript(p + "selection/active-line.js"),$.getScript(p + "display/fullscreen.js"),
getCSS(p + "display/fullscreen.css"),
getCSS(p + "dialog/dialog.css"),
$.getScript(p + "dialog/dialog.js"),$.Deferred(function( deferred ){
$( deferred.resolve ); }) ).then(function success(){ console.log('Great success'); IPython.CodeCell.options_default.cm_config.foldGutter = true; IPython.CodeCell.options_default.cm_config.gutters = ["CodeMirror-linenumbers", "CodeMirror-foldgutter"]; IPython.Cell.prototype.at_top = function () { var cm = this.code_mirror; var cursor = cm.getCursor(); if (cursor.line === 0) { return true; } return false; }; IPython.Cell.prototype.at_bottom = function () { var cm = this.code_mirror; var cursor = cm.getCursor(); if (cursor.line === (cm.lineCount()-1)) { return true; } return false; }; // on all code mirror instances on this page, apply the function f function all_cm(f) { // apply f to every code mirror instance. f takes one parameter IPython.notebook.get_cells().map(function (c) { f(c.code_mirror); } ); } to('vim'); function vim_up(event) { var cell = IPython.notebook.get_selected_cell(); if (cell && cell.at_top() && cell.code_mirror.options.keyMap === 'vim') { console.log('inside the business logic k'); event.preventDefault(); IPython.notebook.command_mode() IPython.notebook.select_prev(); IPython.notebook.edit_mode(); return false; }; } function vim_down(event) { var cell = IPython.notebook.get_selected_cell(); if (cell && cell.at_bottom() && cell.code_mirror.options.keyMap === 'vim') { event.preventDefault(); IPython.notebook.command_mode() IPython.notebook.select_next(); IPython.notebook.edit_mode(); return false; }; } var m = '(vim) ' var edit_shortcuts = { 'k' : { help : m + 'up a line, even across cells', help_index : 'AA', handler : vim_up }, 'j' : { help : m + 'down a line, even across cells', help_index : 'AA', handler : vim_down }, }; var command_shortcuts = { 'c' : { help : m + def_cmd['y'].help, help_index : 'AA', handler : def_cmd['y'].handler } }; edit.add_shortcuts(edit_shortcuts); cmd.add_shortcuts(command_shortcuts); //edit.add_shortcuts('k', def_edit['up'].handler); //edit.add_shortcut('j', def_edit['down'].handler); // N.B. This code looks fairly simple, but it took me forever to // figure out how to do this, // // there's a problem here, Ctrl-[ is already handled by CodeMirror by the time we // (IPython.keyboard_manager) get it CodeMirror issues signals on mode change, // so we have to hook into that to get Ctrl-[ edit.remove_shortcut('Ctrl-['); edit.remove_shortcut('Esc'); CodeMirror.commands.leaveInsertOrEdit = function (cm) { if ( cm.state.vim.insertMode ) { // do magic here to get out of insert mode CodeMirror.keyMap['vim-insert']['Esc'](cm); } else { IPython.notebook.command_mode(); IPython.notebook.focus_cell(); } }; //C().options.extraKeys['Ctrl-['] = 'leaveInsertOrEdit'; all_cm( function (cm) { cm.options.extraKeys['Ctrl-['] = 'leaveInsertOrEdit'; cm.options.extraKeys['Esc'] = 'leaveInsertOrEdit'; if ( CodeMirror.defaults.extraKeys === null ) { CodeMirror.defaults.extraKeys = {}; } // TODO: make this change permanent // this part seems to be ignore when adding a new cell // - alternative solution would be to listen for NewCell events and rerun the CM function on it // - it could also be the case that when we instatiate CodeMirror, we somehow leave out CM.defaults.extraKeys IPython.CodeCell.options_default.cm_config.extraKeys['Ctrl-['] = 'leaveInsertOrEdit'; IPython.TextCell.options_default.cm_config.extraKeys['Ctrl-['] = 'leaveInsertOrEdit'; IPython.CodeCell.options_default.cm_config.extraKeys['Esc'] = 'leaveInsertOrEdit'; IPython.TextCell.options_default.cm_config.extraKeys['Esc'] = 'leaveInsertOrEdit'; }) // On blur, make sure we go back to command mode for CodeMirror (in case user clicked away) // TODO: Make this permanent - how to get CodeMirror to do this for new cells created after all_cm( function (cm) { cm.on('blur', function(cm) { // TODO: I wish I understood a better way to do this, but fake pressing Escape work CodeMirror.keyMap['vim-insert']['Esc'](cm); CodeMirror.keyMap['vim']['Esc'](cm); cm.setOption('styleActiveLine', false); if (cm.getOption("fullScreen")) { cm.setOption('fullScreen', false); // fullScreen the newly selected code mirror (doesn't work) //setTimeout(100, function() { // console.log(IPython.notebook.get_selected_cell().code_mirror); // IPython.notebook.get_selected_cell().code_mirror.setOption('fullScreen', true); //}); } }); cm.on('focus', function(cm) { cm.setOption('styleActiveLine', true); }); }); // 'i' by default interrupts the kernel (what Ctrl-C does at the terminal) cmd.remove_shortcut('i'); cmd.add_shortcut('i', def_cmd.enter); // not quite what we want - 'i' requires a double-tap // add documentation for this. cmd.add_shortcut('ctrl-c', function(e) { IPython.notebook.kernel.interrupt(); return false}); function focus_last(e) { var cells = IPython.notebook.get_cells(); cells[cells.length-1].focus_cell(); }; function focus_first(e) { var cells = IPython.notebook.get_cells(); cells[0].focus_cell(); }; function combo_tap(combo, action) { var that = this; var timeout; function f() { console.log('f called once'); // redo this so that when an action is performed, we restore the original combo cmd.add_shortcut(combo[1], function() { console.log("doing action", combo); reset(); action(); timeout.clear();} ); timeout = setTimeout(function () { console.log('resetting f'); reset(); //cmd.add_shortcut(combo[0], reset) }, 800); } function reset(e) { //cmd.remove_shortcut(combo[0]); console.log('reset called'); //if (timeout) { // console.log('resetting aborted'); // clearTimeout(timeout); // timeout = null; //} //that(combo, action); cmd.add_shortcut(combo[0], f); } console.log("combo tap for", combo); reset(); }; cmd.add_shortcut('shift-g', focus_last); combo_tap('gg', focus_first); // XXX: the way combo tap is currently implemented, this won't work // need a more generic mechanism for combo-taps with common prefixes // combo_tap('gq', f(); //cmd.remove_shortcut('d'); // cut combo_tap('dd', def_cmd['x'].handler); // copy combo_tap('yy', def_cmd['c'].handler); // paste cmd.add_shortcut('p', def_cmd['v']); // undo cmd.add_shortcut('u', def_cmd['z']); // Join (merge down with cell below) cmd.add_shortcut('shift-j', def_cmd['shift-m']) //edit.add_shortcut('k', def_edit['up'].handler); //[edit.add_shortcut('j', def_edit['down'].handler); CodeMirror.prototype.save = function() { IPython.notebook.save_checkpoint() } function focus_last(e) { var cells = IPython.notebook.get_cells(); cells[cells.length-1].focus_cell(); }; function focus_first(e) { console.log('focus first called'); var cells = IPython.notebook.get_cells(); cells[0].focus_cell(); }; cmd.add_shortcut('shift-g', focus_last); combo_tap('gg', focus_first); // get rid of the default Ctrl-W binding // this only works for Firefox$(document).ready(function() {
$(this).bind('keypress', function(e) { var key = (e.keyCode ? e.keyCode : e.charCode); if (key == '119' && e.ctrlKey) { return false; } }); }); window.addEventListener("beforeunload", function( event ) { var press = jQuery.Event("keypress"); press.ctrlKey = false; press.which = 27; // escape$(document).trigger(press);
event.returnValue = "\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
event.returnValue +="\nX  Chrome sucks at captruring Ctrl-W, sorry  X";
event.returnValue += "\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
});

// update the keyboard shortcuts
IPython.quick_help = new IPython.QuickHelp();

//IPython.CodeCell.options_default.cm_config.styleActiveLine = true;

all_cm( function (cm) {
cm.setOption('foldGutter', true);
cm.setOption('gutters',  ["CodeMirror-linenumbers", "CodeMirror-foldgutter"]);
cm.options.extraKeys["Ctrl-F"] = function(cm){ cm.foldCode(cm.getCursor()); };
var wrapOptions = {column: 78, killTrailingSpace: true, wrapOn: /\s\S|[^\.\d]/ };
// XXX: add a hardwrap-range to this as well
cm.options.extraKeys["F2"] =  function(cm) { cm.wrapParagraph(cm.getCursor(), wrapOptions); };
//cm.options.extraKeys["["] =  function(cm) { cm.setOption("fullScreen", !cm.getOption("fullScreen"))};
IPython.CodeCell.options_default.cm_config.extraKeys['Ctrl-F'] = function(cm){ cm.foldCode(cm.getCursor()); };
IPython.TextCell.options_default.cm_config.extraKeys['Ctrl-F'] = function(cm){ cm.foldCode(cm.getCursor()); };

// todo - do this for new cells as well
// support this a :only? turn off full screen on blur
cm.options.extraKeys["F11"] =  function(cm) { cm.setOption("fullScreen", !cm.getOption("fullScreen"))};
cm.options.extraKeys["Ctrl-A"] =  function(cm) {
if (cm.getOption("fullScreen")) cm.setOption("fullScreen", false);
};
//all_cm( function (cm) {
});

//setTimeout(function() {IPython.notebook.get_selected_cell().set_input_prompt('vim');}, 200)

$("#ipython_notebook").find('img').remove('#vim');$("#ipython_notebook").append('<amp-img layout="responsive" width="500" height="300" id="vim" src="http://www.vim.org/images/vim_on_fire.gif"'
// XXX: add it to the distribution
// /static/custom/vim_on_fire.gif"
+ ' style="'
+ 'position: absolute; left: 51px; top: -10px; height: initial;">')
$("#vim").click( function () {$(this).hide()});

// XXX: Autowrapping is kind of broken - you can write a line that will have
// its last word (if it's 1 or 2 characters just go back and forth between the
// current and the next lines)
//all_cm(function (cm) {
//    var wait, options = {column: 78, killTrailingSpace: true, wrapOn: /\s\S|[^\.\d]/};
//    cm.on("change", function(cm, change) {
//      clearTimeout(wait);
//      wait = setTimeout(function() {
//        console.log(cm.wrapParagraphsInRange(change.from, CodeMirror.changeEnd(change), options));
//      }, 300);
//    });
//});

}, function  failure() {

});

// at_top  and at_bottom methods for ipython-vimception
/**
* @method at_top
* @return {Boolean}
*/
Cell.prototype.at_top = function () {
var cm = this.code_mirror;
var cursor = cm.getCursor();
if (cursor.line === 0 && cm.findPosV(cursor, -1, 'line').hitSide) {
return true;
} else {
return false;
}
};

/**
* @method at_bottom
* @return {Boolean}
* */
Cell.prototype.at_bottom = function () {
var cm = this.code_mirror;
var cursor = cm.getCursor();
if (cursor.line === (cm.lineCount()-1) && cm.findPosV(cursor, 1, 'line').hitSide) {
return true;
} else {
return false;
}
};




In [5]:




var element = \$('#c3f7a725-762c-4b55-be0a-958416efceeb');

console.log("hello world")


0
1



In [ ]: