Skip to content

Instantly share code, notes, and snippets.

@maxvyaznikov
Last active August 29, 2015 14:22
Show Gist options
  • Save maxvyaznikov/8abf6c8f45c56606a34d to your computer and use it in GitHub Desktop.
Save maxvyaznikov/8abf6c8f45c56606a34d to your computer and use it in GitHub Desktop.
<script>
var vals = [];
var last_packets_num = 10;
callback = function(f){
my_ip = f.ip;
setInterval(calc,1000)
}
calc = function(){
var x=new Date
function response_cb(){
vals.push(new Date() - x);
if (vals.length > last_packets_num) {
vals = vals.slice(vals.length - last_packets_num, vals.length);
}
var valssum = vals.reduce(function(prev, cur){ return prev + cur }, 0);
avg = valssum / vals.length;
document.getElementById('out').innerHTML = (my_ip+" / "+avg+" "+vals.length);
}
xx=new XMLHttpRequest;
xx.open('HEAD','http://cdn.jsdelivr.net/jquery/2.1.4/jquery.min.js?x='+Math.random());
xx.send();
xx.onload = response_cb;
xx.onerror = response_cb;
}
</script>
<script src="http://ipinfo.io/?callback=callback"></script>
<div id="out"></div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment