Is there an easier way than below to find the longest item in an array?
arr = [
[0,1,2],
[0,1,2,3],
[0,1,2,3,4],
[0,1,2,3]
]
longest_row = []
@rows.each { |row| longest_row = row if row.length > longest_row.length }
p longest_row # => [0,1,2,3,4]
...
As you can see in the current code below, I am finding the duplicate based on the attribute recordable_id. What I need to do is find the duplicate based on four matching attributes: user_id, recordable_type, hero_type, recordable_id. How must I modify the code?
heroes = User.heroes
for hero in heroes
hero_statuses = hero.hero_statuse...
Hi,
I need to run a ruby client that wakes up every 10 minutes, takes a screen-shot (ss) of a users screen, crops part of the (ss) out and use's OCR to check for a matching word....its basically a program to make sure remote employees are actually working by checking that they have a specific application open & the case numbers shown ch...
I have an issue where Passenger is not detecting the config.ru file for the following nginx server
server {
listen 80;
passenger_enabled on;
server_name callumj.com cjlondon.com;
access_log logs/callumj.access.log;
root /webapps/callumj_com/public;
}
Nginx just seems to ignor...
I have the following expression:
^\w(\s(+|-|\/|*)\s\w)*$
This simply looks to match a mathematical expression, where a user is prompted for terms separated by basic operators (ex: price + tax)
The user may enter more than just 2 terms and one operator (ex: price + tax + moretax)
I tested this expression in Rubular http://rubular.com/...
@string = "Sometimes some stupid people say some stupid words"
@string.enclose_in_brackets("some") # => "Sometimes {some} stupid people say {some} stupid words"
How should the method enclose_in_brackets look ? Please keep in mind, I want only enclose whole words, (I don't want "{Some}times {some} stupid....", the "sometimes" word shou...
I'm wondering if writing functions like this is considered good or bad form.
def test(x)
if x == 1
return true
else
return "Error: x is not equal to one."
end
end
And then to use it we do something like this:
result = test(1)
if result != true
puts result
end
result = test(2)
if result != true
p...
I want to replace the inner_text in all paragraphs in my XHTML document.
I know I can get all text with Nokogiri like this
doc.xpath("//text()")
But I want only operate on text in paragraphs, how I can select all text in paragraphs without affecting eventually existent anchor texts in links ?
#For example : <p>some text <a href="/">...
Hello, so I have this big method in my application for newsletter distribution. Method is for updating rayons and I need to assign a user to rayon. I have relation n:n through table colporteur_in_rayons which has attributes since_date and until_date.
I am a junior programmer and I know this code is pretty dummy :)
I appreciate every s...
If i have a # {} , like #{results}, in the snippet below:
results = Array.new
f = open("/Users/kahmed/messages", "r")
f.each_line do |line|
results << "#{$.} #{line}" if line =~ /NFE/
put #{r...
I have a rails webapp which internally connects to another request server. At times , ruby process gets stuck in close_wait state and stop responding and needs a restart. i guess this happens only when the request server which the rails app connects to is restarted. But am not completely sure of it. Any help appreciated on how should i g...
So, I'd like to be able to make a call
x = MyClass.new('good morning', 'good afternoon', 'good evening', 'good night',
['hello', 'goodbye'])
that would add methods to the class whose values are the values of the arguments. So now:
p x.methods #> [m_greeting, a_greeting, e_greeting, n_greeting,
r_g...
Hi,
I am trying to write a Ruby script in one file.
I would like to know if it is possible to write the "main" function in the beginning, having the other functions that are used by main, defined after it. In other words, I would like to call a not yet defined function, so that they do not depends on definition order. Just changing the...
I want to create a binary executable for a relatively simple script that would not require people to install macruby or HotCocoa. The script is here. I've understood that I want to use the --static option for the compiler and I'm using the following command:
macrubyc -o postprocessor --static postprocessor.rb
I get the following error...
Hi.
I've got form for some model A, which has got few fields:
tile
description
...
colors
colors are selected from multiple select and options are ['red', 'green', 'blue', 'yellow']. User can choose colors as many as he wants. I don't think that making Color model and has_many relationship is good solution here to store colors data...
Hey Guys,
I'm participating in the 2010 code jam and I solved two of the problems for the small data sets, but I'm not even close to solving the large data sets in the 8 minute time frame.
I'm wondering if anyone out there has solved the large data set:
What hardware were you running on?
What language were you running on?
What perfor...
can I have some examples of how you organize your Shoes apps? I mean, simply using a Shoes.app{} block and instance variables is clumsy.. I'd like to achieve a MVC like structure.. I'm used to it (from rails, FLEX frameworks and others..) and would like to recreate something similar..
...
Having a bit of difficulty finding out the proper way to mix in code that I put into the lib/ directory for Rails 2.3.5.
I have several models that require phone validation. I had at least three models that used the same code, so I wanted to keep things DRY and moved it out to the lib/ directory. I used to have code like this in each mo...
Hi, I'm trying to build a multidimensional array dynamically. What I want is basically this (written out for simplicity):
b = 0
test = [[]]
test[b] << ["a", "b", "c"]
b += 1
test[b] << ["d", "e", "f"]
b += 1
test[b] << ["g", "h", "i"]
This gives me the error: NoMethodError: undefined method `<<' for nil:NilClass. I can make it work ...
I'm planning to write an application that should handle incoming mails. Basically it will act more like a ticketing system than a webmail, so I'm only interested in receiving emails, and not sending them.
I have made a simple prototype that downloads mails and displays the text with downloadable attachments in a web page, but handling m...