Skip to content

Instantly share code, notes, and snippets.

@anvaka
Last active January 16, 2019 14:45
Show Gist options
  • Save anvaka/a9df7d6e573640d148b5 to your computer and use it in GitHub Desktop.
Save anvaka/a9df7d6e573640d148b5 to your computer and use it in GitHub Desktop.
npm modules with highest pagerank

This excercise computes PageRank of npm dependencies graph.

  1. Download all npm modules: wget https://skimdb.npmjs.com/registry/_design/scratch/_view/byField
  2. Convert them into ngraph.graph using convertToGraph.js script.
  3. Run rank.js (see below):

Number of nodes: 123,969; Number of edges: 281,471; PageRank computed in 1,187 ms;

  1. underscore - 0.0132458168541106
  2. lodash - 0.012808245947189859
  3. request - 0.01124548887292648
  4. async - 0.01021872541704812
  5. minimist - 0.007416850477780134
  6. debug - 0.0063426388460246
  7. ms - 0.005713853566335207
  8. commander - 0.005602967220606088
  9. readable-stream - 0.005279385043316346
  10. coffee-script - 0.004722570622623644
  11. optimist - 0.004666371354769678
  12. chalk - 0.004148714607703072
  13. colors - 0.004126358737569487
  14. nan - 0.004006493881364531
  15. express - 0.003940025721262941
  16. q - 0.003850786943940958
  17. yeoman-generator - 0.00379555140778547
  18. inherits - 0.003748721827295395
  19. mkdirp - 0.003691480063872078
  20. through - 0.0036221839261054304
  21. through2 - 0.0034514656168033947
  22. glob - 0.002979874394020952
  23. xtend - 0.0027326243900742237
  24. uglify-js - 0.0023098313251757674
  25. moment - 0.002249874112136482
  26. bluebird - 0.0022252922069381084
  27. wordwrap - 0.0020718821613235163
  28. node-uuid - 0.0020627160971188074
  29. bindings - 0.0019857793086189546
  30. amdefine - 0.001959479557513207
  31. rimraf - 0.001918687193488459
  32. cheerio - 0.0019043660485402569
  33. gulp-util - 0.0018981460908246285
  34. source-map - 0.0018852809976354834
  35. redis - 0.0018594637139311351
  36. isarray - 0.0018220440432625256
  37. es5-ext - 0.0017027234351276802
  38. minimatch - 0.0016839206057532087
  39. jquery - 0.0016550758180527772
  40. xml2js - 0.0016506472503138743
  41. mime - 0.001621778661522743
  42. wrappy - 0.0015909624429127976
  43. windows.foundation - 0.00157602399018788
  44. qs - 0.001501985861094205
  45. mongodb - 0.0014977834307627752
  46. once - 0.0014956419730362738
  47. brace-expansion - 0.001438595161357216
  48. semver - 0.0014309608124292556
  49. sax - 0.0013807343648451979
  50. socket.io - 0.0013674165209619459
  51. esprima - 0.0013416406420303142
  52. jade - 0.0013032043926214701
  53. xmlbuilder - 0.001239612050770304
  54. underscore.string - 0.0012316579970975483
  55. ansi-regex - 0.0012191293061688908
  56. handlebars - 0.0012107063185569928
  57. core-util-is - 0.0012015448533117606
  58. winston - 0.0011757859673551018
  59. hoek - 0.0011748035129163078
  60. grunt - 0.0011661316363914904
  61. nopt - 0.0011654698324087072
  62. string_decoder - 0.0011423305235877623
  63. mongoose - 0.0011058402247590357
  64. jsdom - 0.0010977644107550975
  65. extend - 0.0010807732145026085
  66. superagent - 0.0010761510925892386
  67. mime-types - 0.001051777017875102
  68. connect - 0.0010387743685316797
  69. abbrev - 0.0010300368512824332
  70. iconv-lite - 0.0010068448117545388
  71. es6-symbol - 0.0009700304296423444
  72. pkginfo - 0.0009554849042053358
  73. shelljs - 0.0009494098537727799
  74. mime-db - 0.0009344205293040478
  75. strip-ansi - 0.0009332974405163956
  76. js-yaml - 0.0009211293516341474
  77. ejs - 0.0009101503704715386
  78. graceful-fs - 0.0009100154816892158
  79. promise - 0.000905122298188923
  80. ws - 0.0008965944442138012
  81. mocha - 0.0008850342003560252
  82. fs-extra - 0.0008831021953667824
  83. marked - 0.0008804861013534269
  84. asap - 0.0008637007702030617
  85. escape-string-regexp - 0.0008454335799155875
  86. d - 0.0008450133108992707
  87. form-data - 0.0008300510351767073
  88. get-stdin - 0.0008274849067018161
  89. oauth - 0.0008274380256108579
  90. combined-stream - 0.0008239251856871775
  91. ansi-styles - 0.0008186687052269188
  92. when - 0.0007919792243572224
  93. yosay - 0.0007779586957863931
  94. bl - 0.0007569674379639022
  95. punycode - 0.0007544014325444696
  96. es6-iterator - 0.0007472596867243485
  97. clone - 0.0007348787616316237
  98. htmlparser2 - 0.0007326573048439669
  99. event-stream - 0.0007325110849134281
  100. isstream - 0.0007296274011156147
var fileName = 'graph.out';
var content = require('fs').readFileSync(fileName, 'utf8');
var serializer = require('ngraph.serialization/json');
var pagerank = require('ngraph.pagerank');
var graph = serializer.load(content);
var start = new Date();
var rank = pagerank(graph, 0.85, 0.00000001);
var end = new Date();
console.log("# nodes: ", graph.getNodesCount());
console.log("# edges: ", graph.getLinksCount());
console.log("PageRank computed in %d ms", end - start);
var results = Object.keys(rank).sort(byRank).map(tonpmUrl);
for (var i = 0; i < 100; ++i) {
console.log(i + '. ' + results[i]);
}
function byRank(y, x) {
return rank[x] - rank[y];
}
function tonpmUrl(x) {
return '[' + x + '](https://www.npmjs.org/package/' + x + ') - ' + rank[x];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment