toot.cat is one of the many independent Mastodon servers you can use to participate in the fediverse.
On the internet, everyone knows you're a cat — and that's totally okay.

Administered by:

Server stats:

424
active users

Public

programmer challenge: write a script which, when given a file in the current git repository, outputs the average age of the lines in the file

bonus challenge: implement a toggle to include or exclude blank lines

Public

@Lady interesting challenge! this prints the average age of the lines in $filename, in days:

git blame --line-porcelain "$filename" | grep '^author-time ' | awk '{ mean += ($2 - mean) / NR } END { print (systime() - mean) / 86400 }'

excluding blank lines is a little trickier but the --line-porcelain output does have enough information to do it

Public

@jamey `systime()` isn’t POSIX but i imagine that’s doable to replace? awk probably is the easiest solution here huh

Public

@Lady there's always the approach of sticking '$(date +%s)' there instead 😁

Public

@jamey or

("date +%s" | getline); print ($0 - mean) / 86400

worked for me if you want to keep it in awk 😂

(macOS uses a fork of "The One True AWK”, not GNU awk, by default so the question isn’t purely hypothetical)

@Lady that's a delightful option too! I just take way too much pleasure in metaprogramming things that weren't meant to be metaprogrammed. 😅 and yeah, I assumed you were asking due to being on one of the BSD-ish platforms, which is a totally reasonable constraint