ruby

Ruby daemons vs daemon-kit gems: what are the pros and cons?

What are the relative pros and cons of: http://rubyforge.org/projects/daemons http://github.com/kennethkalmer/daemon-kit Which is more robust? Are there any other effective Ruby daemon management tools? ...

Ruby Methods: how to return an usage string when insufficient arguments are given

Hi, After I have created a serious bunch of classes (with initialize methods), I am loading these into IRb to test each of them. I do so by creating simple instances and calling their methods to learn their behavior. However sometimes I don't remember exactly what order I was supposed to give the arguments when I call the .new method on...

What is up with Shoooes.net (Ruby UI module)

I have been looking at ways to program a UI in ruby here, on SO, and on Google. Everyone keeps saying that Shoooes is the way to go. However every link to the site and the site of the person behind it has been failing for at least a week. So what's the deal with that, where else can I go for information on Shoooes? ...

[RAILS] Why is ssl_requirement clearing the Flash? (Chrome Mac)

I am using ssl_requirement and since setting it up, my application's Flash messages are disappearing. I've modified the plugin slightly as accounts can optionally have a domain mapped to their account. In that case the non-ssl areas of the site should use the mapped domain, whereas the ssl areas should use the subdomain: def ensure_pro...

What ORM to use in one process multiple db connections sinatra application?

Checked ActiveRecord, DataMapper, Sequel: some use globals (static variables) some require open db connection before loading source file with models. What ORM is better to use in sinatra application that uses different databases. ...

Ruby Hide Console

I am attempting to make a game written in Ruby using the Gosu library (http://www.libgosu.org/) but when I run the game, a console also shows. How do I make sure the console is hidden from the start? thanks in advance, ell ...

Can the opensocial API remotely search for users in orkut etc.?

Does anyone know if (and how) I can build an application (Java/Ruby/whatever) doing REST or RPC calls to a social network like Orkut (using opensocial) to search for a user by name or email address? So far I know that I can list all friends for a particular user ID, but I want to search among all users. Would I need to code it as an app/...

Extract number from string in Ruby

I'm using this code: s = line.match( /ABCD(\d{4})/ ).values_at( 1 )[0] To extract numbers from strings like: ABCD1234 ABCD1235 ABCD1236 etc. It works, but I wonder what other alternative I have to to this in Ruby? My code: ids = [] someBigString.lines.each {|line| ids << line.match( /ABCD(\d{4})/ ).values_at( 1 )[0] } ...

Help with Ruby Date Compare

Yes, I've read and done teh Google many times but I still can't get this working... maybe I'm an idiot :) I have a system using tickets. Start date is "created_at" in the timestamps. Each ticket closes 7 days after "created_at". In the model, I'm using: def closes (self.created_at + 7.days) end I'm trying to create another metho...

Ruby methods within Javascript within HAML

I have a jQuery script that adds a new field to a form, and this field contains dynamic information from an array. The problem is that I can't figure out how to add an array.each to populate the options of the select field within the javascript without breaking the HAML indentation and causing errors. Here is my best attempt that does n...

How would I detect horizontal-black lines using ImageMagick?

So I have what is essentially a spreadsheet in TIFF format. There is some uniformity to it...for example, all the column widths are the same. I want to de-limit this sheet by those known-column widths and basically create lots of little graphic files, one for each cell, and run OCR on them and store it into a database. The problem is tha...

Programming Technique: How to create a simple card game

Hi, as I am learning the Ruby language, I am getting closer to actual programming. I was thinking of creating a simple card game. My question isn't Ruby oriented, but I do know want to learn how to solve this problem with a genuine OOP approach. In my card game, I want to have four players, using a standard deck with 52 cards, no joker...

Multiple roles with attributes(?) in Capistrano

How can I pass along attributes to my tasks in capistrano? My goal is to deploy to multiple servers in a load balancer. I'd like to take each one out, deploy, and add it back in sequentially so no more than one server is down at any time. I'm thinking it would be something along the lines of... (and the hosts array would be generated d...

Mechanize complex form input name

I am trying to access a form in mechanize with ugly characters in the object name similar to this agent = Mechanize.new page = agent.get('http://domain.com) form = page.forms[0] form.ct600$Main$LastNameTextBox = "whatever" page = agent.submit(form) The problem is the $ in the html name is messing with ruby. Is there another method...

Ruby: counters, counting and incrementing

Hi, If you have seen my previous questions, you'd already know I am a big nuby when it comes to Ruby. So, I discovered this website which is intended for C programming, but I thought whatever one can do in C, must be possible in Ruby (and more readable too). The challenge is to print out a bunch of numbers. I discovered this nifty met...

Ruby: Is there a better way to iterate over multiple (big) files?

Here's what I'm doing (sorry for the variable names, I'm not using those in my code): File.open("out_file_1.txt", "w") do |out_1| File.open("out_file_2.txt", "w") do |out_2| File.open_and_process("in_file_1.txt", "r") do |in_1| File.open_and_process("in_file_2.txt", "r") do |in_2| while line_1 = in_1.gets do ...

Sorting an array in descending order in Ruby.

Hi, I have an array of hashes like following [ { :foo => 'foo', :bar => 2 }, { :foo => 'foo', :bar => 3 }, { :foo => 'foo', :bar => 5 }, ] I am trying to sort above array in descending order according to the value of :bar in each hash. I am using sort_by like following to sort above array. a.sort_by { |h| h[:bar] } However ...

Flushing a queue using AMQP, Rabbit, and Ruby

I'm developing a system in Ruby that is going to make use of RabbitMQ to send messages to a queue as it does some work. I am using: Ruby 1.9.1 Stable RabbitMQ 1.7.2 AMQP gem v0.6.7 (http://github.com/tmm1/amqp) Most of the examples I have seen on this gem have their publish calls in an EM.add_periodic_timer block. This doesn't work...

link_to passing paramater and display problem - tag feature - Ruby on Rails

I have gotten a great deal of help from KandadaBoggu on my last question and very very thankful for that. As we were getting buried in the comments I wanted to break this part out. I am attempting to create a tag feature on the rails blog I am developing. The relationship is Post has_many :tags and Tag belongs_to :post. Adding and dele...

How can I abstract out the core functionality of several Rails applications?

I'd like to develop a number of non-trivial Rails applications which all implement a core set of functionality but each have certain particular customizations, extensions, and aesthetic differences. How can I pull the core functionality (models, controllers, helpers, support classes, tests) common to all these systems out in such a way t...