Remind
July 2, 2019
#! /bin/sh REMINDERFILE=/home/$(whoami)/.reminders TEMPFILE=$(mktemp) if [ $# -gt 0 ]; then PRINTING=0; echo "$*" >> $REMINDERFILE elif [ ! -f $REMINDERFILE ]; then PRINTING=1; touch $REMINDERFILE else PRINTING=1; fi gawk ' # _The_Awk_Programming_Language_ by Aho, Kernighan and Weinberger # daynum function from solution to Exercise 3.8 # only valid from 1901 to 2099; performs no validation function daynum(y, m, d, days, i, n) { # 1 == Jan 1, 1901 split("31 28 31 30 31 30 31 31 30 31 30 31", days) # 365 days per year, plus one for each leap year n = (y-1901) * 365 + int((y-1901)/4) if (y % 4 == 0) days[2]++ # leap year from 1901 to 2099 for (i = 1; i = today) { print $0 >> "'$TEMPFILE'" } printing && $1 < 100 && today <= daynum(year, $1, $2) && daynum(year, $1, $2) = 100 && today <= daynum($1, $2, $3) && daynum($1, $2, $3) <= today + 7 ' $REMINDERFILE mv $TEMPFILE $REMINDERFILE # PLB 6/30/2019
That’s not bad — a genuinely useful program in half a page of code. You can run the program at https://ideone.com/xuRsYh.
Rust version – good exercise! I learned a lot about Rust dates, sorting, file I/O, error handling…
Github: https://github.com/wpwoodjr/remind
Here’s a solution in Python.
[…] an excellent introduction to Unix, still relevant today even though it was published in 1984. The recent exercise Remind was inspired by a program in Section 4.4, and today’s exercise is a rewrite of the program in […]