Skip to content

Instantly share code, notes, and snippets.

@JakubOboza
Created February 9, 2012 15:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JakubOboza/1780601 to your computer and use it in GitHub Desktop.
Save JakubOboza/1780601 to your computer and use it in GitHub Desktop.
gravatar link generator
#!/usr/bin/env node
var email = process.argv[2];
var crypto = require('crypto');
function trim (str) {
var str = str.replace(/^\s\s*/, ''),
ws = /\s/,
i = str.length;
while (ws.test(str.charAt(--i)));
return str.slice(0, i + 1);
}
if(process.argv.length !== 3){
console.log("usage: gravatar <email>");
}else{
var md5sum = crypto.createHash('md5');
md5sum.update(trim(email).toLowerCase());
var hash = md5sum.digest('hex');
console.log("http://www.gravatar.com/avatar/" + hash);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment