ruby

Garbage collection with Ruby C Extension

Hi I am working my way through Ferret (Ruby port of Lucene) code to solve a bug. Ferret code is mainly a C extension to Ruby. I am running into some issues with the garbage collector. I managed to fix it, but I don't completely understand my fix =) I am hoping someone with deeper knowledge of Ruby and C extension (this is my 3rd day wit...

Does/can Passenger use clusters like Mongrel?

I'm just curious if Passenger does or can utilize clusters like Mongrel can. If so, how can I specifically run Passenger with clusters? I'm using nginx. And if not, how does it outperform Mongrel so well? ...

Convert string to symbol-able in ruby

Symbols are usually represented as such :book_author_title but if I have a string: "Book Author Title" is there a built in way in rails/ruby to convert it into a symbol where I can use the : notation without just doing a raw string regex replace? ...

how to remove event attribute from html using Hpricot ?

I want to remove a list of dom events attribute from html? how to do this? like: before = "<div onclick="abc" >abc</div>" after = clean_it(before) // after => "<div>abc</div>" DOM_EVENT_TO_BE_REMOVE = "onclick|ondblclick|onerror|onfocus|onkeydown" // i want to remove these events // i want to do it like this def clean_it(html...

how to access mysql tables with jruby ?

basically i have a table full of data that needs to be processed. i need to somehow access mysql from jruby. which gem can I install on jruby ? where can i find some good tutorials on working with mysql and ruby ? I am not looking for ruby on rails.. ...

create regular express from string

Hi, Is there any way to create the regex /func:\[sync\] displayPTS/ from string func:[sync] displayPTS? The story behind this question is that I have serval string pattens to search against in a text file and I don't want to write the same thing again and again. File.open($f).readlines.reject {|l| not l =~ /"#{string1}"/} File.open(...

Ruby 1.8.7 compatibility

I had a exception when I switch to Ruby 1.8.7 on Snow Leopard ArgumentError: wrong number of arguments (1 for 0) /Library/Ruby/Gems/1.8/gems/activerecord-1.15.5/lib/active_record/connection_adapters/abstract/quoting.rb:27:in 'to_s' /Library/Ruby/Gems/1.8/gems/activerecord-1.15.5/lib/active_record/connection_adapters/abstract/quo...

Refactoring a regular expression check in ruby

I'm thinking there has got to be a cleaner way to check if a regular expression is not nil / is true. This is what I have been using: hold = (h4.text =~ /Blah/) if !hold.nil? ... end I tried: !(h4.text =~ /Blah/).nil? but it did not seem to work. ...

Ruby - DateTime for Database

Hello! I have a Database column with the syntax "0000-00-00 00:00:00". In PHP I would do date('Y-m-d H:i:s'); In Ruby, I do require 'date' now = DateTime::now() puts "#{now.year()}-#{now.mon()}-#{now.mday()} #{now.hour()}:#{now.min()}:#{now.sec()}" The result is: "2010-1-5 10:16:4" That's not okay. How could I create a "timestring...

Ruby - split a string

Hello! I have a string like " This is a test ". I want to split the string by the space character. I do it like this: puts " This is a test ".strip.each(' ') {|s| puts s.strip} The result is: This is a test This is a test Why is there the last line "This is a test"? And I need, that if there are two or more s...

How can I display the 1 to many and many to 1 relationship in RoR?

I have a table called "order" which has many "order_items" , each "order_items" is belongs_to "order" and "product". In the db, I have one record in order. the record is like this: orders table: id = 1 name= customer and the order_items table is like this: id=1 product_id=233 order_id =1 id=2 product_id=454 order_id =1 I have the ...

requeue a sweatshop job in RabbitMQ

I am working on a Rails application where customer refunds are handed to a Sweatshop worker. If a refund fails (because we cannot reach the payment processor at that time) I want to requeue the job. class RefundWorker < Sweatshop::Worker def process_refund(job) if refund Transaction.find(job[:transaction]).update_attributes(:sta...

How to embed a tag using content_tag in RoR?

I have this to generate a hyperlink for me: <%= link_to "Example", "http://example.com" %> And I want it display in the td tag, so I want to use this content_tag to help me: <%= content_tag(:td,"", :class => "example")%> I want the hyperlink in my td, so I have something like this: <%= content_tag(:td,<%= link_to "Example", "http:...

How can I fill a page in Div in RoR?

I have a div called "main", and I have two hyper link, one is called "Google", another is "Yahoo!" , I want the user click the "Google", and the google.com will fill in the main div within refresh, same as "Yahoo!". what should I do in RoR? ...

Ruby: I want a class called 'Thread' - but there already is one...Module ?

I think my brain died, but I thought there was a simple way of using 'Modules' in Ruby to create a namespace for my own classes - or did I dream that ? What I'm after is the Ruby equivalent to the Java-way of putting my class defs in a package ... Or do I have to just invent a new name for my objects ??? ...

How to use Ruby to scrape, build a session, and launch a page on a target site

I am wondering how to use Ruby to scrape a website, with the goal of launching a new browser with the destination page loaded. This is needed, because the destination page is not stateless, and requires a number of session parameters. For an example flow, see how Kayak.com does this. 1. Go to Kayak.com, and search for a hotel in Chica...

Build and run ruby without installing it to system directories

I've cloned the ruby 1.8.7 source tree. I can build ruby. But I can't figure out how to run it without installing it in system directories. How can I do it? Background: I want to use "git bisect" to figure out which build of Ruby introduced a new behavior in my code. I need to build and run ruby against a test program, multiple time...

What are the most useful TextMate bundles or plugins for Rails development.

I'm compiling a list of the most useful bundles and plugins for TextMate which are helpful for using while developing with Rails. I have two which I use religiously: Project Plus Zen Coding ...

Make one gsub call instead of five.

How can I replace this: lyrics = lyrics.gsub(/\n/,'').gsub(/^\{\"similar\": \[/, '').gsub(/\]\}$/, '').gsub(/^\{/, '').gsub(/\}$/, '') to something shorter and one gsub call? ...

How to pass variables from one lesscss stylesheet to an included stylesheet?

I am attempting to use lesscss to build a templating system where each template has 3 or 4 alternative colour schemes. So for example, I could have a red.less stylesheet that looks like this: @main_colour: #ff0000; @import 'main.less'; So, I only have one main.less stylesheet to maintain which contains all the main styles, and uses t...