Skip to content

Instantly share code, notes, and snippets.

@jamesflorentino
Forked from tristanperalta/gist:9149560
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamesflorentino/9149594 to your computer and use it in GitHub Desktop.
Save jamesflorentino/9149594 to your computer and use it in GitHub Desktop.
node_modules
require('http').get('http://www.reddit.com/r/showerthoughts.json', function(res) {
var body = '';
res.setEncoding('utf8');
res.on('data', function(chunk) {
body += chunk;
});
res.on('end', function() {
var data;
try {
data = JSON.parse(body);
} catch(err) {
throw err;
}
var children = data.data.children;
var total = children.length;
var randomItem = children[Math.round(Math.random() * (total - 1))];
console.log(randomItem.data.title);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment