From: Jason Woofenden Date: Thu, 8 Nov 2012 07:35:26 +0000 (-0500) Subject: coffeescript to filter by huge wordlist X-Git-Url: https://jasonwoof.com/gitweb/?p=four-random-words.git;a=commitdiff_plain;h=7c24dcf3c6ad901f09c2951190f5eb3536c6ae5e coffeescript to filter by huge wordlist --- diff --git a/spellcheck.coffee b/spellcheck.coffee new file mode 100644 index 0000000..0779356 --- /dev/null +++ b/spellcheck.coffee @@ -0,0 +1,30 @@ +fs = require 'fs' +async = require 'async' + +dict = {} + +async.waterfall [ + (callback) -> async.parallel [ + (callback) -> fs.readFile '/etc/dictionaries-common/words', 'utf8', callback + (callback) -> fs.readFile 'my_log_words', 'utf8', callback + ], callback + ([dictionary, log_words], callback) -> + for word in dictionary.split(/\n/) + dict[word] = true + good = [] + for line in log_words.split(/\n/) + word = line[line.lastIndexOf(' ')+1..] + if dict[word] + good.push word + if good.length == 8836 + return callback(null, good) + callback 'could find enough real words' + (words, callback) -> + for word in words + console.log word + callback() + ], (err) -> + if err + console.log err + process.exit 1 + process.exit 0