Skip to content

Instantly share code, notes, and snippets.

@acrogenesis
Last active August 29, 2015 14:15
Show Gist options
  • Select an option

  • Save acrogenesis/60368b9c504ba15ed72a to your computer and use it in GitHub Desktop.

Select an option

Save acrogenesis/60368b9c504ba15ed72a to your computer and use it in GitHub Desktop.

Revisions

  1. acrogenesis revised this gist Feb 12, 2015. 1 changed file with 44 additions and 0 deletions.
    44 changes: 44 additions & 0 deletions timestamp_client.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,44 @@
    <html>
    <head>
    <title>Timestamp</title>
    </head>
    <script>
    var myTimer;
    function getTime(){
    var xmlhttp;
    var span;
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function()
    {
    if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    p = document.createElement("p");
    p.innerText = xmlhttp.responseText
    document.getElementById("timestamps").appendChild(p);
    }
    }
    xmlhttp.open("GET","http://localhost:4567/",true);
    xmlhttp.send();
    }
    function startGetTime(){
    getTime();
    myTimer = setInterval(function(){ getTime(); }, 20000);
    }
    function stopGetTime(){
    clearInterval(myTimer);
    }
    </script>
    <body>
    <button name="button" onclick="startGetTime();">Start</button>
    <button name="button" onclick="stopGetTime();">Stop</button>
    <div id="timestamps">
    </div>
    </body>
    </html>
  2. acrogenesis created this gist Feb 9, 2015.
    6 changes: 6 additions & 0 deletions timestamp_server.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    require 'sinatra'

    get '/' do
    response['Access-Control-Allow-Origin'] = '*'
    Time.now.to_s
    end