Skip to content

Instantly share code, notes, and snippets.

@AlexZeitler
Forked from MikeBild/cpu-bound.js
Created October 25, 2016 11:18
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 AlexZeitler/5aaf09356ef20300e10f6feb49d09fb8 to your computer and use it in GitHub Desktop.
Save AlexZeitler/5aaf09356ef20300e10f6feb49d09fb8 to your computer and use it in GitHub Desktop.
Node.js - CPU bound operations with Rx
const RxNode = require('rx-node');
const Rx = require('rx');
const spawn = require('child_process').spawn;
RxNode.fromStream(spawn('find', ['/','-type','f','-exec', 'cat', '{}', '\+']).stdout)
.map(x => x.toString())
.map(x => RxNode.fromStream(spawn('./word-count.js', [x]).stdout))
.mergeAll()
.map(x => x.toString())
.do(x => console.log(x))
.subscribe();
#!/usr/bin/env node
const index = {};
process.argv[2]
.replace(/[.,?!;()"'-]/g, ' ')
.replace(/\s+/g, ' ')
.toLowerCase()
.split(' ')
.forEach(function (word) {
if (!(index.hasOwnProperty(word))) index[word] = 0;
index[word]++;
});
console.log(index)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment