tonic's notebooks

  • ES6 Template Strings - /tonic/es6-template-strings
    Last edited 7 years ago
    In ES6 you can use template strings to more easily construct strings:
  • ES6 Default, Rest, and Spread - /tonic/es6-default-rest-and-spread
    Last edited 7 years ago
    ES6 adds default and rest parameters to your functions. Default parameters can replace the old method of having to check whether arguments were passed in, then assigning them if they're missing:
  • Maps, WeakMaps, Sets, and WeakSets - /tonic/maps-weakmaps-sets-and-weaksets
    Last edited 7 years ago
    Maps and Sets are new Collections in JavaScript that extend its capabilities beyond just Objects and Arrays. Maps are kind of like objects, but allow you to use *any* object as a key, not just strings:
  • Stars Matrix - /tonic/stars-matrix
    Last edited 7 years ago
    We can use Array.join to quickly get us strings of a repeated character:
  • Stars - /tonic/stars-example
    Last edited 7 years ago
    We can use Array.join to quickly get us strings of a repeated character:
  • Regex Validation - /tonic/regex-validation
    Last edited 7 years ago
    FIrst, make our regex. You can test it in the test area below (when it is green, it matches).
  • "from" Take props - /tonic/from-take-props
    Last edited 7 years ago
    var R = require("ramda"); var filterObj = (fn, obj) => R.pipe(R.toPairs, R.filter(R.apply(fn)), R.fromPairs)(obj); var extract = (keys, obj) => filterObj(R.flip(R.has)(R.zipObj(keys, R.times(R.identity, keys.length))), obj) extract(["a", "b"], { a:5, b: 6, c: 7 }) //x = {a,b} = {a:5,b:6,c:6}
  • Untitled - /tonic/d3-graph
    Last edited 7 years ago
    var R = require("ramda") module.exports = function(nodes, links, options = { }) { options.width = R.has("width", options) ? +options.width : 500; options.height = R.has("height", options) ? +options.height : 300; var JSONObject = { graph: { nodes, links }, width: options.width, height: options.height }; return "<center>" + "<style>.node { stroke: #fff; stroke-width: 1.5px; }" + ".link { stroke: #999; stroke-opacity: .6; }" + "</style>" + "<svg width = " + options.width + " height = " + options.height + " ></svg>" + "<script src='https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js'></script>" + "<script>(" + toHTMLD3Graph + ")(" + JSON.stringify(JSONObject)+ ")</script>"; } module.exports([{ "group":0, "name": 0}, { "group":0, "name": 1}],[{ source:0, target: 1, value:0.9}])
  • Untitled - /tonic/test-mathjax
    Last edited 7 years ago
    mathjax("When $a \\ne 0$, there are two solutions to \\(ax^2 + bx + c = 0\\) and they are\n$x = {-b \\pm \\sqrt{b^2-4ac} \\over 2a}.$")
  • MathJax Viewer - /tonic/mathjax-viewer
    Last edited 7 years ago
    function mathjax(string) { return "<script type=\"text/javascript\" src=\"//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML\"></script><script type=\"text/x-mathjax-config\">MathJax.Hub.Config({tex2jax: {inlineMath: [['#x27;,'#x27;], ['\\\\(','\\\\)']]}});</script><div>" + string + "</div>"; } module.exports = mathjax;