JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
cleanup
[four-random-words.git] / spellcheck.coffee
1 fs = require 'fs'
2 async = require 'async'
3
4 dict = {}
5
6 async.waterfall [
7         (callback) -> async.parallel [
8                 (callback) -> fs.readFile '/etc/dictionaries-common/words', 'utf8', callback
9                 (callback) -> fs.readFile 'my_log_words', 'utf8', callback
10         ], callback
11         ([dictionary, log_words], callback) ->
12                 for word in dictionary.split(/\n/)
13                         dict[word] = true
14                 good = []
15                 for line in log_words.split(/\n/)
16                         word = line[line.lastIndexOf(' ')+1..]
17                         if dict[word]
18                                 good.push word
19                                 if good.length == 8836
20                                         return callback(null, good)
21                 callback 'could find enough real words'
22         (words, callback) ->
23                 for word in words
24                         console.log word
25                 callback()
26         ], (err) ->
27                 if err
28                         console.log err
29                         process.exit 1
30                 process.exit 0