ruby

get the last day' s visits google analytics

is possible to get last day's visits google analytics with jquery or ruby? thanks ...

Can't install Rmagick and Imagemagick on Windows 7.

Hi there, when I run gem install rmagick-2.13.1.gem from the directory in which rmagick-2.13.1.gem is I get an Error saying that it failed to build gem native extension, below which it says c:/Ruby192/bin/ruby.exe extconf.rb checking for Ruby version >= 1.8.5 ... yes Unable to get Imagemagick version ***extconf.rb failed*** Could not c...

Ruby, how to convert 1 to "first", 2 to "second"

Is there a built in method in ruby to support this. ...

Comparing objects in ruby

Consider this: class Aaa attr_accessor :a, :b end x = Aaa.new x.a, x.b = 1,2 y = Aaa.new y.a, y.b = 1,2 puts x == y #=>false Is there some way to check if all public attributes are equal in classes of same type? ...

Ruby 1.8.7 - Ruby 1.9.2 and Rails 3.0.0 'Encoding' Model Name Conflict

I have a Rails 3.0.0 application that has a model named 'Encoding' and is currently running on 1.8.7 fine. I'm trying to upgrade to 1.9.2, but the name 'Encoding' is conflicting with that version of Ruby. I tried creating a new project, and when running rails g model encoding with 1.9.2 it complains giving: The name 'Encoding' is e...

Array include any value from another array?

What's the best, most elegant/efficient way to test if an array contains any element from a second array? Two examples below, attempting to answer the question does 'foods' contain any element from 'cheeses': cheeses = %w(chedder stilton brie mozzarella feta haloumi) foods = %w(pizza feta foods bread biscuits yoghurt bacon) puts chees...

Why does this string comparison give that result in ruby?

k=[] path="E:/expr/amit.txt" name="amit" File.open("amit.txt").each do |l| k<< l end puts k[0] puts name.eql?("k[0]") O/p amit false why o/p containing false??it should give true ...

ImageMagick: What is this convert-command doing?

I'm trying to port a PHP script to Ruby and until now I only used ImageMagick to convert from one file-format to another. Meaning: Yes, I'm an ImageMagick newbie. ;-) Somewhere inside the PHP script the following code is executed: $output = array(); $returnValue = 0; $cmd = 'convert '.$pngFile->path.' -resize 1x1 -alpha on -channel o ...

Not Null in "count" or "find" function in rails

I'm trying to find the not null elements in a database @genus_counts = Table.count(:all, :conditions=> {:col1 => params[:gm], :col2 => nil}, :without => {:col3 => nil}) It's not recognising "without" function. I am in doubt to apply it as array value. @genus_counts = Table.count(:all, :conditions=> {:col1 => params[:gm], :col3 != nil...

Regular Expression problem in erb Rails

Dear All, I need to apply a regular expression in html.erb <% taxon_name.strains.each do |strain| %> <% taxon_name.strain_appendices.each_with_index do |strain_appendice, i| %> <% if ((strain_appendice.data_source =~ /LPSN/) && (strain.relevance =~ /^ty(.*)ain$/))%> <% if i == 0 %> <p><%= strain_appendice.appendix %> </p> <% strain.st...

Freeze in Python?

I have programmed in Python for a while, and just recently started using Ruby at work. The languages are very similar. However, I just came across a Ruby feature that I don't know how to replicate in Python. It's Ruby's freeze method. irb(main):001:0> a = [1,2,3] => [1, 2, 3] irb(main):002:0> a[1] = 'chicken' => "chicken" irb(main):003:...

How could I 'hide away' a complex group_by clause in Ruby?

In a Rails 3 app, I'm running a somewhat complex group_by and am curious if I can hide it away elsewhere, much like one can hide away ActiveRecord conditions in a scope. I realize group_by is an operation on an Enumerable, so scopes don't apply here, but my question is if there's a way to create a shorthand for this in a comparable way: ...

Page load time, when in RoR lifecycle do you start/stop a timer to get this stat?

Page load time, when in RoR lifecycle do you start/stop a timer to get this stat? I know I can create a before/after at the controller level, is there anything higher up in the chain that I get start/stop this timer? I want to get timings for a production release also, not just development mode where things are always slower. ...

How to get result of the previous action

Hi Inside rails console you can get the result of the previous operation with _ Is there any way to do such a thing inside ruby program? ...

Rackup with HTTPS support

I've found this question, which doesn't really solve my problem but at least maybe lets me phrase my question the right way. I have a simple Camping app that I launch via rackup. I'd like to be able to test the app over a secure connection (self-signed server cert would be fine) but since I don't have root on my development box it'd be...

Ruby - why can't and / or statements be on a separate line?

Hi all, I am writing a very simple ruby script and has a few checks: if true and true and true then else end Why can I not format it this way if true and true and true then else end Ruby blows up if I do it that way. I want do do it that way so my lines are crazy long. I simply made the criteria a function so that s...

How to save multiple initialized record with one save.

Take it as example. new_array = [] Country.all do |c| g = c c = c.clone c.country_name = "kkk" new_array << c end At this point my new_array containing multiple records .. How may i store all the values with one save or create ? Any other better way ? ...

How to copy multiple row with single column update.

I want to copy all the rows from my table with single column update. Example. Table County has 1000 rows and i want to copy all the rows with single column update. What is the proper way to do that ? ...

Cucumber: How to write snippets/step definitions in PHP?

I am trying to get Cucumber working to test a PHP application. So far I am able to get the feature to run by simplying running cucumber in my features directory. At the bottom of the results, it says: If you want snippets in a different programming language, just make sure a file with the appropriate file extension exists where cuc...

Silverlight developer, learning ruby, rails

Hello! As said in title I'm SL developer and want to learn ruby and after adopt rails. Which books/resources/screencasts you can recomend to get up and running quickly? I'll use Linux and chosed Netbeans as IDE but if i won't like it i'll use gedit. What can you say about this? ...