Created
November 14, 2012 04:54
-
-
Save ox/4070330 to your computer and use it in GitHub Desktop.
A commit-based calendar. If a commit was made on a day, that day is green, otherwise red.
This file contains 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 'date' | |
require 'time' | |
require 'colored' | |
time = Date.today | |
puts time.strftime("%B %Y").center(20) | |
puts "Su Mo Tu We Th Fr Sa" | |
sday = Date.new(time.year, time.month, 1) | |
days_in_month = (Date.new(time.year, 12, 31) << (12-time.month)).day | |
commits_from_this_month = `git log --format="%aD" --since=1.month`.split("\n") | |
days = commits_from_this_month.map { |n| Time.parse(n) } | |
.take_while { |n| n.mon == time.mon } | |
.map { |n| n.day } | |
print " " * sday.wday | |
(1..days_in_month).each do |n| | |
print n.to_s.rjust(2).send(days.include?(n) ? :green : :red) | |
(sday = sday + 1).wday == 0 ? print("\n") : print(" ") | |
end | |
puts "\n\n" | |
streak = 0 | |
for n in (0..time.day) do | |
if days.include?(time.day - n) | |
streak = streak + 1 | |
else | |
break | |
end | |
end | |
puts "#{streak} day streak!" if streak > 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment