James Bowes

Purveyor of Pre-eminent Programmes

Graphing Git Repository Activity In ASCII

with 3 comments

Here’s a quick little script I wrote up (adapted from this perlmonks post) to show git repository activity as an ascii graph, like so:

git-graph screenshotThe X axis represents a day, with the current day being on the far right. The Y axis is no. of lines added + no. of lines deleted during that day.

EDIT (2009/02/03):

WordPress.com won’t let me attach a .pl file, so here’s the contents:

#!/usr/bin/perl
#
# git-graph.pl - Generate an ascii graph of git repository activity
#
# Copyright (C) 2008 James Bowes <jbowes@dangerouslyinc.com>
#
# Graphing routine Adapted from http://www.perlmonks.org/?node_id=336907

sub get_activity {
    my $day = shift;
    my $git_cmd = 'git diff --shortstat "@{' . ($day + 1) .' day ago}" "@{' .
                  ($day or "0") . ' day ago}"';
    $res = `$git_cmd 2> /dev/null`;

    $res =~ /, (.*?) insertions\(\+\), (.*?) deletions\(-\)/;
    $activity = $1 + $2;

    return $activity;
}

@deltas = ();
foreach $day (0..70) {
    push (@deltas, get_activity ($day));
}

print ("\n");
print graph(@deltas);
print ("\n");

sub graph {
  my( $i, $magic, $m, $p, $top, @g ) = ( 0, 20, 7, 70, 0, () );

  foreach $pad (0..($p - scalar(@_))) {
      push (@_, 0);
  }

  @_ = reverse @_; 

  for (0..($p)) {
      $top = ($top > $_[$_]) ? $top : $_[$_];
  }

  $top = $top - ($top % 100) + 100;

  my $s = $top > $magic ? ( $top / $magic ) : 1;  ### calculate scale

  for (0..$magic) {
    $g[$_] = sprintf("%" . ($m - 1) . "d |", $_ * $s) .
             ($_ % 5 == 0 ? '_' : ' ') x ($p);
    for $i (0..($p)) {
        substr($g[$_], ($i + $m), 1) = '#' if ($_[$i] / $s) > $_;
    }
  }
  join( "\n", reverse( @g ), ' Date:  ' . '^^^^^^|' x ( $p / 7 ));  
}  # end sub graph

__END__
Advertisements

Written by jbowes

May 24, 2008 at 11:15 am

Posted in SCM

Tagged with , , , ,

Installing ruby gems in your home directory

with one comment

update: This post is now on my new blog.

I found it hard to find good instructions for installing ruby gems as a non-root user without installing the gem package locally as well. Here’s what I figured out; hopefully this will save someone else some time in the future:

Make a directory for gem installation:

$> mkdir ~/.gems

Set up your .gemrc for gem install-time configuration:

$> cat << EOF > ~/.gemrc
gemhome: $HOME/gems
gempath:
- $HOME/gems
- /usr/lib/ruby/gems/1.8
EOF

Set up some environment variables for run-time:

$> cat << EOF >> ~/.bashrc
export GEM_HOME=$HOME/gems
export GEM_PATH=$HOME/gems:/usr/lib/ruby/gems/1.8/
export PATH=$PATH:$HOME/gems/bin
EOF

Source your bashrc and you’re all set.

UPDATE (Apr 18, 2009): gem seems to do this on its own now, so just adding

export PATH=$PATH:$HOME/.gem/ruby/1.8/bin

to your .bash_profile should be enough.

Written by jbowes

May 13, 2008 at 10:54 am

Posted in config files

Tagged with , ,

Shell HIstory Meme

leave a comment »

[jbowes@laptop ~]$ history | awk '{a[$2]++ } END{for(i in a){print a[i] " " i}}'|sort -rn|head
211 git
148 fg
107 ls
99 cd
89 python
43 make
26 vim
23 sudo
20 nosetests
19 player/swfplay

[jbowes@workstation ~]$  history | awk '{a[$2]++ } END{for(i in a){print a[i] " " i}}'|sort -rn|head -n 12
163 ls
156 cd
115 svn
76 vim
70 screen
55 fg
47 exit
35 sudo
30 git
21 yasql

Seen on Adrian’s and Mike’s blogs.

Written by jbowes

April 9, 2008 at 1:12 pm

Posted in tech

Tagged with , ,

Dear Government of Canada

leave a comment »

Please stop Bell from doing crazy stuff.  Thanks!

Love,

James

Written by jbowes

March 26, 2008 at 8:30 am

Posted in life, opinion, tech

Tagged with , ,

Cat News

with 4 comments

Our boy cat Julius passed away a few weeks ago. It was pretty shocking, as he was quite young and his passing was sudden and unexpected. While we miss him terribly, Cherie and I didn’t want Spook to get too used to being an only cat again.

So this weekend we picked up a new little fellow from the Toronto Humane Society:

img_3405.jpg

He doesn’t have a name yet, but he sure has quite a pair of ears on him!

Written by jbowes

March 3, 2008 at 7:51 am

Posted in life

Tagged with ,

2% Genius

leave a comment »

Agile Tsar Dmitri Dolguikh pointed out Project Euler yesterday, which is a website containing a series of short programming problems. It reads a bit like bonus questions on a math exam, which is actually quite refreshing compared to the day-to-day problems at work. For added fun, I’m trying to run through the problems in Common Lisp.

So far I have completed 4 out of 179 problems, which makes me 2% genius, according to the site.

Written by jbowes

January 29, 2008 at 8:46 pm

Posted in life, tech

Tagged with , ,

Mission Accomplished!

with 2 comments

A lot of people are linking to this article about the state of the practice in CS curriculum and its use of Java creating dull replaceable drones.

mdehaan points out a wonderful section wherein the authors relate Java programming to a plumber in a hardware store, finding pieces and putting them together to solve a problem, rather than their unmentioned alternative (maybe an artist molding clay?)

If this is true, then we, the software industry and software engineering fields, are done. We have found the holy grail: true modularity and reusable software components. Drop whatever language you’re using and switch to Java.

Written by jbowes

January 8, 2008 at 10:35 am