Skip to content

Instantly share code, notes, and snippets.

@ox
Created November 14, 2012 04:54
Show Gist options
  • Select an option

  • Save ox/4070330 to your computer and use it in GitHub Desktop.

Select an option

Save ox/4070330 to your computer and use it in GitHub Desktop.

Revisions

  1. ox revised this gist Nov 14, 2012. 1 changed file with 4 additions and 6 deletions.
    10 changes: 4 additions & 6 deletions gitcal.rb
    Original file line number Diff line number Diff line change
    @@ -10,11 +10,9 @@
    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")
    dates = commits_from_this_month.map { |n| Time.parse(n) }.take_while do |n|
    n.month == time.month and n.year == time.year
    end

    days = dates.map { |n| n.day }
    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|
    @@ -25,7 +23,7 @@
    puts "\n\n"

    streak = 0
    for n in (0..(days_in_month-time.day)) do
    for n in (0..time.day) do
    if days.include?(time.day - n)
    streak = streak + 1
    else
  2. ox revised this gist Nov 14, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gitcal.rb
    Original file line number Diff line number Diff line change
    @@ -25,7 +25,7 @@
    puts "\n\n"

    streak = 0
    for n in (0..(days_in_month-n)) do
    for n in (0..(days_in_month-time.day)) do
    if days.include?(time.day - n)
    streak = streak + 1
    else
  3. ox revised this gist Nov 14, 2012. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions gitcal.rb
    Original file line number Diff line number Diff line change
    @@ -25,8 +25,8 @@
    puts "\n\n"

    streak = 0
    for n in (1..days_in_month) do
    if days.include?(days_in_month - n)
    for n in (0..(days_in_month-n)) do
    if days.include?(time.day - n)
    streak = streak + 1
    else
    break
  4. ox revised this gist Nov 14, 2012. 1 changed file with 11 additions and 0 deletions.
    11 changes: 11 additions & 0 deletions gitcal.rb
    Original file line number Diff line number Diff line change
    @@ -23,3 +23,14 @@
    end

    puts "\n\n"

    streak = 0
    for n in (1..days_in_month) do
    if days.include?(days_in_month - n)
    streak = streak + 1
    else
    break
    end
    end

    puts "#{streak} day streak!" if streak > 0
  5. ox created this gist Nov 14, 2012.
    25 changes: 25 additions & 0 deletions gitcal.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    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")
    dates = commits_from_this_month.map { |n| Time.parse(n) }.take_while do |n|
    n.month == time.month and n.year == time.year
    end

    days = dates.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"