Commit c03a15be authored by Aral Balkan's avatar Aral Balkan
Browse files

Added simple word filtering to avoid potentially insentive random word...

Added simple word filtering to avoid potentially insentive random word combinations (after seeing ‘hate-mongoloid–…’ in one of the codes.
parent 82a39aa1
......@@ -26,7 +26,10 @@ hashids = new Hashids secret
#
hhgttg = JSON.parse fs.readFileSync 'all-unique-words-in-the-hitchhikers-guide.json'
hhgttgPicker = new Picker hhgttg
hhgttgPicker = new Picker hhgttg
# Words in hhgttg that might be insenstive especially when combined with another random word.
wordsToAvoid = {'mongoloid': true, 'buggering': true, 'cock': true}
#
# Implementation of hash sieve algorithm that I read
......@@ -60,15 +63,26 @@ generateCodes = (fromId, toId) ->
count++
process.stdout.write "Generating code ##{count} (ID: #{i}) \r"
code = hashids.encode i
code = "#{hhgttgPicker.pick().toLowerCase()}-#{hhgttgPicker.pick().toLowerCase()}-#{code}"
code = "#{pickWord()}-#{pickWord()}-#{code}"
codes.push code
codes = codes.unique()
assert.equal numCodes, codes.length, 'All codes should be unique.'
console.log "Generated #{numCodes} codes (from ID #{fromId} to ID #{toId})."
if numAvoidedWords > 0
console.log "Avoided #{numAvoidedWords} potentially insensitive words."
return codes
numAvoidedWords = 0
pickWord = ->
word = hhgttgPicker.pick().toLowerCase()
if wordsToAvoid[word]
# console.log "Avoiding word #{word}…"
numAvoidedWords++
word = pickWord()
return word
generateCodesAndSaveToFile = (fromId, toId, fileName) =>
codes = generateCodes fromId, toId
......@@ -81,9 +95,9 @@ generateCodesAndSaveToFile = (fromId, toId, fileName) =>
args = process.argv
if args.count != 3
if args.length != 3
console.log 'Usage: ./h2c2 <number of codes to generate>'
process.exit
process.exit()
numberOfCodesToGenerate = args[2]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment