Skip to content

Instantly share code, notes, and snippets.

@lemoncmd
Created January 5, 2020 17:57
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 lemoncmd/c967f248a79d3a208bfd457a2379dc8c to your computer and use it in GitHub Desktop.
Save lemoncmd/c967f248a79d3a208bfd457a2379dc8c to your computer and use it in GitHub Desktop.
V言語がCrystalを越してからRubyに到達するのにどれだけStar数を稼いでいるか見る奴
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