ruby

SQLite3-ruby extremely slow under 1.9.1?

I decided to upgrade my server to Ruby 1.9.1, and a lot of things are indeed much faster. However, I have a process that dumps a database to sqlite, and it's become glacially slow. What used to take 30 seconds now takes upwards of 10 minutes. The code does several create table statements, and then lots of inserts. The insert statements ...

Test (with RSpec) a controller outside of a Rails environment

I'm creating a gem that will generate a controller for the Rails app that will use it. It's been a trial and error process for me when trying to test a controller. When testing models, it's been pretty easy, but when testing controllers, ActionController::TestUnit is not included (as described here). I've tried requiring it, and all simi...

actionmailer formatted from

Hello everybody. I want to send emails with formatted sender such as "Support team [email protected]". If delivery method I wrote from "support team <[email protected]>" and from "\"support team\" <[email protected]>" but smtp server says #<Net::SMTPSyntaxError: 501 <support team <[email protected]>>: "@" or "." expected after "support" This means that rai...

Logging in with WebFinger and OpenID

I am messing around with WebFinger and trying to create a small rails app that enables a user to log in using nothing but their WebFinger account. I can succesfully finger myself, and I get back an XRD file with the following snippet: Link rel="http://specs.openid.net/auth/2.0/provider" href="http://www.google.com/profiles/{redacted}"/...

Get used color names from image

Hello, I would like to check what colors is present in a image. This will be stored in the database and used for a search form. (red=1, green=1, blue=0, yellow=1, black=1, white=1 etc.) img = Magick::Image.read('phosto-file.jpg').first img = img.quantize(10 h = img.color_histogram pp h {red=12815, green=18494, blue=15439, opacity=0=>13...

Strange Ruby String Selection

The string in question (read from a file): if (true) then { _this = createVehicle ["Land_hut10", [6226.8901, 986.091, 4.5776367e-005], [], 0, "CAN_COLLIDE"]; _vehicle_10 = _this; _this setDir -2.109278; }; Retrieved from a large list of similar (all same file) strings via the following: get_stringR(string,"if","};") And the fun...

JRuby: import vs include vs java_import vs include_class

why so many different ways to include Java classes into JRuby? What are the differences? Which one should I use? ...

Any other ways to install heroku except gem install

Hi, Command gem install heroku failed with following messsage and I have tried the solution here , but failed also. So , is there any other way i can install heroku? WARNING: RubyGems 1.2+ index not found for: http://gems.rubyforge.org/ RubyGems will revert to legacy indexes degrading performance. ERROR: could not f...

Call nested rake file from the root directory

How can I run rake file for a nested project from the root directory? (2 cases: from console and from the root rakefile). Assume that I cannot modify the nested rakefile and that it must have 'libs/someproject' as the working directory. Here is my project structure: -root --rakefile.rb --libs ---someproject ----rakefile.rb ...

Ruby in DOS CLI, How to do?

I see in a lot of the tutorials and how to pages, they use the following, or something similar ruby C:\test.rb Which would parse test.rb to the interpreter and ... execute the script. But how is this done a on a windows? Ruby isn't a recognized internal command (as per the DOS output)? I know how to do all these things on Linux, and i...

Ruby: Integer.times - how do I know what iteration I'm in?

Let's say I have some_value = 23 I use the integer and the .times to loop. Inside the iteration, is there an easy way, without keeping a counter, to see what iteration the loop is currently in? ...

Configurable ruby logger setup: Logger.new().level = variable

Hi, I want to change the logging level of an application (ruby). require 'logger' config = { :level => 'Logger::WARN' } log = Logger.new STDOUT log.level = Kernel.const_get config[:level] Well, the irb wasn't happy with that and threw "NameError: wrong constant name Logger::WARN" in my face. Ugh! I was insulted. I could do this ...

In Ruby how do you sort one multi dimendional array by another multi dimensional array?

Lets say I have an array : a=[[1,2,3],[4,5]] and I have another array : b=[[2.5,1.5,3.5],[1.5,2.5]] I need to sort 'a' with respect to 'b'. i.e the output should be = [[3,1,2],[5,4]] I tried but my code seemed to be very lengthy. It would be great if you could help me out.Thanks! ...

Detecting OS X camera with Ruby

I'd know how to do this with AS3, but ruby search turns up nothing. Any help please. ...

Duplicating an array of strings.

arr = ["red","green","yellow"] arr2 = arr.clone arr2[0].replace("blue") puts arr.inspect puts arr2.inspect produces: ["blue", "green", "yellow"] ["blue", "green", "yellow"] Is there anyway to do a deep copy of an array of strings, other than using Marshal as i understand that is a hack. I could do: arr2 = [] arr.each do |e| ar...

How do I Order on common attribute of two models in the DB?

If i have two tables Books, CDs with corresponding models. I want to display to the user a list of books and CDs. I also want to be able to sort this list on common attributes (release date, genre, price, etc.). I also have basic filtering on the common attributes. The list will be large so I will be using pagination in manage the load...

Ruby regex match specific string with special conditions

I'm currently trying to parse a document into tokens with the help of regex. Currently I'm trying to match the keywords in the document. For example I have the following document: Func test() Return blablaFuncblabla EndFunc The keywords that needs to be matched is Func, Return and EndFunc. I've comed up with the following regex: (...

Start or ensure that Delayed Job runs when an application/server restarts.

Hi there, We have to use delayed_job (or some other background-job processor) to run jobs in the background, but we're not allowed to change the boot scripts/boot-levels on the server. This means that the daemon is not guaranteed to remain available if the provider restarts the server (since the daemon would have been started by a capis...

Exclude some ids from result in Rails ActiveRecord

I have following statement for query articles from some sections Article.all(:joins => :sections, :conditions => { :sections =>{ :id => [3, 4, 6, 7, 8, 9] }, :id_not_in => @some_ids }, :limit => 4) Variable @some_ids is array with ids of articles wich must be excluded from result. ...

where can I find a good ruby excel parser that also had good documentation?

Hi All, I've spent some time today looking for a pure ruby library that will parse an excel workbook. I could find the parseexcel gem in the repos, but the problem is that I can't find any documentation on it. and the rdoc is pitiful. so, my question is 1) is there good documentation out there for this gem? 2) if not, is there another g...