I have a script that can be called by untrusted users, we need to make a call along the lines of this made up example:
system 'somescript ' + data
We need to ensure if data == 'filename; dosomethingelse' then the ; is escaped (or any other special character. The result is the shell command run is actually somescript filename\;\ dosome...
I am learning Ruby & Perl has this very convenient module called Data::Dumper, which allows you to recursively analyze a data structure (like hash) & allow you to print it. This is very useful while debugging. Is there some thing similar for Ruby?
...
In this question, I find that using system('start http://www.google.com') is OK. If the file is in local disk, though, using system('start file:///c:/temp/a.html') doesn't work. How do I have Ruby get the default browser to open a local file?
...
I have a server application that allows users to execute their own ruby scripts. The server that the scripts run on is a virtual instance on Amazon's EC2 so no permanent damage can be done. However I'd like to take whatever precautions I can to stop any dangerous/malicious script, reboots are still something I'd like to avoid.
At the mo...
Is there a way to create an editable PDF programmatically? By editable, I mean you can click in a text area and type in your name, that kind of thing.
I'm using Ruby and have found PrinceXML and Princely to be nice projects. I'm wondering if they could do that?
...
I'm creating a gem package with hoe library.
The package shoud do "cd ext/lib/ && make " when "gem install pkg.gem"
How to add task when package installing.
# -*- ruby -*-
require 'rubygems'
require 'hoe'
file ["ext/lib/*.c", "ext/lib/*.h"] do
Dir.chdir "ext/lib" do
sh "make"
end
end
Hoe.spec 'mypackage' do |p|
p.develope...
I'm trying to get delayed job to work as a rake task, but for the life of me I can't figure out what I'm doing wrong. Given the following setup:
#config/environment.rb
Rails::Initializer.run do |config|
config.gem 'delayed_job'
end
#Rakefile
begin
require 'delayed/tasks'
rescue LoadError
STDERR.puts "Run `rake gems:install` ...
I've run into this problem with testing. Let's assume I have two models, User and Post, where user has_many :posts.
I'm trying to spec out a code block that includes something like this:
user = User.find(123)
post = user.posts.find(456)
I know how to mock out the User.find and user.posts parts. The user.posts mock returns an array of...
I'm trying to build a class diagram in Sparx Enterprise Architect for future usage in Ruby project.
How should I set up base code datatypes (Settings -> Code Datatypes...)?
It should be something like: Datatype = Common Type (additional notes, if any). Does anyone know what pairs should be input?
I'd also highly appreciate advice on h...
Is there any possibility to overwrite the dots in a ruby range?. My aim is, to manipulate the given objects before the range is created.
I thought of something like this
require 'rubygems'
require 'active_support'
#actual i have to call explicitly .to_date
Date.today.to_date..1.month.since.to_date
#this should give me a range with Da...
Writing a globalization module for a web application and I need a regexp to replace all instances of a word with another word (the translation) - except - words found within a URL/URI.
EDIT: I forgot to mention that I'm using Ruby, so I can't use 'Lookbehind'
...
I'm trying to find all topics in a one particular category, but I'm not sure if this is the most efficient way to do it:
Topic.all.select { |topic| topic.categories.include?(category) }
The above works for me but it seems that it takes MySQL a long time to find the records. Is there anything more efficient?
...
I recently discovered the Hanna RDoc template and I like it a lot more than the default. I want to use it in my project, but I also don't want my project to require it.
The only change I had to make to my Rakefile to get the hanna template to work was to change
require 'rake/rdoctask'
to
require 'hanna/rdoctask'
Is there any way...
i have this string
string = "<p>para1</p><p>para2</p><p>para3</p>"
I want to split on the para2 text, so that i get this
["<p>para1</p>", "<p>para3</p>"]
The catch is that sometimes para2 might not be wrapped in p tags (and there might be optional spaces outside the p and inside it). I thought that this would do it:
string.split(...
Hi there,
I'm creating a plugin and am having a hard time defining a before_save filter that calls an instance method I've just defined. Here's a quick sample:
module ValidatesAndFormatsPhones
def self.included(base)
base.send :extend, ClassMethods
end
module ClassMethods
def validates_and_formats_phones(field_names = [...
I want to run a thread-safe piece of script in Ruby that calls an external program, then checks the exit status of that external program. What's the best way to do it? So far, I've been checking $?, but I think I'm getting a race condition with other parts of the program.
Here's some example code:
Thread.new do
`external_program`
i...
m = Model.find(1);
m.class_name would give you "Model"
If we have:
m = Model.find(:all);
How do we get the name of the model from m alone?
...
the code that didn't work:
login_form = page.form_with(:method => 'post')
and code that works
login_form = page.form_with(:method => 'POST')
I inspected the form object via puts page.forms.inspect and got
[#<WWW::Mechanize::Form
{name nil}
{method "POST"}
....]
html source:
<form class="login" method="post"> <fieldset>
<legend>...
I'm trying to create default seed records for every user that signs up to the app. I'm thinking I could use the after_create method in my users observer model:
def after_create(user)
user.recipes.create(:name => "Sample Recipe", :description => "This is a sample recipe.")
user.cuisines.create(:name => "Sample Cusine", :description =...
Hello all,
This is my first stab at Ruby on Rails. Just deployed a very simple app to Heroku.
The thing is that my app runs flawlessly on mongrel development; When I run it with "mongrel_rails start -e production" however, I get the error "We're sorry, but something went wrong."
For the life of me, I couldn't debug this. Heroku logs i...