Skip to content

Instantly share code, notes, and snippets.

@program247365
Created August 26, 2014 06:47
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 program247365/df18360384511c5dd0d0 to your computer and use it in GitHub Desktop.
Save program247365/df18360384511c5dd0d0 to your computer and use it in GitHub Desktop.
An idea for a funny Docker based GIF generator.
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
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment