Skip to content

Instantly share code, notes, and snippets.

@thedod
Last active November 14, 2016 23:29
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 thedod/d072c273b24e4a1790ec9f72a1d298d3 to your computer and use it in GitHub Desktop.
Save thedod/d072c273b24e4a1790ec9f72a1d298d3 to your computer and use it in GitHub Desktop.
shinatra.sh variant for serving files

f.shinatra.sh

A variant of shinatra.sh that serves the current version of a file (f is for file).

Usage: f.shinatra.sh somefile.html [port] [filter]

  • Default port is 8080
  • Default filter is unix2dos (see edge effect example below)

Examples:

  • Hasciicam:

    run hasciicam -m html and ./f.shinatra.sh hasciicam.html

  • Webcam snapshot (e.g fswebcam) with edge effect:

    ./f.shinatra.sh cam.jpg 8080 ./jpeg2edge2html.sh

#!/bin/bash
while { echo -en "HTTP/1.1 200 OK\r\nConnection: keep-alive\r\n\r\n$(${3:-unix2dos} < "$1")"; } | nc -l ${2:-8080}; do
echo "================================================"
done
#!/bin/sh
echo "<html><head><title>jpg2html</title><meta http-equiv=\"refresh\" content=\"1\"></head><body><img style=\"width:100%; height:auto; margin:auto\" src=\"data:image/jpg;base64,$( jpegtopnm | ppmrelief | ppmbrighten -v 100 | pnminvert | pnmtojpeg | base64 )\"></body></html>"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment