Skip to content

Instantly share code, notes, and snippets.

@fetimo
Created May 24, 2017 21:10
Show Gist options
  • Save fetimo/a4336e4d070b8cfd9ad515b8ed940320 to your computer and use it in GitHub Desktop.
Save fetimo/a4336e4d070b8cfd9ad515b8ed940320 to your computer and use it in GitHub Desktop.
Spelling test
require 'httparty'
WORDS = [
'quixotic',
'abstemious',
'piquancy',
'potentate',
'proselytized',
'parricide',
'épater',
'Encomium',
'proscription',
'evinces',
'en passant',
'abstruse',
'invective',
'eudaimonia',
'asceticism',
'mendicant',
'indigence',
'epideictic',
'antithetical',
'truculence',
'recuse',
'otiose',
'ostentation',
'disquisition',
'supererogatory',
'apposite',
'patrimony',
'inimical',
'avaricious',
'piquant',
'licentious',
'meting',
'Apropos',
'malapropisms',
'peroration',
'impudence',
'tetrad',
'herald',
'protean',
'uncongenial',
'pastoralists',
'exposition'
]
def getDefinition (word)
definition = HTTParty.get("https://od-api.oxforddictionaries.com:443/api/v1/entries/en/#{URI.escape(word.downcase)}",
headers: {
'app_id' => ENV['app_id'],
'app_key' => ENV['app_key']
})
if definition
begin
senses = definition['results'][0]['lexicalEntries'][0]['entries'][0]['senses'][0]
definition = senses['definitions'][0]
# print senses
# print "\n"
if senses['examples']
example = senses['examples'][0]['text']
definition = definition.gsub(/[^0-9a-z ]/i, '') + '. E.g. ' + example.gsub(/[^0-9a-z ]/i, '')
end
print definition
print "\n"
rescue
definition = 'no definition found.'
end
end
return definition
end
def say (phrase)
`say #{phrase} `
end
def getWord
# grab a random word
word = WORDS.sample
# print word so we know what it was
print word
print "\n"
definition = getDefinition word
3.times do |x|
say word
# only say definition first time
if x.eql? 0
say definition
end
sleep 3
end
sleep 5
end
say 'okay, ready for your spelling test today? Ok, let\'s go!'
10.times do
getWord
end
say 'test complete! swap your papers with your classmate and mark each others work'
@fetimo
Copy link
Author

fetimo commented May 24, 2017

I miss having spelling tests and often come across words that I want to learn so I created this simple script which gets a random word from the array, looks up a definition from the Oxford English Dictionary API and reads it out. You then get a few moments to write down (with real life pen and paper, not pencil, that's cheating) the spelling of it.

It's best played against another person!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment