How Many Lines of Code Did You Write This Year?
Filling out my pre-tenure paperwork (blech) I started to wonder. I sure wasn’t going to count them by hand, so I wrote a Processig sketch bash script to find out. Result: 208 sketches for a total of 20,944 lines or 590,670 characters! (2010: 232 sketches, 19,786 lines, 563,083 characters; 2012 so far: 9 sketches, 879 lines, 27,533 characters)
UPDATE:
The previous version used a Processing sketch to find the information, which seemed poetic. However, it seems that Java doesn’t do file handling very cleanly (curse you File variable). As I went to bed, it seemed a bash script would be much cleaner and likely faster, so I got up today and wrote one. Sorry Windows users, this is likely Mac/Linux only. You can still download the Processing sketch and try it yourself.
#!/bin/bash
# Jeff Thompson | www.jeffreythompson.org
# enter the year you're looking for and the path to your Processing sketchbook
lookFor="pde" # file extension to look (period optional)
yearCreated="2011" # year to look at
pathToCheck="/Users/jeffthompson/Documents/Processing" # where to look
# pathToCheck=$HOME # alternatively, look everywhere (may be VERY slow)
dateRange="01-Jan-$yearCreated" # set date to the first of the year we're looking for
echo ""
echo "HOW MANY LINES OF CODE DID YOU WRITE THIS YEAR?"
echo -e "Path:\t\t$pathToCheck"
echo -e "Extension:\t$lookFor"
echo -e "Year:\t\t$yearCreated"
# note: we don't need the . in front of the extension since * will match all preceeding characters
find $pathToCheck -type f -name \*$lookFor -newermt "$dateRange" -and -not -newermt "$dateRange +12 month"> "$lookFor_files.txt"
fileCount=$(wc -l < "$lookFor_files.txt")
lineCount=0
charCount=0
while read line; do
lines=$(wc -l < $line) # count lines in the file
let "lineCount += lines"
chars=$(wc -c < $line) # count characters
let "charCount += chars"
done < "$lookFor_files.txt"
rm "$lookFor_files.txt" # be nice and delete the working file (optional)
echo -e "Result:\t ${fileCount} files, ${lineCount} lines, ${charCount} characters"
exit
