ruby

Ruby URL regex matcher

Hey, I have some content with a list of URLs contained in it. I am trying to grab all the URLs out and put them in an array. I have this code content = "Here is the list of URLs: http://www.google.com http://www.google.com/index.html" urls = content.scan(/^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*...

Cucumber+Capybara: Problem with a scenario that redirects the browser outside of my app

Given I have a rails app And I'm using cucumber And I'm using capybara And I have an action that results in a redirect_to "http://some.other.domain.com/some_path" When I test this action Then the in-app portion of the test works fine But I see this error: No route matches "/some_path" with {:method=>:get} (ActionController::RoutingError)...

Ruby string encoding problem

I've looked at the other ruby/encoding related posts but haven't been able to figure out why the following is not working. Likely just because I'm dense, but here's the situation. Using Ruby 1.9 on windows. I have a set of CSV files that need some data appended to the end of each line. Whenever I run my script, the appended characters a...

Ruby Server #eliminate garbage build up

I have a working TCP/IP socket server that loads 3-flash files in succession. How can I unload previous files and eliminate the garbage build up? 2-Flash clients are active, 1-the loader, 2-the next Flash file being loaded, however "the Flash files don't unload." Maybe there's a "put - kill" method or something similar to addChild remo...

Scripting language for trading strategy development

I'm currently working on a component of a trading product that will allow a quant or strategy developer to write their own custom strategies. I obviously can't have them write these strategies in natively compiled languages (or even a language that compiles to a bytecode to run on a vm) since their dev/test cycles have to be on the orde...

Soap4r : the requested address is not valid in the its context.

Hello. I was wondering if somebody has seen this error before? C:/Ruby/lib/ruby/gems/1.8/gems/httpclient-2.1.5.2/lib/httpclient/session.rb:675:in `initialize': The requested address is not valid in its context. - connect(2) (://:0) (Errno::EADDRNOTAVAIL) from C:/Ruby/lib/ruby/gems/1.8/gems/httpclient-2.1.5.2/lib/httpclient/se...

Rails: How do I add an additional parameter to resource-based link_to call?

I have a resource defined in routes.rb like so: map.resources :users I like using the cleanest link_to option, which would be: link_to @user I'd like to add an additional parameter to this call, though: "view=local" If I were using the user_path, I'd do this: link_to user_path(@user, { :view => 'local' }) Is there a way to get ...

Method declared out side the class is included automatically?

Can someone help me make sense of the following? I have the following code in test.rb: class Dog end // bark is declared outside of Dog class def bark puts 'Woof!' end then in irb: >> source 'test.rb' >> a = Dog.new => #<Dog:0x117f614> >> a.bark Woof! => nil Why does method bark exist in Dog instance even though it is declared ou...

How do I build something when I know I'll get it wrong?

Background I have a personal project that I've been trying to build for around 5 years. In essence it's an online game - a web application. It's not a "money maker", just something that I really want to build, so finding the funding to hire a skilled team is very unlikely. I've built two fully-functional prototypes over the years, both...

Refactor my ruby anagram solver?

I recently had to write an anagram solver for a job interview. Here is my code. class Anagram def self.resolves?(first_word, second_word) @letter_counts = {} # Assuming that anagrams aren't case sensitive. first_word.downcase! second_word.downcase! count_letters(first_word, 1) count_letters(second_word, -1)...

Rest-client log in with authlogic

Hello, I am trying to use the Rest-client gem to do a few small tasks for my app which uses Authlogic to authenticate users. From Rest-Client's API, I see that one can post data necessary for the log-in process like this: require 'rest_client' RestClient.post "http://127.0.0.1:3000/user_sessions", {:user_session => {:username => 'myuser...

Modeling relationships between spots and checkins ala Foursquare

Here's the scoop: As a learning exercise, I'm trying to write a Rails clone of one of the many location-based games out there (Foursquare, Gowalla, etc.) I have Users who create and check in to Stores. In ActiveRecord terms: :user has_many :stores :store belongs_to :user But now I've created a third model - Checkins. The table behin...

can I download a file over http that have a space in the name? (ruby)

there is a space after the word Part in the file name I want to download. It looks like http.get doesn't pass the url_path correctly because you can download the file from the browser without any troubles. any suggestion how I can download a file if there is a space in the file name? require 'net/http' url = "http://www.onalllevels.co...

Ruby IRB output is messed up in the console on Windows 7

I am getting very strange outputs from my IRB console. Here it is: irb(main):001:0> File.dirname(__FILE__) => ←[0;31m"←[0;0m←[0;36m.←[0;0m←[0;31m"←[0;0m Seems like an encoding issue, right? I am not sure why this is happening. Any ideas how to fix it? ...

Get file size before downloading & counting how much already downloaded (http+ruby)

Can anybody help me to get the file size before I start downloading display how much % was already downloaded . require 'net/http' require 'uri' url = "http://www.onalllevels.com/2009-12-02TheYangShow_Squidoo_Part 1.flv" url_base = url.split('/')[2] url_path = '/'+url.split('/')[3..-1].join('/') Net::HTTP.start(url_base) do |htt...

Ruby - Evaluation woes

I'm trying to evaluate something like this but more complex, but I get a TypeError because apparently you can't convert a hash to a string. Without changing my entire script, is there a decent workaround for this already ugly workaround? hash = { :somestuff => "etc", ... } eval module + "::" + object + "." + function + "(" + hash + ")" ...

Is it possible to integrate Vaadin with Rails??? If so, how???

As i see Vaadin is a Java based UI framework. But it has some really nice set of widgets and a very good layout engine. Is it possible to integrate Rails and Vaadin? JSON perhaps?? ...

What is the optimal winning strategy for this modified blackjack game?

Questions Is there a best value to stay on so that I win the greatest percentage of games possible? If so, what is it? Edit: Is there an exact probability of winning that can be calculated for a given limit, independent of whatever the opponent does? (I haven't done probability & statistics since college). I'd be interested in seeing t...

download only from 1am - 8am (ruby)

I have a script running on windows box that downloads files from the net via http. I want it to download only from 1am - 8am (my ISP's off peak time). I am happy if already started download finishes after 8am but what is the best method to make sure that the script starts downloading after 1am? I want to run the script and go to sleep. I...

check if the value of a field changed in a before_update filter

Hi I have a database field where I want to store my password. In a before_create filter in my model I call a encryption function and save from clear text to encrypted text. I want now to use the before_update also for encryption, but only if the value has changed. How can I write a condition for checking if a field value has changed? ...