Skip to content

Instantly share code, notes, and snippets.

@mamantoha
Last active October 6, 2016 12:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mamantoha/2d3ee46f9cae84e4084b29a80e696611 to your computer and use it in GitHub Desktop.
Save mamantoha/2d3ee46f9cae84e4084b29a80e696611 to your computer and use it in GitHub Desktop.
Small CLI tool to tell you if GitHub is online
require 'net/http'
def warning_message
puts <<~HEREDOC
Usage:
$ is_github_down
🦄 It's down. Go outside!
HEREDOC
exit
end
def up?(url)
uri = URI.parse(url)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true if uri.scheme == 'https'
http.read_timeout = 5
http.open_timeout = 5
response = http.head('/')
response.code == '200'
rescue Timeout::Error, SocketError
false
end
puts warning_message if ARGV.any?
if up?('https://github.com')
puts "\n 🐈 It's up. Go back to work!"
else
puts "\n🦄 It's down. Go outside!"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment