Welcome, guest | Sign In | My Account | Store | Cart

This recipe is a command line alarm. If not used correctly, usage information is printed. If an exception is thrown, details on the exception are printed out, though in a format most useful for a programmer. The program has no built-in way of being shutdown, so such actions must be executed externally.

Python, 19 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
import os, sys, time

def main():
    if len(sys.argv) != 4:
        print os.path.basename(sys.argv[0]),
        print '<hours> <minutes> <seconds>'
    else:
        try:
            timer(*[int(x) for x in sys.argv[1:]])
        except Exception, error:
            print error

def timer(hours, minutes, seconds):
    time.sleep(abs(hours * 3600 + minutes * 60 + seconds))
    while True:
        print '\x07',

if __name__ == '__main__':
    main()

This program was originally far simpler and was designed to wake the author up in three after (no alarm clock was available at the time). It is conceivable that more inventive uses of the recipe could be invented (such as a cooking time), but that is up to the readers to decide. The presentation here is made in the hopes that it might go on to serve in better capacities.