Last active
October 6, 2016 12:11
-
-
Save mamantoha/2d3ee46f9cae84e4084b29a80e696611 to your computer and use it in GitHub Desktop.
Small CLI tool to tell you if GitHub is online
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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