Created
January 15, 2021 04:37
-
-
Save xnuk/93576c4dae1fde1dfcc8a2dc9af21acf to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env ruby | |
[].filter_map {} # filter_map support check | |
require 'net/http' | |
MIRRORLIST = Net::HTTP.get(URI('https://www.archlinux.org/mirrorlist/?country=KR&country=JP&country=SG&country=TW&country=HK&protocol=https')) | |
ARCH = `uname -m`.strip | |
REPO = 'core' | |
PREFIX = "curl -L --silent --max-time 3 --output /dev/null --write-out '%{http_code} %{time_total}" | |
def template(pattern) | |
url = pattern.sub('$arch', ARCH).sub('$repo', REPO) | |
"#{PREFIX} #{pattern}' #{url}/#{REPO}.db" | |
end | |
RUNNERS = MIRRORLIST.strip.lines.filter_map do |line| | |
next unless line.start_with? '#Server ' | |
pattern = line.strip.sub /^#Server = /, '' | |
template(pattern) | |
end | |
RESULTS = RUNNERS.filter_map do |line| | |
code, seconds, url = `#{line}`.split | |
next unless code == '200' | |
puts "## Server = #{url} # #{seconds}" | |
[seconds.to_f, url] | |
end.sort_by{|sec, _| sec} | |
puts | |
RESULTS.each do |sec, url| | |
puts "# #{sec} seconds" | |
puts "Server = #{url}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment