Archive for July, 2007

Command History in DrScheme’s REPL

Wednesday, July 25th, 2007

As I like to use a Scheme REPL as a sort of (very) advanced pocket calculator. I frequently would like to refer to results of previous calculations. Although you can paste previous inputs (<Esc> P), I prefer having a special symbol I can use in a subsequent calculation, like in Mathematica or Axiom. Fortunately, this is very easy to achive: DrScheme lets you change its REPL’s constituents so executing the following code will make a global variable “%” available that always contains the result of the last calculation. Moreover, the list “%%” is created that will hold all of your previous results. Best of all its just nine lines of code:


(define % '())
(define %% '())
(current-eval
 (let ([orig-eval (current-eval)])
   (lambda (sexp)
     (let ([result (orig-eval sexp)])
       (set! %% (cons result %%))
       (set! % result)
       result))))

ICQ Messages from Your Server

Tuesday, July 3rd, 2007

Often, I have long running jobs on various headless machines. Sometimes, I am eager to get the results, but get tired watching the console. Therefore, I wrote a small shell script that will send me an ICQ message once the job is done. To distinguish between several jobs, the message contains the original command and the last 10 lines of the result. This script takes another command as paremeter and also prints out the command’s stdout and stderr.


#!/bin/zsh
doReport() {
SINK="$HOME/.micq/scripting"
echo "msg NICK" > $SINK
echo "command: \"$@\":" > $SINK
tail > $SINK
echo "." > $SINK
}
$@ |& tee >(doReport $@)

It also requires a running instance of mICQ under the specified username. Due to the nice scripting interface of mICQ, automated sending of messages is made extremely easy. You have to replace NICK with the intended receiver’s nickname in mICQ.