Skip to content

Instantly share code, notes, and snippets.

@ox
Created November 14, 2012 04:54
Show Gist options
  • Save ox/4070330 to your computer and use it in GitHub Desktop.
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.
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