Created
February 10, 2016 19:15
-
-
Save jcgregorio/6d5c51b9d494e7913cb1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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