ruby

mysqlplus is better adapter than ruby mysql?

I want to know if the mysqlplus gem is a better database driver than the common Ruby mysql gem? I used to have some problems in my Rails application, like: ActiveRecord::StatementInvalid: Mysql::Error: MySQL server has gone away ...

Complete a Ruby Array

My application needs to deal with arrays of fixed size. The problem is that sometimes elements are nil but nil is a forbidden value. I think an easy way is to replace nil values with an the closest non-nil value (right before or right after). The nil values can be first, last or even multiples. Here are some examples of what I'm looking...

Ruby threading deadlocks

I'm writing a project at the moment that involves running two parallel threads to pull data from different sources at regular intervals. I am using the Threads functionality in ruby 1.9 to do this but am unfortunately running up against deadlock problems. Also I have a feeling that the Thread.join method is causing the threads to queue r...

Rails + C# - Reusing Models

I'm working on a project that has a website in Rails and a C# GUI that use the same database and data models. I'd like to share the (active)models between the two parts. Any ideas on how this is possible? ...

Ruby script to grab lyrics?

Anyone have a Ruby script to grab some lyrics from somewhere? ...

How many times was a Ruby gem installed via `gem install` or `gem update`

I am trying to find out how many times a gem was installed via gem install or gem update. For example, Watir 1.6.2: it was installed 97 times via gemcutter (http://gemcutter.org/gems/watir/versions/1.6.2) it is downloaded 4,027 times from http://rubyforge.org/frs/?group%5Fid=104 I have been told that 4,027 does not include installs ...

Invoking ONC RPC from Ruby?

I have a Ruby (Rails) app that needs to make some calls to a service exposed via ONC RPC. Is there a way I can readily accomplish this in Ruby or do I need to create a proxy service using another language? FWIW, my target platform is CentOS. Thanks! ...

ActiveRecord nested SELECT -- can I do it without manual SQL?

I have a table with (among other things) a name and a rank. I'd like to return the set of all unique names, but for each name returned, I'd like to pick the row with the highest rank. This is simple with two nested SELECT statements: SELECT * FROM (SELECT * FROM foo ORDER BY rank DESC) AS ordered GROUP BY name MySQL takes the first ...

Ruby: Split string at character, counting from the right side

Short version -- How do I do Python rsplit() in ruby? Longer version -- If I want to split a string into two parts (name, suffix) at the first '.' character, this does the job nicely: name, suffix = name.split('.', 2) But if I want to split at the last (rightmost) '.' character, I haven't been able to come up with anything more elega...

writing custom methods with def

Warning Rookie/newb mistakes contained within read at your own risk! Ok trying to put together some code to read and print a text based maze file. This is what I have so far: def read_maze( filename ) local_maze = [] mz_file = File.open(filename,"r") while ! mz_file.eof? do line = mz_file.gets.chomp local_maze = line.scan(/./) end mz...

shotgun gem explodes when starting a Sinatra app on windows

Sinatra app: require "rubygems" require "sinatra" get '/' do "Hello world. It's #{Time.now} at the server!" end windows XP with latest version of mongrel, sinatra, shotgun. ruby 1.8.6 running shotgun test_app.rb results in C:\Files\sites\sinatra>shotgun test.rb == Shotgun starting Rack::Handler::Mongrel on localhost:9393 Th...

Relation Between 2 Controllers

Hello, How can I define a relationship between two controllers. I have one controller called rides and another called registrant. Is there anyway I can access the registrant database from within the rides controller? I was thinking @registrant = Registrant.find(:first) from within rides, but that didn't work. Any suggestions? Thanks ...

Read one number from file into Variable in Ruby

I am a ruby newbie. Want to know how to read a number from a file to a variable. Anyone able to help please? Thanks in advance! ...

Rails and beyond

I feel like I'm an intermediate-advanced Rails programmer. I've written some small client apps. However, I feel like I'm missing something. I don't really understand HTTP; what a web server is; how networking works; what Mongrel is beyond just "script/server". Are there any good books to explain what HTTP is and other stuff I'm missing o...

pathfinding conditions def

Ok so I had to crack a Heineken for this one. Trying to solve a shortest path problem with a text file. My research took me to: link text link text pretty good information for my algorithm Basically, I'm trying to start out at 'S' for start and quit at 'F' for finish or return no solution message the two self styled tests or text fil...

Ruby Array group and average by hour

We get our data from a sensor which records and stores data like hashes. At any time it measures a few stuff like that: {:temperature => 30, :pression => 100, :recorded_at => 14:34:23} {:temperature => 30, :pression => 101, :recorded_at => 14:34:53} {:temperature => 31, :pression => 102, :recorded_at => 14:34:24} {:temperature => 30, :p...

gem cmd from a ruby script

hi I want to check with "gem outdated" if there are any gem updates. Is it possible to get the result of the gem software in a script as string or value? I don't want to execute system() oder something similar. thanks for your help ...

Trying to use accepts_nested_attributes_for and has_and_belongs_to_many but the join table is not being populated

I am learning RoR and trying to use accepts_nested_attributes_for and has_and_belongs_to_many to submit information that would traditionally be two forms. I have read on some sites they are compatible, some sites they aren't compatible, and some sites don't know. As reference, I am using Rails 2.3.4. I tried modeling my solution from ...

Errors with Ruby and File.open

Having problems with a Ruby script that uses File.Open Here is the code that I am speaking of... f = File.open(Socket.gethostname().gsub!(/[[:space:].]/,"")+".log","a") The issue is the + inside of .open, it is returning a error message saying its a undefined method. Anyone able to help? Edit: Here is some code from the class which ...

Opening router ports by UPnP in Ruby

I know it should be possible to communicate with a NAT/Router on a local network and ask for ports to be forwarded via UPnP, but I don't know any of the specifics. I've found a gem that looks like it might be useful, but beyond that I'm at a loss (The gem's homepage appears to be down). Does anyone have any pointers? ...