Skip to content

Instantly share code, notes, and snippets.

@rogsmith
rogsmith / gist:7ead0421e70a0edc3906
Created December 14, 2015 21:34
Save RubyZip to Paperclip
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"
@rogsmith
rogsmith / gist:5f723ffd99e70f9c63df
Last active November 6, 2015 04:02
therubyracer + commonsjsrb
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