Last active
December 19, 2015 21:19
-
-
Save danmaclean/6019651 to your computer and use it in GitHub Desktop.
codefest - sample rack app
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
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@helios - for you