I have a bunch of rspec tests that are taking entirely too long to run. I am trying to figure out where the bottleneck is and the logical place to start is using the standard libraries profile library. Execution is happening with JRuby 1.5.2 in this particular case. Here is the output after embedding the profile library in my spec:
% ...
Links have one or more tags, so at first it might seem natural to embed the tags:
link = { title: 'How would you implement these queries efficiently in MongoDB?'
url: 'http://stackoverflow.com/questions/3720972'
tags: ['ruby', 'mongodb', 'database-schema', 'database-design', 'nosql']}
How would these queries be imple...
So, I'm a total nuby working through http://www.rubykoans.com/ and I'm stuck on about_scoring_project.rb. This is my stab at the score method.
def score(dice)
score = 0;
if dice.respond_to?("include?") then
# add 1000 points if rolled 3 ones
score += 1000 if dice.include?([1, 1, 1])
# add 100 points times die face va...
Hi,
I've started learning rails3 few days ago, and since today, every time I run unit test for my model I get this error message:
ActiveRecord::StatementInvalid: SQLite3::SQLException: no such table: users: DELETE FROM "users" WHERE 1=1
The tests went smoothly yesterday, I run them today (reverting everything to the state from ...
Is there a gem or plugin, that can generate a Comments with columns names above the class definition in Active Record model? I'm pretty sure that I've seen something like this, but can't find it anywhere:
Example:
# columns Defs
# name:string
# user_id:integer
# etc.
class Post < ActiveRecord::Base
end
I could as well write something...
Hey guys, in the following code:
def process(batch_size=1000)
claim_numbers.each_slice(batch_size) do |numbers_batch|
claims = Claim.find(:all, :conditions => ["claim_number in (?)", numbers_batch])
# do something with claims
end
end
In one of my Rails models I'm processing a lot of claim_numbers, I'm simu...
Can embedded ruby (erb) be used outside of rails in regular webpages to dynamically update content (almost as a replacement for PHP)?
...
I'm looking for a forgiving HTML parser for scraping HTML and extracting data in Ruby. I've had success using BeautifulSoup for this - what is the ruby equivalent?
...
Which way of writing this condition is better?
1)
(self.expense_gl_dist_code.dist_type == GlDistCode::PERCENTAGE || self.expense_gl_dist_code.dist_type == GlDistCode::MIXED)
2)
["GlDistCode::PERCENTAGE","GlDistCode::MIXED"].include?(self.expense_gl_dist_code.dist_type)
...
Hello!
I am new to ruby and to rails, so excuse my question... .
What i want to know is, how to take a file from a ftp server with ruby without saving the file on my rails application harddrive (streaming the filedata direct to the client). I am working with the ruby Net/FTP class.
With the method "retrbinary" from the Net/FTP class i ...
I want to use YAJL to render JSON. If I require 'yajl' in the controller and perform a render :json => some_hash, will this use YAJL to encode the hash into json? Should I convert the hash to JSON using YAJL's encode method before calling render?
If not, how can I go about doing this?
...
I wonder, why don't they implement other languages like python and ruby on the web browsers?
Don't they fit as client programming languages or did it just happen to be that Javascript was the first one to be implemented, and they then kept on only supporting javascript because it just worked.
I mean...I really hate Javascript compared ...
For some time, xml-simple gem had been working for me just fine (indirectly, through another gem).
But lately I had to install Amazon S3 gem also. Amazon guys had decided that xml-simple wasn't cool enough, so they supplied a replacement: 'faster-xml-simple'. And they also decided that everybody wants to use their code now, so they did ...
I have written a ruby daemon and I would like for it to run when I log in. It is normally run by going to the command line and calling ruby my_ruby_script.rb. How can I start my daemon on login? (Running 10.6 Snow Leopard).
...
How can I mock the initialize method on a ruby class?
I'm doing some testing and want to mock out the object that is created from a new call.
I tried to write a few things and none of them seemed to get the mock class to return from the new call. It just keeps returning the normal, expected object.
EDIT:
one attempt -
class MockR...
For instance, if I have a Time.now, how would I convert that to a friendly url string?
Time.now.some_method_here => some_url_friendly_string_here
I believe there is a built-in Ruby method to do so, but I can't seem to locate it on Google. Any ideas?
...
{'a' => 'b'}.grep /a/
=> []
>> {'a' => 'b'}.grep /b/
=> []
It doesn't seem to match the keys or values. Does it do something I'm not discerning?
...
I discovered this while using ruby printf, but it also applies to C's printf.
If you include ANSI colour escape codes in an output string, it messes up the alignment.
Ruby:
ruby-1.9.2-head > printf "%20s\n%20s\n", "\033[32mGreen\033[0m", "Green"
Green # 6 spaces to the left of this one
Green # correctly ...
I feel like I have a simple desire that no one can satisfy: I want to be able to graph a set of points, and I am using Ruby 1.9.2.
I would like to use Gruff or Scruffy, since these seem to be the easiest to use. However, they both rely on rmagick, and it seems that many other libraries do to. Rmagick isn't compatible with Ruby 1.9 thoug...
related to http://stackoverflow.com/questions/2127374/mongodb-group-using-ruby-driver
if I want to do something like the following in SQL:
select page_id, count(page_id) from a_table group by page_id
I thought the MongoDB's doc says
http://api.mongodb.org/ruby/current/Mongo/Collection.html#group-instance_method
group(key, condition...