Skip to content

Instantly share code, notes, and snippets.

@lennym
Created October 3, 2014 14:43
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 lennym/3d4dd51150af1c8d4599 to your computer and use it in GitHub Desktop.
Save lennym/3d4dd51150af1c8d4599 to your computer and use it in GitHub Desktop.
/**
Usage: `node domains.js --file <inputfile.csv>
**/
var fs = require('fs');
var argh = require('argh').argv;
var _ = require('underscore');
var input = argh.file;
fs.readFile(input, function (err, filedata) {
var rows = filedata.toString().split('\n');
var domains = _.map(rows, function (e) {
return e.toLowerCase().split('@')[1];
});
domains = _.countBy(domains, _.identity);
domains = _.map(domains, function (val, key) {
return { domain: key, count: val};
});
domains = _.sortBy(domains, 'count');
domains = _.last(domains, 30);
domains = _.pluck(domains, 'domain');
console.log(domains);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment