Skip to content

Instantly share code, notes, and snippets.

{
"*" : [
["exec", "echo 'exec works!'"],
["eval", "puts 'eval works!'"]
],
"iruby" : [
["eval", "puts 'gems work!'"],
["gem", "metaid"]
],
"metaid": [
# https://porkrind.org/missives/calling-applescript-from-ruby/
def osascript(script)
system 'osascript', *script.split(/\n/).map { |line| ['-e', line] }.flatten
end
# http://stackoverflow.com/questions/5292204/macosx-get-foremost-window-title
osascript <<-END
global frontApp, frontAppName, windowTitle
set windowTitle to ""

The following block renders as ruby even though no language is specified:

def method
  puts "a method!"
end
 :~$ This text is always clobbered by the YARD parser
@kylekyle
kylekyle / doc.rb
Created March 4, 2016 06:27
Dynamically generate docs from a gem
require 'zlib'
require 'yard'
require 'tmpdir'
require 'stringio'
require 'fileutils'
require 'archive/tar/minitar'
io = StringIO.new File.read('sequel-4.32.0.gem')
catch :finished do
@kylekyle
kylekyle / jupyter_kernel.js
Last active March 1, 2016 05:09
How to communicate with a Jupyter kernel directly
Jupyter.notebook.kernel.execute("puts 'hello world'", {
iopub : {
output : function(response) {
console.log(response);
}
}
});
@kylekyle
kylekyle / integration.js
Created January 24, 2016 00:58
A remote script for Jupyter
Jupyter.notification_area.get_widget("notebook").set_message("Extension loaded!");
@kylekyle
kylekyle / status.py
Last active January 23, 2016 18:39
Return a health monitoring status
''' Add to jupyter_notebook_config.py
import sys
sys.path.append("/root/.jupyter/extensions/")
c.NotebookApp.reraise_server_extension_failures = True
c.NotebookApp.server_extensions = ['status']
'''
from notebook.utils import url_path_join
from notebook.base.handlers import IPythonHandler
@kylekyle
kylekyle / custom.js
Last active January 23, 2016 05:28
More tricks
IPython.CodeCell.options_default.cm_config.autoCloseBrackets = false;
setTimeout(function() {
if (window.terminal != undefined) {
window.terminal.term.screenKeys = true;
}
}, 1000);
@kylekyle
kylekyle / tree.json
Created January 23, 2016 03:37
Place in ~/.jupyter/nbconfig/ to make Ruby the default kernel
{
"NewNotebookWidget": {
"default_kernel": "ruby"
}
}
@kylekyle
kylekyle / notebook.json
Last active January 24, 2016 00:57
Editor configuration settings in Jupyter. Save in ~/.jupyter/nbconfig/
{
"load_extensions": {
"integration": true,
"toolmetrics": true
},
"_": "https://codemirror.net/doc/manual.html",
"MarkdownCell": {
"cm_config": {
}
},