This file contains hidden or 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
context = V8::Context.new timeout: timeout | |
js = CommonJS::Environment.new(context, path: "#{Rails.root}/lib/javascripts") | |
context["_"] = js.require('underscore.js') | |
context['data'] = "[1,2,3,4]" | |
source = "(function(){return _.map(JSON.parse(data), function(num){ return num * 5 });});" | |
res = context.eval(source) | |
# res is a #<V8::Function:0x007feaf195a720 | |
# if I then try |
This file contains hidden or 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
buffer_string = Zip::OutputStream.write_buffer do |zos| | |
zos.put_next_entry("FILENAME") | |
zos.write FILE_DATA | |
end.string | |
file = StringIO.new(buffer_string) | |
file.class.class_eval { attr_accessor :original_filename, :content_type } | |
file.original_filename = "#{file_name}.zip" | |
file.content_type = "application/zip" |