Skip to content

Instantly share code, notes, and snippets.

@dcki
Created March 31, 2016 07:12
Show Gist options
  • Select an option

  • Save dcki/d7b14857f6ca83a85d5cb7b641895f0c to your computer and use it in GitHub Desktop.

Select an option

Save dcki/d7b14857f6ca83a85d5cb7b641895f0c to your computer and use it in GitHub Desktop.
require 'open-uri'
require 'csv'
require 'pry'
file1 = '/tmp/1-1000.txt'
file2 = '/tmp/4000-most-common-english-words-csv.csv'
if File.exist?(file1)
words1 = File.read(file1).split
else
uri1 = URI.parse('https://gist.githubusercontent.com/deekayen/4148741/raw/01c6252ccc5b5fb307c1bb899c95989a8a284616/1-1000.txt')
words1 = uri1.read
File.write(file1, words1)
words1 = words1.split
end
if File.exist?(file2)
words2 = File.read(file2).split
else
uri2 = URI.parse('http://www.rupert.id.au/resources/4000-most-common-english-words-csv.csv')
words2 = uri2.read
File.write(file2, words2)
words2 = words2.split
end
words2.shift
pairs = []
1000.times { pairs << [words1[rand words1.length], words1[rand words1.length]].join(' ') }
1000.times { pairs << [words2[rand words2.length], words2[rand words2.length]].join(' ') }
puts pairs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment