Pardon the absence. I’m adventuring along the coast this month. (Rails 1.0 is out, wowwa!) Still, the scripts are flowing freely.
For example, here’s a Ruby prompt which only requires sh and curl. See, it’s a Try Ruby hack. I know this would have been ten times cooler to write in Python. But I don’t want people installing Python, I really don’t!
#!/bin/sh
tryurl="http://tryruby.hobix.com/irb?cmd="
wget="curl -s -b $HOME/.tryruby -c $HOME/.tryruby"
sess="$($wget "$tryurl!INIT!IRB!")"
# heshugly url encoding
urlx() {
echo "$*" |
awk 'BEGIN { split("1 2 3 4 5 6 7 8 9 A B C D E F", het, " ");het[0] = 0
for (i = 1; i <= 255; ++i) ord[ sprintf ("%c", i) "" ] = i + 0;}{
enx = "";for (i = 1; i <= length($0); ++i ) {c = substr ($0, i, 1);val = ord[c]
if (val >= 97 && val <= 122){enx = enx c}else if (val >= 65 && val <= 90){
enx = enx c}else if (val >= 48 && val <= 57){enx = enx c}else if (val >= 45 &&
val <= 46){enx = enx c}else if (c == " "){enx = enx "+"}else if (val < 128) {
lo = val % 16;hi = int(val / 16);enx = enx "%" het[hi] het[lo];}else{byte = \
192 + val/64;lo = byte % 16;hi = int(byte / 16);enx = enx "%" het[hi] het[lo];
byte = 128 + val%64;lo = byte % 16;hi = int(byte / 16)
enx = enx "%" het[hi] het[lo]}}print enx}'
}
# the prompt!
echo "Interactive Ruby ready."
echo -n ">> "
while read cmd
do
resp=""; ps=">>"
if [ -n "$cmd" ] ; then
resp="$($wget "$tryurl$(urlx "$cmd")")"
ps=".."
if [ -n "$resp" ] ; then
echo $resp
ps=">>"
fi
fi
echo -n "$ps "
done
Now if you want to play with hacking the Try Ruby prompt from the commandline, you don’t even hafta download the script. It’s easy as:
sh -c "$(curl -s http://tryruby.hobix.com/try.sh)"
I get email from guys who think this online Ruby interpreter is quite a risky business and I’m totally aware that a brilliant cracker will definitely break everything very soon. So I’m glad for the civility so far and I’m very okay with the risk. Now, enough. Please play.