Skip to content

Instantly share code, notes, and snippets.

@pongsh
Created August 2, 2013 07:38
Show Gist options
  • Save pongsh/6138131 to your computer and use it in GitHub Desktop.
Save pongsh/6138131 to your computer and use it in GitHub Desktop.
Retrieves data from the humble bundle website and calculates the average.
<html>
<body>
<div id="info">
</div>
</body>
<script src=http://cdn.pubnub.com/pubnub-3.5.1.min.js ></script>
<script>(function(){
// Init
var pubnub = PUBNUB.init({
subscribe_key : '6b5eeae3-796b-11df-8b2d-ef048cc31d2e'
})
// LISTEN
pubnub.subscribe({
'channel': 'humbledeepsilver_bundle',
'callback': function(m){
data = document.createElement('p');
data.innerHTML = "Total payments: " + m.stats.rawtotal + "\n" +
"Number of purchases: " + m.stats.numberofcontributions.total + "\n" +
"Average: " + m.stats.rawtotal / m.stats.numberofcontributions.total;
info = document.getElementById('info');
info.appendChild(data);
}
})
})();</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment