I use jQuery Autosize plugin:
http://www.jacklmoore.com/autosize/
The script itself you can see here:
http://www.jacklmoore.com/js/jquery.autosize.js
FWIW the autosize invocation method has changed. If you end up here and are using it with jQuery
Previously it was
$('textarea').autosize();
The new invocation is
autosize($('textarea'));