ruby

Algorithm for filling a matrix of item, item pairs

Hey guys, I have a sort of speed dating type application (not used for dating, just a similar concept) that compares users and matches them in a round based event. Currently I am storing each user to user comparison (using cosine similarity) and then finding a round in which both users are available. My current set up works fine for sma...

How to mock an TCP connecting in Cucumber

I want to test one program which can capture and send IP packets to some clients, so how to mock request or client in Cucumber? thanks ...

Ruby TCPSocket: Find out how much data is available

Is there a way to find out how many bytes of data is available on an TCPSocket in Ruby? I.e. how many bytes can be ready without blocking? ...

Watir, How can i fetch the errors it displays after running a test script and place it on a file

Hi, Im new to watir and running scripts from it. Just want to ask if how can I get or extract the error messages Scite displays on the left panel and import it to a textfile? or is it really possible to do? Thanks. ...

How to ensure a rake task only running a process at a time

I use crontab to invoke rake task at some time for example: every 3 hour I want to ensure that when crontab ready to execute the rake task it can check the rake task is running. if it is so don't execute. how to do this. thanks. ...

Rails 3 Layout + Querystring Problem

I'm trying to setup an ajax-based website that loads a fragment of a webpage when a specific combination of GET variables and HTTP Headers are given. GET /normal/html/page?ajax=true X-ajax: true What I've setup in my controller is: before_filter do |controller| if request_by_ajax? ApplicationController.layout false end end ...

Ruby Rail View Chain

I am new to Ruby on Rail and I have some questions. I have used the Builder to output XML. render :template => "xxx/yyy.xml.builder" However I want to add a filter to modify the output (i.e. signing it). I prefer not to generate the XML and modify it in the controller as I think it is a responsibility of a view. Is there any chain me...

How can I customize rails3 validation error?

If I have a text input name 'email', and if I set :message => 'Your email is wrong kind' the validation error message will have something like 'Email Your email is wrong kind.' I am wondering if there is any way to remove that orginal input name (in above case, its Email) from the validation error output in rails3. ...

Process.fork in Rails controller

We're doing some prototyping of a new app and noticed that one of the actions were taking forever to load (80-120 seconds). As a lot of the processing doesn't need to happen on page load (we can request the data via Ajax later), I thought of using Process.fork to allow the page to return immediately, while the processing still happening ...

How can I use content_for to put something in :yield

I am in ruby 1.9.2, rails3. So My website has some structures, and I want to put menu in a middle of my webpage. I am doing something like (within application.html.erb file) blahblahblah <div id="menu"> <%= yield :menu %> <div> blahblhablah I have a file menu.html.erb which has menu structure for the site. What can I do if I wan...

One question with EventMachine

require 'eventmachine' module EchoServer def post_init puts "-- someone connected to the echo server!" end def receive_data data send_data ">>>you sent: #{data}" close_connection if data =~ /quit/i end def unbind puts "-- someone disconnected from the echo server!" end end class ...

Can a task be dependent on file changes instead of another task?

I understand that the file task is executed dependent on some list of monitored files: file "file_to_edit" => ["a","b"] do do_x_here sh "echo 'a or b changed' >> file_to_edit" end So in this case, if a or b change, then do_x_here is executed as is the sh command. However, I have a situation where the same file would be changed wi...

Does imap.fetch(uid,'RFC822')[0].attr['RFC822'] return the entire message, including attachments?

Wondering if there's a way I can avoid fetching the attachments as well. ...

Rails 3 Tree Data Structure

I have bees searching for a good solution for Tree Data Structure in Rails 3. I'm trying to build a Tree menu. What do you use and what would you recommend? ...

Ruby/Rails: Is it possible to execute a default method when calling an instance (@instance == @instance.all IF "all" is the default method)?

I understand my question is a bit vague but I don't know how else to describe it. I've asked in numerous places and no one seems to understand why I want to do this. But please bear with me, and I'll explain why I want something like this. I'm using Liquid Templates to allow users to make some dynamic pages on my site. And for those tha...

Tell RubyGems to always search remote gems

hi all, is there a way to tell rubygems to always search for remote gems (instead of local)? I tried adding the following line to my ~/.gemrc gem: --remote but the problem is, that when i do gem list i get the following result ~$ gem list *** REMOTE GEMS *** - (1) 10io-jekyll (0.7.0) 1234567890_ (1.0) 2Performant (0.0.8) 360_servi...

How to access joined table attributes in Rails3 ?

I am having trouble accessing the attributes of a join in Rails3. There is two models/tables : Place and Address. One place can have many addresses (i.e. a specific street address, a "corner of" address, etc.). For historical reasons, the tables do not follow standard Rails conventions: class Place < ActiveRecord::Base set_table_name ...

parsing XSD with ruby

Hi i have a XSD that i want to parse. Note that i don't want validate it against a XML but get all enumerations that i have there. For example <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt; <xsd:simpleType name="fruitNames"> <xsd:restriction base="xsd:string"> <xsd:enumeration value="banana" /> <xsd:enumeration valu...

Ruby task: joining numbers to intervals

Hi! I've got an array of uniq numbers. Like this: [1,2,3,4,7,8,10,12]. It can be unsorted. What I need is to get intevals for this array: intervals_for [1,2,3,4,7,8,10,12] #=> "1-4, 7-8, 10,12" I've got my own solution: def intervals_for(array) array.sort! new_array = [] array.each do |a| if new_array.last and a == new_arr...

render based on a condition, rails

Hello, I have a form displaying a nested relationship. The call to render the nested child objects is made like below: <% if @fpimgblocks %>   <% f.fields_for @fpimgblocks do |builder| %>     <%= render 'fpimgblock_fields', :f => builder %>   <% end %> <% end %> @fpimgblocks is the result of a find, I have verified there are zero resu...