Friday, March 11, 2011

Better Code Weight Bash One-Liner For Rails Apps

function heftiest {
  for file in $(find app/$1/**/*.rb -type f); do wc -l $file ; done  | sort -r | head
}

[jamesgolick@James-Golicks-MacBook-Pro arbitrary_project (master)]$ heftiest models
     368 app/models/penguin/walrus.rb
      98 app/models/penguin/orca.rb
      91 app/models/wombat/chihuahua.rb
      71 app/models/pokemon/pikachu.rb
      69 app/models/wombat/savage.rb
      69 app/models/melt_banana/its_in_the_pillcase.rb
      61 app/models/foo/bar.rb
      41 app/models/fake/model_name.rb
      31 app/models/fake/other_model_name.rb
      31 app/models/pokemon/charmander.rb


By James Golick, who appears to be working on a very peculiar project at the moment.

Update: Eric Davis wrote a similar blog post not long ago.