ruby

Ruby/Glibc coredump (double free or corruption)

I am using a distributed continuous integration tool which I have written by myself in Ruby. It uses a fork of Mike Perham's "politics" for distribution of the tasks. The "politics" module is using threads for the mDNS part. Every now and then I encounter a core dump which I don't understand: *** glibc detected *** ruby: double free or...

How can I mock/fake the existence of a file using rspec?

This is what I have: it "should be able to get a valid directory path" do @asset.some_file_path.should == "/something/test.jpg" end The problem is that some_file_path returns "/not_here_yet.jpg" if there is no existing file. def some_file_path if File.exists(self.my_image_path) return my_image_path else return "/not_...

How can I create new symlink for RoR Application in the public_html folder ?

I have one folder in the public_html folder named techease and I want my application symlink with this existing folder how can I do this ? because when I link this with this folder then it will create public folder in the techease folder and then symlink with that folder. It how can I create symlink with the existing folder not new cre...

How do I test a WHOLE string against regex in ruby?

Hey, How do I a string against a regex such that it will return true if the whole string matches (not a substring)? eg: test( \ee\ , "street" ) #=> returns false test( \ee\ , "ee" ) #=> returns true! Thank you. ...

Tell Merb not to timeout

Hi, after posting a question related to nginx, I'm a bit further with my investigations: The problem is, that the merb framework timeouts after about 30 seconds. If i tell the underlying nginx-server not to timeout, merb does, and I can't find a way to tell it not to; I need to do requests that take up to some minutes. Any hints? Thank...

Solution for semantic control of xml document

For example, Xml document: <some_document> <elements> <element>1</element> <element>2</element> <element>3</element> </elements> <sum>6</sum> <some_document> Rules(in some form, probably in xml), according to schema of given document: Sum of all <element> fields must match the value in <sum> field Result: Is document vali...

Mocking an object method within a Thread?

In the situation below the @crawl object DOES RECEIVE the crawl call, but the method mock fails ie: the method is not mocked. Does Thread somehow create its own copy of the @crawl object escaping the mock? @crawl.should_receive(:crawl).with(an_instance_of(String)).twice.and_return(nil) threads = @crawl.create_threads thread crea...

RoR live-search (text_field_with_auto_complete) submit.

I have a "Movies" and a "Actors" table and "Casts" as join-model. To be more specific "Casts" has movie_id, actor_id and rolename. I want in "Movies" form to add a live search to search through actors and a "rolename" text_field and save those to "Casts". I don't know if text_field_with_auto_complete is the right choice but i prefer not ...

How can I get past "http://gems.rubyforge.org/ does not appear to be a repository" error message

Question 828421 asked similar question, but received only one real answer (update rubygems) and that attempt results in the same error. Ruby version 1.9.1.p243 on Windows. Included Gem, version 1.3.5. Never installed any gems before; never did any special config for this Ruby. Ruby itself works, as does irb, and "gem" operates but can'...

Retrieving specific hash key values from an array of hashes

All, I was wondering if anyone knew a better patten than: array_of_hashes.map { |hash_from_array| hash_from_array[:key] } for retrieving an array of values with a specific key from an array of hashes containing that key. ...

extracting specific value from a multidimensional hash in ruby by key name

let's say i have a multidimensional hash, and in one of the subhashes i have a key=>value pair which i need to retrieve by key. how can i do it? example hashes: h={:x=>1,:y=>2,:z=>{:a=>{:k=>"needle"}}} h={:k=>"needle"} key is always :k, and i need to get "needle" i noticed that there is no "flatten" function for hashes in ruby 1.8, ...

Ruby whitespace: Is { :a => 1 } better than {:a => 1}?

Looking at other people's code it seems really common to include an extra space inside curly brace blocks. Is there a reason for that? To me it seems to add extra keystrokes for added ugliness. Especially when things get nested: lambda { (1..5).map { |i| { :a => { :b => i } } } } For some reason it just looks more concise and coherent...

Optimisation of Ruby algorithm for grouping and counting colours.

Hi, i have what seems on the surface a simple problem which i wish to solve using ruby, i have a bunch of colours with associated photo id's, e.g [[1,"red"],[1,"green"],[2,"red"],[3,"yellow"],[4,"green"],[4,"red"]] and i wish to process the data so that it is in this format: 2 photos for red,green 3 photos for red 1 photo for yellow ...

Replace all text except links

I have many html documents, I need to replace the text "foo" to "bar" in all documents, except in links For example foo<a href="foo.com">foo</a> should be raplaced to bar<a href="foo.com">bar</a> the url in the link (foo.com) should be left untouched. The same case in image links and links to javascripts or stylesheets, only th...

Apache Tomcat and Ruby

We have Ruby Rails and Apache tomcat servers running on the samw windows server. When the App on Apache Tomcat is installed alone its working fine, but when the ruby app is installed, the Apace Tomcat App stops working. We need to have both the apps running on the same server. Please help. The application running on Tomcat is displaying ...

Use Rack::CommonLogger in Sinatra

I have a small web-server that I wrote with Sinatra. I want to be able to log messages to a log file. I've read through http://www.sinatrarb.com/api/index.html and www.sinatrarb.com/intro.html, and I see that Rack has something called Rack::CommonLogger, but I can't find any examples of how it can be accessed and used to log messages. ...

Can anyone help me scrape the Amazon Products API using Ruby?

Hi, I'm using the amazon-product-advertising-api gem and am following the example code to try and grab music album data. The code I have is as follows: post '/mash' do username = params[:username] user = Scrobbler::User.new(username) @recommendations = user.recommendations @urls = { } @recommendations.each do |t...

how to build a select tag from a range in rails

I want to have a drop down that consists of values 10% 20% 30% so on till 100. In ruby It can be done by (10..100).step(10) { |i| p i } how can i convert this into a select tag? I tried: <%=p.select :thc, options_for_select((10..100).step(10) {|s| ["#{s}%", s]})%> but this is printing 10 11 12 13....100 ...

Symbol Table Overflow Issue in Ruby

I have written some Ruby code to import the Google n-gram data into a hash table, mapping word unigrams to their respective counts. I'm using symbols as opposed to strings for the keys. I've been running this code on a linux box for a while now with no problems. Running it on my Mac this morning yielded a symbol table overflow runtime...

Datamapper (ruby) - (Using the blog example) Getting the posts that don't have comments

Hi there, First SO question after using this place for reference on a lot of other things.. I'm nervous. DataMapper.. Using Blog model for example (posts, comments etc - http://datamapper.org/docs/associations.html) I'm trying to workout how to get the blog posts that don't have any comments.. So something like Post.all(:comments => {...