<commit_before>{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Introduction to Interact.jl"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<script charset=\"utf-8\">(function ($, undefined) {\n",
       "\n",
       "    function createElem(tag, attr, content) {\n",
       "\t// TODO: remove jQuery dependency\n",
       "\tvar el = $(\"<\" + tag + \"/>\").attr(attr);\n",
       "\tif (content) {\n",
       "\t    el.append(content);\n",
       "\t}\n",
       "\treturn el[0];\n",
       "    }\n",
       "\n",
       "    // A widget must expose an id field which identifies it to the backend,\n",
       "    // an elem attribute which is will be added to the DOM, and\n",
       "    // a getState() method which returns the value to be sent to the backend\n",
       "    // a sendUpdate() method which sends its current value to the backend\n",
       "    var Widget = {\n",
       "\tid: undefined,\n",
       "\telem: undefined,\n",
       "\tlabel: undefined,\n",
       "\tgetState: function () {\n",
       "\t    return this.elem.value;\n",
       "\t},\n",
       "\tsendUpdate: undefined\n",
       "    };\n",
       "\n",
       "    var Slider = function (typ, id, init) {\n",
       "\tvar attr = { type:  \"range\",\n",
       "\t\t     value: init.value,\n",
       "\t\t     min:   init.min,\n",
       "\t\t     max:   init.max,\n",
       "\t\t     step:  init.step },\n",
       "\t    elem = createElem(\"input\", attr),\n",
       "\t    self = this;\n",
       "\n",
       "\telem.onchange = function () {\n",
       "\t    self.sendUpdate();\n",
       "\t}\n",
       "\n",
       "\tthis.id = id;\n",
       "\tthis.elem = elem;\n",
       "\tthis.label = init.label;\n",
       "\n",
       "\tInputWidgets.commInitializer(this); // Initialize communication\n",
       "    }\n",
       "    Slider.prototype = Widget;\n",
       "\n",
       "    var Checkbox = function (typ, id, init) {\n",
       "\tvar attr = { type: \"checkbox\",\n",
       "\t\t     checked: init.value },\n",
       "\t    elem = createElem(\"input\", attr),\n",
       "\t    self = this;\n",
       "\n",
       "\tthis.getState = function () {\n",
       "\t    return elem.checked;\n",
       "\t}\n",
       "\telem.onchange = function () {\n",
       "\t    self.sendUpdate();\n",
       "\t}\n",
       "\n",
       "\tthis.id = id;\n",
       "\tthis.elem = elem;\n",
       "\tthis.label = init.label;\n",
       "\n",
       "\tInputWidgets.commInitializer(this);\n",
       "    }\n",
       "    Checkbox.prototype = Widget;\n",
       "\n",
       "    var Button = function (typ, id, init) {\n",
       "\tvar attr = { type:    \"button\",\n",
       "\t\t     value:   init.label },\n",
       "\t    elem = createElem(\"input\", attr),\n",
       "\t    self = this;\n",
       "\tthis.getState = function () {\n",
       "\t    return null;\n",
       "\t}\n",
       "\telem.onclick = function () {\n",
       "\t    self.sendUpdate();\n",
       "\t}\n",
       "\n",
       "\tthis.id = id;\n",
       "\tthis.elem = elem;\n",
       "\tthis.label = init.label;\n",
       "\n",
       "\tInputWidgets.commInitializer(this);\n",
       "    }\n",
       "    Button.prototype = Widget;\n",
       "\n",
       "    var Text = function (typ, id, init) {\n",
       "\tvar attr = { type:  \"text\",\n",
       "\t\t     placeholder: init.label,\n",
       "\t\t     value: init.value },\n",
       "\t    elem = createElem(\"input\", attr),\n",
       "\t    self = this;\n",
       "\tthis.getState = function () {\n",
       "\t    return elem.value;\n",
       "\t}\n",
       "\telem.onkeyup = function () {\n",
       "\t    self.sendUpdate();\n",
       "\t}\n",
       "\n",
       "\tthis.id = id;\n",
       "\tthis.elem = elem;\n",
       "\tthis.label = init.label;\n",
       "\n",
       "\tInputWidgets.commInitializer(this);\n",
       "    }\n",
       "    Text.prototype = Widget;\n",
       "\n",
       "    var Textarea = function (typ, id, init) {\n",
       "\tvar attr = { placeholder: init.label },\n",
       "\t    elem = createElem(\"textarea\", attr, init.value),\n",
       "\t    self = this;\n",
       "\tthis.getState = function () {\n",
       "\t    return elem.value;\n",
       "\t}\n",
       "\telem.onchange = function () {\n",
       "\t    self.sendUpdate();\n",
       "\t}\n",
       "\n",
       "\tthis.id = id;\n",
       "\tthis.elem = elem;\n",
       "\tthis.label = init.label;\n",
       "\n",
       "\tInputWidgets.commInitializer(this);\n",
       "    }\n",
       "    Textarea.prototype = Widget;\n",
       "\n",
       "    // RadioButtons\n",
       "    // Dropdown\n",
       "    // HTML\n",
       "    // Latex\n",
       "\n",
       "    var InputWidgets = {\n",
       "\tSlider: Slider,\n",
       "\tCheckbox: Checkbox,\n",
       "\tButton: Button,\n",
       "\tText: Text,\n",
       "\tTextarea: Textarea,\n",
       "\tdebug: false,\n",
       "\tlog: function () {\n",
       "\t    if (InputWidgets.debug) {\n",
       "\t\tconsole.log.apply(console, arguments);\n",
       "\t    }\n",
       "\t},\n",
       "\t// a central way to initalize communication\n",
       "\t// for widgets.\n",
       "\tcommInitializer: function (widget) {\n",
       "\t    widget.sendUpdate = function () {};\n",
       "\t}\n",
       "    };\n",
       "\n",
       "    window.InputWidgets = InputWidgets;\n",
       "\n",
       "})(jQuery, undefined);\n",
       "</script>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<script charset=\"utf-8\">(function (IPython, $, _, MathJax, Widgets) {\n",
       "    $.event.special.destroyed = {\n",
       "\tremove: function(o) {\n",
       "\t    if (o.handler) {\n",
       "\t\to.handler.apply(this, arguments)\n",
       "\t    }\n",
       "\t}\n",
       "    }\n",
       "\n",
       "    var redrawValue = function (container, type, val) {\n",
       "\tvar selector = $(\"<div/>\");\n",
       "\tvar oa = new IPython.OutputArea(_.extend(selector, {\n",
       "\t    selector: selector,\n",
       "\t    prompt_area: true,\n",
       "\t    events: IPython.events,\n",
       "\t    keyboard_manager: IPython.keyboard_manager\n",
       "\t})); // Hack to work with IPython 2.1.0\n",
       "\n",
       "\tswitch (type) {\n",
       "\tcase \"image/png\":\n",
       "            var _src = 'data:' + type + ';base64,' + val;\n",
       "\t    $(container).find(\"img\").attr('src', _src);\n",
       "\t    break;\n",
       "\tdefault:\n",
       "\t    var toinsert = IPython.OutputArea.append_map[type].apply(\n",
       "\t\toa, [val, {}, selector]\n",
       "\t    );\n",
       "\t    $(container).empty().append(toinsert.contents());\n",
       "\t    selector.remove();\n",
       "\t}\n",
       "\tif (type === \"text/latex\" && MathJax) {\n",
       "\t    MathJax.Hub.Queue([\"Typeset\", MathJax.Hub, toinsert.get(0)]);\n",
       "\t}\n",
       "    }\n",
       "\n",
       "\n",
       "    $(document).ready(function() {\n",
       "\tWidgets.debug = false; // log messages etc in console.\n",
       "\tfunction initComm(evt, data) {\n",
       "\t    var comm_manager = data.kernel.comm_manager;\n",
       "        //_.extend(comm_manager.targets, require(\"widgets/js/widget\"))\n",
       "\t    comm_manager.register_target(\"Signal\", function (comm) {\n",
       "            comm.on_msg(function (msg) {\n",
       "                //Widgets.log(\"message received\", msg);\n",
       "                var val = msg.content.data.value;\n",
       "                $(\".signal-\" + comm.comm_id).each(function() {\n",
       "                var type = $(this).data(\"type\");\n",
       "                if (val[type]) {\n",
       "                    redrawValue(this, type, val[type], type);\n",
       "                }\n",
       "                });\n",
       "                delete val;\n",
       "                delete msg.content.data.value;\n",
       "            });\n",
       "\t    });\n",
       "\n",
       "\t    // coordingate with Comm and redraw Signals\n",
       "\t    // XXX: Test using Reactive here to improve performance\n",
       "\t    $([IPython.events]).on(\n",
       "\t\t'output_appended.OutputArea', function (event, type, value, md, toinsert) {\n",
       "\t\t    if (md && md.reactive) {\n",
       "                // console.log(md.comm_id);\n",
       "                toinsert.addClass(\"signal-\" + md.comm_id);\n",
       "                toinsert.data(\"type\", type);\n",
       "                // Signal back indicating the mimetype required\n",
       "                var comm_manager = IPython.notebook.kernel.comm_manager;\n",
       "                var comm = comm_manager.comms[md.comm_id];\n",
       "                comm.then(function (c) {\n",
       "                    c.send({action: \"subscribe_mime\",\n",
       "                       mime: type});\n",
       "                    toinsert.bind(\"destroyed\", function() {\n",
       "                        c.send({action: \"unsubscribe_mime\",\n",
       "                               mime: type});\n",
       "                    });\n",
       "                })\n",
       "\t\t    }\n",
       "\t    });\n",
       "\t}\n",
       "\n",
       "\ttry {\n",
       "\t    // try to initialize right away. otherwise, wait on the status_started event.\n",
       "\t    initComm(undefined, IPython.notebook);\n",
       "\t} catch (e) {\n",
       "\t    $([IPython.events]).on('status_started.Kernel', initComm);\n",
       "\t}\n",
       "    });\n",
       "})(IPython, jQuery, _, MathJax, InputWidgets);\n",
       "</script>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "using Reactive, Interact"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Interact.jl provides interactive widgets for IJulia. Interaction relies on [Reactive.jl](http://julialang.github.io/Reactive.jl/) reactive programming package. Reactive provides the type `Signal` which represent time-varying values. For example, a Slider widget can be turned into a \"signal of numbers\". Execute the following two cells, and then move the slider. You will see that the value of `signal(slider)` changes accordingly."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [],
      "text/plain": [
       "Slider{Float64}([Input{Float64}] 0.5,\"Slider X:\",0.5,0.0:0.1:1.0)"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],<commit_msg>- Fixes link to canonical URL<commit_after>{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Introduction to Interact.jl"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<script charset=\"utf-8\">(function ($, undefined) {\n",
       "\n",
       "    function createElem(tag, attr, content) {\n",
       "\t// TODO: remove jQuery dependency\n",
       "\tvar el = $(\"<\" + tag + \"/>\").attr(attr);\n",
       "\tif (content) {\n",
       "\t    el.append(content);\n",
       "\t}\n",
       "\treturn el[0];\n",
       "    }\n",
       "\n",
       "    // A widget must expose an id field which identifies it to the backend,\n",
       "    // an elem attribute which is will be added to the DOM, and\n",
       "    // a getState() method which returns the value to be sent to the backend\n",
       "    // a sendUpdate() method which sends its current value to the backend\n",
       "    var Widget = {\n",
       "\tid: undefined,\n",
       "\telem: undefined,\n",
       "\tlabel: undefined,\n",
       "\tgetState: function () {\n",
       "\t    return this.elem.value;\n",
       "\t},\n",
       "\tsendUpdate: undefined\n",
       "    };\n",
       "\n",
       "    var Slider = function (typ, id, init) {\n",
       "\tvar attr = { type:  \"range\",\n",
       "\t\t     value: init.value,\n",
       "\t\t     min:   init.min,\n",
       "\t\t     max:   init.max,\n",
       "\t\t     step:  init.step },\n",
       "\t    elem = createElem(\"input\", attr),\n",
       "\t    self = this;\n",
       "\n",
       "\telem.onchange = function () {\n",
       "\t    self.sendUpdate();\n",
       "\t}\n",
       "\n",
       "\tthis.id = id;\n",
       "\tthis.elem = elem;\n",
       "\tthis.label = init.label;\n",
       "\n",
       "\tInputWidgets.commInitializer(this); // Initialize communication\n",
       "    }\n",
       "    Slider.prototype = Widget;\n",
       "\n",
       "    var Checkbox = function (typ, id, init) {\n",
       "\tvar attr = { type: \"checkbox\",\n",
       "\t\t     checked: init.value },\n",
       "\t    elem = createElem(\"input\", attr),\n",
       "\t    self = this;\n",
       "\n",
       "\tthis.getState = function () {\n",
       "\t    return elem.checked;\n",
       "\t}\n",
       "\telem.onchange = function () {\n",
       "\t    self.sendUpdate();\n",
       "\t}\n",
       "\n",
       "\tthis.id = id;\n",
       "\tthis.elem = elem;\n",
       "\tthis.label = init.label;\n",
       "\n",
       "\tInputWidgets.commInitializer(this);\n",
       "    }\n",
       "    Checkbox.prototype = Widget;\n",
       "\n",
       "    var Button = function (typ, id, init) {\n",
       "\tvar attr = { type:    \"button\",\n",
       "\t\t     value:   init.label },\n",
       "\t    elem = createElem(\"input\", attr),\n",
       "\t    self = this;\n",
       "\tthis.getState = function () {\n",
       "\t    return null;\n",
       "\t}\n",
       "\telem.onclick = function () {\n",
       "\t    self.sendUpdate();\n",
       "\t}\n",
       "\n",
       "\tthis.id = id;\n",
       "\tthis.elem = elem;\n",
       "\tthis.label = init.label;\n",
       "\n",
       "\tInputWidgets.commInitializer(this);\n",
       "    }\n",
       "    Button.prototype = Widget;\n",
       "\n",
       "    var Text = function (typ, id, init) {\n",
       "\tvar attr = { type:  \"text\",\n",
       "\t\t     placeholder: init.label,\n",
       "\t\t     value: init.value },\n",
       "\t    elem = createElem(\"input\", attr),\n",
       "\t    self = this;\n",
       "\tthis.getState = function () {\n",
       "\t    return elem.value;\n",
       "\t}\n",
       "\telem.onkeyup = function () {\n",
       "\t    self.sendUpdate();\n",
       "\t}\n",
       "\n",
       "\tthis.id = id;\n",
       "\tthis.elem = elem;\n",
       "\tthis.label = init.label;\n",
       "\n",
       "\tInputWidgets.commInitializer(this);\n",
       "    }\n",
       "    Text.prototype = Widget;\n",
       "\n",
       "    var Textarea = function (typ, id, init) {\n",
       "\tvar attr = { placeholder: init.label },\n",
       "\t    elem = createElem(\"textarea\", attr, init.value),\n",
       "\t    self = this;\n",
       "\tthis.getState = function () {\n",
       "\t    return elem.value;\n",
       "\t}\n",
       "\telem.onchange = function () {\n",
       "\t    self.sendUpdate();\n",
       "\t}\n",
       "\n",
       "\tthis.id = id;\n",
       "\tthis.elem = elem;\n",
       "\tthis.label = init.label;\n",
       "\n",
       "\tInputWidgets.commInitializer(this);\n",
       "    }\n",
       "    Textarea.prototype = Widget;\n",
       "\n",
       "    // RadioButtons\n",
       "    // Dropdown\n",
       "    // HTML\n",
       "    // Latex\n",
       "\n",
       "    var InputWidgets = {\n",
       "\tSlider: Slider,\n",
       "\tCheckbox: Checkbox,\n",
       "\tButton: Button,\n",
       "\tText: Text,\n",
       "\tTextarea: Textarea,\n",
       "\tdebug: false,\n",
       "\tlog: function () {\n",
       "\t    if (InputWidgets.debug) {\n",
       "\t\tconsole.log.apply(console, arguments);\n",
       "\t    }\n",
       "\t},\n",
       "\t// a central way to initalize communication\n",
       "\t// for widgets.\n",
       "\tcommInitializer: function (widget) {\n",
       "\t    widget.sendUpdate = function () {};\n",
       "\t}\n",
       "    };\n",
       "\n",
       "    window.InputWidgets = InputWidgets;\n",
       "\n",
       "})(jQuery, undefined);\n",
       "</script>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<script charset=\"utf-8\">(function (IPython, $, _, MathJax, Widgets) {\n",
       "    $.event.special.destroyed = {\n",
       "\tremove: function(o) {\n",
       "\t    if (o.handler) {\n",
       "\t\to.handler.apply(this, arguments)\n",
       "\t    }\n",
       "\t}\n",
       "    }\n",
       "\n",
       "    var redrawValue = function (container, type, val) {\n",
       "\tvar selector = $(\"<div/>\");\n",
       "\tvar oa = new IPython.OutputArea(_.extend(selector, {\n",
       "\t    selector: selector,\n",
       "\t    prompt_area: true,\n",
       "\t    events: IPython.events,\n",
       "\t    keyboard_manager: IPython.keyboard_manager\n",
       "\t})); // Hack to work with IPython 2.1.0\n",
       "\n",
       "\tswitch (type) {\n",
       "\tcase \"image/png\":\n",
       "            var _src = 'data:' + type + ';base64,' + val;\n",
       "\t    $(container).find(\"img\").attr('src', _src);\n",
       "\t    break;\n",
       "\tdefault:\n",
       "\t    var toinsert = IPython.OutputArea.append_map[type].apply(\n",
       "\t\toa, [val, {}, selector]\n",
       "\t    );\n",
       "\t    $(container).empty().append(toinsert.contents());\n",
       "\t    selector.remove();\n",
       "\t}\n",
       "\tif (type === \"text/latex\" && MathJax) {\n",
       "\t    MathJax.Hub.Queue([\"Typeset\", MathJax.Hub, toinsert.get(0)]);\n",
       "\t}\n",
       "    }\n",
       "\n",
       "\n",
       "    $(document).ready(function() {\n",
       "\tWidgets.debug = false; // log messages etc in console.\n",
       "\tfunction initComm(evt, data) {\n",
       "\t    var comm_manager = data.kernel.comm_manager;\n",
       "        //_.extend(comm_manager.targets, require(\"widgets/js/widget\"))\n",
       "\t    comm_manager.register_target(\"Signal\", function (comm) {\n",
       "            comm.on_msg(function (msg) {\n",
       "                //Widgets.log(\"message received\", msg);\n",
       "                var val = msg.content.data.value;\n",
       "                $(\".signal-\" + comm.comm_id).each(function() {\n",
       "                var type = $(this).data(\"type\");\n",
       "                if (val[type]) {\n",
       "                    redrawValue(this, type, val[type], type);\n",
       "                }\n",
       "                });\n",
       "                delete val;\n",
       "                delete msg.content.data.value;\n",
       "            });\n",
       "\t    });\n",
       "\n",
       "\t    // coordingate with Comm and redraw Signals\n",
       "\t    // XXX: Test using Reactive here to improve performance\n",
       "\t    $([IPython.events]).on(\n",
       "\t\t'output_appended.OutputArea', function (event, type, value, md, toinsert) {\n",
       "\t\t    if (md && md.reactive) {\n",
       "                // console.log(md.comm_id);\n",
       "                toinsert.addClass(\"signal-\" + md.comm_id);\n",
       "                toinsert.data(\"type\", type);\n",
       "                // Signal back indicating the mimetype required\n",
       "                var comm_manager = IPython.notebook.kernel.comm_manager;\n",
       "                var comm = comm_manager.comms[md.comm_id];\n",
       "                comm.then(function (c) {\n",
       "                    c.send({action: \"subscribe_mime\",\n",
       "                       mime: type});\n",
       "                    toinsert.bind(\"destroyed\", function() {\n",
       "                        c.send({action: \"unsubscribe_mime\",\n",
       "                               mime: type});\n",
       "                    });\n",
       "                })\n",
       "\t\t    }\n",
       "\t    });\n",
       "\t}\n",
       "\n",
       "\ttry {\n",
       "\t    // try to initialize right away. otherwise, wait on the status_started event.\n",
       "\t    initComm(undefined, IPython.notebook);\n",
       "\t} catch (e) {\n",
       "\t    $([IPython.events]).on('status_started.Kernel', initComm);\n",
       "\t}\n",
       "    });\n",
       "})(IPython, jQuery, _, MathJax, InputWidgets);\n",
       "</script>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "using Reactive, Interact"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Interact.jl provides interactive widgets for IJulia. Interaction relies on [Reactive.jl](http://julialang.org/Reactive.jl/) reactive programming package. Reactive provides the type `Signal` which represent time-varying values. For example, a Slider widget can be turned into a \"signal of numbers\". Execute the following two cells, and then move the slider. You will see that the value of `signal(slider)` changes accordingly."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [],
      "text/plain": [
       "Slider{Float64}([Input{Float64}] 0.5,\"Slider X:\",0.5,0.0:0.1:1.0)"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
{'fraction_non_alphanumeric': 0.21463815789473684, 'fraction_numerical': 0.0023757309941520467, 'mean_word_length': 1.510782289515944, 'pattern_counts': {'":': 66, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2537549', 'n_tokens_mistral': 7435, 'n_tokens_neox': 7293, 'n_words': 1547}