Skip to content

Instantly share code, notes, and snippets.

@danmaclean
Last active December 19, 2015 21:19
Show Gist options
  • Save danmaclean/6019651 to your computer and use it in GitHub Desktop.
Save danmaclean/6019651 to your computer and use it in GitHub Desktop.
codefest - sample rack app
require 'rubygems'
require 'json'
require 'rack'
require 'rinruby'
class HelloApp
def call(env)
req = Rack::Request.new(env)
#text = JSON.pretty_generate(JSON.parse(req.params.to_json))
#[200,{"Content-Type"=> "text/plain"}, ["Hello, Rack #{text}"]]
plot_r_norm
[200,{"Content-Type" => "image/png"}, ["out.png"] ]
end
def plot_r_norm
r = new_r
r.eval "x = rnorm(100,100)"
r.eval "png('out.png')"
r.eval "plot(x)"
r.eval "dev.off()"
end
def new_r
r = RinRuby.new(echo = false, interactive = false)
r.eval "options(warn=-1)"
return r
end
end
@danmaclean
Copy link
Author

@helios - for you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment