tonic's notebooks

  • My First Playground - /tonic/welcome
    Last edited 3 years ago
    This is a playground to test JavaScript. It runs a completely standard copy of Node.js on a virtual server created just for you. Every one of npm’s 300,000+ packages are pre-installed, so try it out:
  • D3 Example from Beaker - /tonic/d3-example-from-beaker
    Last edited 7 years ago
    Original example using Python here: http://sharing.beakernotebook.com/gist/anonymous/e21582541d7c1fe60eb4
  • API Diff - /tonic/api-diff-example
    Last edited 7 years ago
    Tonic allows you to require multiple versions of the same package, which gives you the unique ability to compare them. Here we'll see what the difference is between ramda 0.9.1 and the latest state of the art:
  • Untitled - /tonic/stream-workbook
    Last edited 7 years ago
    var Promise = require("bluebird").Promise; var Readable = require('stream').PassThrough; var rs = new Readable; rs.push("beep"); rs.push("boo"); var data = await readAtMost(rs, 10); console.log(data); rs.push("boo"); var data = await readAtMost(rs, 100); console.log(data);
  • Untitled - /tonic/webhook-test
    Last edited 7 years ago
    var tonicExpress = require("notebook")("tonic/express-endpoint/1.0.0") // Just provide the exports object to the tonicExpress helper var app = tonicExpress(module.exports) var bodyParser = require('body-parser'); var jsonParser = bodyParser.json(); // Handling Webhooks app.post("/webhook", jsonParser, (req, res) => { // Retrieve the request's body and parse it as JSON //var postData = JSON.parse(req.body); try { res.send(JSON.stringify(req.body)); } catch(e) { console.log(e) } }); // Handling Webhooks app.get("/webhook2", jsonParser, (req, res) => { // Retrieve the request's body and parse it as JSON //var postData = JSON.parse(req.body); try { res.send(JSON.stringify(req.body)); } catch(e) { console.log(e) } });
  • Untitled - /tonic/babel-issue-let-scope-labels
    Last edited 7 years ago
    var transform = require("babel-core").transform; transform(` let x = 10; if (1) { ca: let x = 20; } `, { plugins: require("babel-plugin-transform-es2015-block-scoping") }).code
  • ES6 Classes - /tonic/es6-classes
    Last edited 7 years ago
    Classes are a shorthand that make it easier to work with JavaScript's existin prototypal inheritance.
  • Create a static file server for a given npm package - /tonic/package-server
    Last edited 7 years ago
    module.exports = function(exports, packageName) { var path = require("path") var express = require("express") var tonicExpress = require("notebook")("tonic/express-endpoint/1.0.0") var app = tonicExpress(exports) app.use(require('compression')()) app.use(express.static(path.dirname(require.resolve(packageName)))) return "https://tonicdev.io" + process.env.TONIC_ENDPOINT_PATH }
  • JSON Endpoint Example 2 - /tonic/json-endpoint-example-2
    Last edited 7 years ago
    Send a request like ?url=http://google.com, get back the title of the page.
  • JSON Endpoint Example 1 - /tonic/json-endpoint-example-1
    Last edited 7 years ago
    Send a request to a URL like https://tonicdev.io/tonic/json-endpoint-example-1/branches/master?url=http://google.com, get back the title of the page in the url query parameter.