Skip to content

Instantly share code, notes, and snippets.

@yorickpeterse
Created July 27, 2014 21:45
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 yorickpeterse/aa4245d577fadbfa7eb2 to your computer and use it in GitHub Desktop.
Save yorickpeterse/aa4245d577fadbfa7eb2 to your computer and use it in GitHub Desktop.
require 'httpclient'
require 'json'
repos = []
days = %w{Sunday Monday Tuesday Wednesday Thursday Friday Saturday}
times = Hash.new do |hash, key|
hash[key] = Hash.new { |h, k| h[k] = 0 }
end
resp = HTTPClient.get('https://api.github.com/users/yorickpeterse/repos')
JSON(resp.body).each do |repo|
repos << repo['name']
end
repos.each do |name|
resp = HTTPClient.get("https://api.github.com/repos/yorickpeterse/#{name}/stats/punch_card")
JSON(resp.body).each do |(day, hour, amount)|
times[day][hour] += amount
end
end
spacing = days.sort_by(&:length).last.length
times.each do |day_index, hours|
day = days[day_index]
hour, commits = hours.sort_by { |pair| pair[1] }.last
puts "#{day.ljust(spacing, ' ')} at #{hour.to_s.ljust(2, ' ')}: #{commits} commits"
end
Sunday at 21: 54 commits
Monday at 22: 62 commits
Tuesday at 23: 65 commits
Wednesday at 23: 64 commits
Thursday at 0 : 72 commits
Friday at 0 : 48 commits
Saturday at 0 : 28 commits
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment