ruby

Encryption is hard: AES encryption to Hex

So, I've got an app at work that encrypts a string using ColdFusion. ColdFusion's bulit-in encryption helpers make it pretty simple: encrypt('string_to_encrypt','key','AES','HEX') What I'm trying to do is use Ruby to create the same encrypted string as this ColdFusion script is creating. Unfortunately encryption is the most confusing ...

Rails form protection questions, hidden field

I have a live rails website and I want to have a form with a lot of fields on it. I have set up validations and allowed formatting for every field. I've tested it quite a bit and it seems to catch anything I throw at it. I think it's almost ready to go live, but I want to quadruple check if there's anything else I should do to protect it...

What is the state of Ruby as a compiled language?

Ruby has been around for a while now so I was wondering if there was any work being done on a compiler for it? I know that compiler design is hindered by things like Eval() so I would not expect implementations to be 100 percent accurate? My own searches have turned up sparse results. ...

respond_to? and protected methods

It may not be so obvious how respond_to? works in ruby. Consider that: class A def public_method end protected def protected_method end private def private_method end end obj = A.new obj.respond_to?(:public_method) # true - that's pretty obvious obj.respond_to?(:private_method) # false - as expected obj.res...

What Ruby and Rails Developers Ought To Know?

What should know the Entry Level, Mid-level, Senior Developer? Theoretical knowledge, development tools, gems and more. What issues are usually at the interview? ...

Get Number of Months passed in Ruby

Is there an easy way to get the number of months(over multiple years) that have passed between two dates in ruby? ...

Upload a Photo to Facebook with REST API and Ruby

It's much harder than you'd think: http://wiki.developers.facebook.com/index.php/Photos.upload The tricky part is how to create the MIME multi-part message in Rails, which Facebook requires. I'm also using a Ruby Facebook API gem (mini_fb) which signs my other requests, and in addition to having no idea how to set up the MIME multi-par...

Prime Number - Data while loading

Hi, I was trying in Ruby on Rails how to find a prime number. Here is my code : helper : app/helpers/test_helper.rb module TestHelper def prime_number? number index = 2 tmp = 0 while index <= number if tmp < 1 if (numbe...

Ruby send mail with smtp

I'm trying to send simple email via Ruby (no rails) on OS X, with XCode (which installs Ruby.) But I'm running into a problem with my smtp server which requires the email client to check mail before sending as a form of authentication. How can I get Ruby to authenticate with the smtp server in a "POP" fashion before I can send mail? Not...

Is File#print atomic when given multiple arguments?

For C-based implementations of ruby 1.8 and ruby 1.9, is File#print atomic when it is given multiple arguments? ...

Parsing some results returned by nokogiri in ruby, getting an error message

The following code returns an error: require 'nokogiri' require 'open-uri' @doc = Nokogiri::HTML(open("http://www.amt.qc.ca/train/deux-montagnes/deux-montagnes.aspx")) #@doc = Nokogiri::HTML(File.open("deux-montagnes.html")) stations = @doc.xpath("//area") stations.each { |station| str = station reg = /href="(.*)" title="(.*)"/ ...

Constructor overriding

I have a library with a class: class One def initialize puts "one initialize" end end I can not change the declaration and difinition of this class. I need create new class with my own constructor. Like this: class Two < One def initialize(some) puts some super end end one = One.new one = Two.new("thing") But...

Loading a page into memory in Rails

My rails app produces XML when I load /reports/generate_report. On a separate page, I want to read this XML into a variable and save it to the database. How can I do this? Can I somehow stream the response from the /reports/generate_report.xml URI into a variable? Or is there a better way to do it since the XML is produced by the sa...

No such file to load bundler error for Rails 3

I have a Rails 3 app ready for staging. I haven't got a VPS host set up yet. As I was planning to have everything on shared host for the first few months. Problem: cd myapp bundle check result: The Gemfile's dependencies are satisfied Passenger error: Error message: no such file to load -- bundler Exception class: LoadEr...

In Mechanize what is the cookiejar and how does it differ from cookies?

How does Mechanize::CookieJar differ from the Mechanize::Cookies array? There must be some difference but after poking around for a little bit I can't seem to find a good explanation? ...

Rails: How to to download a file from a http and save it into database

Hi, i would like to create a Rails controller that download a serie of jpg files from the web and directly write them into database as binary (I am not trying to do an upload form) Any clue on the way to do that ? Thank you Edit : Here is some code I already wrote using attachment-fu gem : http = Net::HTTP.new('awebsite', 443) http...

ruby regex, parsing html

Hello all, I'm trying to parse some returned html (from http://www.google.com/movies?near=37130 )to look for currently playing movies. The pattern I'm trying to match looks like: <span dir=ltr>Clash of the Titans</span> Of which there are several in the returned html. I'm trying get an array of the movie titles with the following c...

Return hash with modified values in Ruby

I'm trying this: {:id => 5, :foos => [1,2,3]}.each {|k,v| v.to_s} But that's returning this: {:id=>5, :foos=>[1, 2, 3]} I'd like to see this: {:id=>"5", :foos=>"[1, 2, 3]"} I've also tried variations of Hash#collect and Hash#map. Any ideas? ...

How to restrict the number of objects of a class to a given number in ruby?

how can i extend the singleton pattern to a number of objects for a class i.e. how can i have only 5 objects of a class at max and not more than that in ruby ...

implicit argument passing of super from method defined by define_method() is not supported. Specify all arguments explicitly. (ActionView::TemplateError)

Most of you should already know Pragmatic book's "Agile web dev with rails" (third edition). On page 537 - 541 it has "Custom Form Builders" code as follows: class TaggedBuilder < ActionView::Helpers::FormBuilder # <p> # <label for="product_description">Description</label><br/> # <%= form.text_area 'description' %> #</p> def s...