Skip to content

Instantly share code, notes, and snippets.

@mohayl
Forked from anonymous/fiddle.css
Created March 11, 2018 09:30
Show Gist options
  • Save mohayl/68632bcf8933affddf893a429b2953fe to your computer and use it in GitHub Desktop.
Save mohayl/68632bcf8933affddf893a429b2953fe to your computer and use it in GitHub Desktop.

Revisions

  1. @invalid-email-address Anonymous created this gist Mar 11, 2018.
    24 changes: 24 additions & 0 deletions fiddle.css
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    #main {
    width: 400px;
    }

    #container {
    width: 400px;
    }

    #answer {
    font-color: red;
    font-size: 18pt;
    }

    body {
    background: #FFFFFF;
    font-family: 'Open Sans', sans-serif;
    }

    .logo_container {
    margin-top: 5px;
    margin-bottom: 6px;
    float: left;
    width: 200px;
    }
    16 changes: 16 additions & 0 deletions fiddle.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    <h2>MATLAB Production Server (JSON request example)</h2>
    <div id="main">
    <label><span>Compute the Nth Fibonacci number (Please enter N):</span>
    <input type="text" class="n" name="fn">
    </label>
    <input type="button" value="submit">
    </div>
    <div id="container">
    <p>Result from MATLAB:</p>
    <div id="answer"></div>
    </div>
    <div class="logo_container hidden-xs hidden-sm">
    <a href="http://www.mathworks.com/index.html?s_tid=gn_logo" class="svg_link pull-left">
    <img src="http://www.mathworks.com/images/responsive/global/pic-header-mathworks-logo.svg" class="mw_logo" alt="MathWorks">
    </a>
    </div>
    41 changes: 41 additions & 0 deletions fiddle.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    $(document).ready(function() {
    $('input:button').click(function() {
    if (isNumeric($("input:first").val()) == true) {

    /* Call MATLAB Production Server */
    var n = Number($("input:first").val());
    computeFibonacciMPS(n);

    } else {
    $('#answer').text("Input needs to be numeric!");
    }

    });
    });

    /* Function to compute Fibonacci series on MATLAB Production Server */
    function computeFibonacciMPS(n) {
    /* Create a simple AJAX request to the MATLAB Production Server */
    $.ajax({
    url: 'http://ec2-34-206-1-112.compute-1.amazonaws.com:31415/example/fibonacci',
    type: "POST",
    data: JSON.stringify({
    "rhs": n,
    "nargout": 1
    }),
    contentType: 'application/json',
    success: function(data) {
    /* Parse the response when ready */
    $('#answer').text(data.lhs[0].mwdata[0]);
    $('#answer').effect("highlight", {
    color: "#FFFF00"
    }, 1000);
    //console.log(data);
    }
    });
    }

    /* Helper function to determine if input is numeric */
    function isNumeric(n) {
    return !isNaN(parseFloat(n)) && isFinite(n);
    }