Skip to content

Instantly share code, notes, and snippets.

@lalyos
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lalyos/11314322 to your computer and use it in GitHub Desktop.
Save lalyos/11314322 to your computer and use it in GitHub Desktop.
apibunny.com solved in 140 characters

The apibunny challenge

There is a geek challenge called apibunny to play with rest apis.

my 1-liner (140 chars) script which fits in a twitter message:

c(){ curl -O http://apibunny.com/cells/$1;for  l in $(sed -n "s/.*\([[:alnum:]]\{16\}\).*/\1/p" $1); do wc $l || c $l;done; } && c taTKQ3Kn4KNnmwVI
checkCell() {
grep $1 visited &>/dev/null && return
curl -s -O http://apibunny.com/cells/$1
echo -n .
echo $1 >> visited
for cell in $(sed -n "s/.*\([[:alnum:]]\{16\}\).*/\1/p" $1); do
checkCell $cell
done
} && rm -f visited && checkCell taTKQ3Kn4KNnmwVI
c(){ curl -O apibunny.com/cells/$1;for l in $(sed -n "s/.*\([[:alnum:]]\{16\}\).*/\1/p" $1); do wc $l || c $l;done; } && c taTKQ3Kn4KNnmwVI
checkCell() {
local ACTUAL=$1
[ -f $1 ] || curl -sO http://apibunny.com/cells/$ACTUAL
grep $ACTUAL visited
if [ $? -eq 0 ]; then
echo already [visited]
return
fi
name=$(cat $ACTUAL | jq ".cells[]|.name" -r)
echo [$ACTUAL] $name | tee -a visited
CELLS=$(cat $ACTUAL | jq '.cells[].links| to_entries | map(select(.key != "maze"))[]| .value' -r)
for cell in $CELLS; do
checkCell $cell
done
}
checkCell XjVE3BtLvP8wYskv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment