Skip to content

Instantly share code, notes, and snippets.

@devpuppy
Last active August 29, 2015 14:20
Show Gist options
  • Save devpuppy/adeaec2ddcf13e11b51e to your computer and use it in GitHub Desktop.
Save devpuppy/adeaec2ddcf13e11b51e to your computer and use it in GitHub Desktop.
Tools for working with JavaScript gists
function ajax(url, callback) {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
callback(xhr.responseText);
}
}
xhr.open('GET', url, true);
xhr.send();
}
function gist(id, callback) {
var url = 'https://api.github.com/gists/'+id;
ajax(url, function(json) {
var gist = JSON.parse(json);
for (var i in gist.files) {
var file = gist.files[i];
if (file.language == 'JavaScript') {
ajax(file.raw_url, callback);
}
}
});
}
function evalGist(id) {
gist(id, eval);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment