Created
January 5, 2020 17:57
-
-
Save lemoncmd/c967f248a79d3a208bfd457a2379dc8c to your computer and use it in GitHub Desktop.
V言語がCrystalを越してからRubyに到達するのにどれだけStar数を稼いでいるか見る奴
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
import ( | |
net.http | |
json | |
math | |
) | |
const ( | |
disp_len = 100 | |
) | |
struct Data { | |
stargazers_count int | |
} | |
fn get_stargazer(name string) ?Data { | |
resp := http.get('https://api.github.com/repos/$name') or { | |
return error('Cannot fetch GitHub repository `$name`') | |
} | |
if resp.status_code != 200 { | |
return error('Cannot fetch GitHub repository `$name`') | |
} | |
text := resp.text | |
data := json.decode(Data, text) or { | |
return error('Cannot parse json from fetched data') | |
} | |
return data | |
} | |
fn main() { | |
v := get_stargazer('vlang/v')? | |
crystal := get_stargazer('crystal-lang/crystal')? | |
ruby := get_stargazer('ruby/ruby')? | |
diff := ruby.stargazers_count - crystal.stargazers_count | |
prog := math.max(f64(0), ruby.stargazers_count - v.stargazers_count) / diff | |
done := '|'.repeat(int((f64(1) - prog) * disp_len)) | |
notdone := '-'.repeat(int(prog * disp_len)) | |
println('crystal|$done\(v)$notdone|ruby') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment