Created
August 26, 2014 06:47
Revisions
-
program247365 created this gist
Aug 26, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,86 @@ var http = require('http'); var util = require('util'), left = ["happy", "jolly", "dreamy", "sad", "angry", "pensive", "focused", "sleepy", "grave", "distracted", "determined", "stoic", "stupefied", "sharp", "agitated", "cocky", "tender", "goofy", "furious", "desperate", "hopeful", "compassionate", "silly", "lonely", "condescending", "naughty", "kickass", "drunk", "boring", "nostalgic", "ecstatic", "insane", "cranky", "mad", "jovial", "sick", "hungry", "thirsty", "elegant", "backstabbing", "clever", "trusting", "loving", "suspicious", "berserk", "high", "romantic", "prickly", "evil"], right = ["lovelace", "franklin", "tesla", "einstein", "bohr", "davinci", "pasteur", "nobel", "curie", "darwin", "turing", "ritchie", "torvalds", "pike", "thompson", "wozniak", "galileo", "euclid", "newton", "fermat", "archimedes", "poincare", "heisenberg", "feynman", "hawking", "fermi", "pare", "mccarthy", "engelbart", "babbage", "albattani", "ptolemy", "bell", "wright", "lumiere", "morse", "mclean", "brown", "bardeen", "brattain", "shockley"]; namesgenerator = function(checker) { var name, retry = arguments.length > 1 && typeof arguments[1] == 'number' ? arguments[1] : 5; name = util.format('%s+%s', randelem(left), randelem(right)); sterm = util.format('%s', randelem(left)); while (checker && checker(name) && retry) { name = util.format('%s%d', name, randnum(10)); retry--; } return retry ? name : null; }; function randnum(n) { var min = 0, max = n; return Math.floor(Math.random() * (max - min + 1) + min); } function randelem(a) { return a[randnum(a.length)]; } var names = {} , i , name ; var checker = function(name) { return names.hasOwnProperty(name); }; for (i = 0; i < 1; i++) { name = namesgenerator(checker); if (name) { // console.log(name); //The url we want is: 'www.random.org/integers/?num=1&min=1&max=10&col=1&base=10&format=plain&rnd=new' var options = { host: 'api.giphy.com', path: '/v1/gifs/search?q=' + sterm + '&api_key=dc6zaTOxFJmzC&limit=1' }; callback = function(response) { var str = ''; //another chunk of data has been recieved, so append it to `str` response.on('data', function (chunk) { str += chunk; }); //the whole response has been recieved, so we just print it out here response.on('end', function () { var json = JSON.parse(str); if (json.data[0] !== undefined) { var image = json.data[0].images.fixed_height.url; var json = { name: name, image: image }; if(image) { console.log(json); } else { console.log('nope'); } } }); } http.request(options, callback).end(); } else { return { name: name, image: image }; } }