Skip to content

Instantly share code, notes, and snippets.

@jcgregorio
Created February 10, 2016 19:15
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 jcgregorio/6d5c51b9d494e7913cb1 to your computer and use it in GitHub Desktop.
Save jcgregorio/6d5c51b9d494e7913cb1 to your computer and use it in GitHub Desktop.
A quick and hacky HTTP server in Julia to execute Julia, which gets around the
startup and JIT delays when running Julia scripts from the command line.
using HttpServer
info("loading Gadfly...")
tic()
using Gadfly
toc()
info("JIT warmup...")
tic()
draw(SVG("output_0.svg", 6inch, 3inch), plot([sin, cos], 0, 25))
toc()
http = HttpHandler() do req::Request, res::Response
try
io = IOBuffer()
r = eval(parse(UTF8String(req.data)))
show(io, r)
return Response(takebuf_string(io))
catch err
println("Connection ended with error: $err")
end
return Response("Success")
end
http.events["error"] = (client, err) -> println(err)
http.events["listen"] = (saddr) -> println("Running on https://$saddr (Press CTRL+C to quit)")
server = Server( http )
run(server, host=IPv4(127,0,0,1), port=8111)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment