ruby

Ruby console application using text editor?

Hi there, I'm building a console application in Ruby. One of the things I'd like it to do is edit text files. It strikes me that the most reasonable course of action would be to launch whatever default editor the user has set up -- nano, vi, emacs... let the user decide. I'd like to pass it the name of the file that will be created/edit...

Ruby: Apply gsub to first and second array items

I have the follow line: text.gsub(/,\ /,'| ').first But in addition to the first item, I want to apply it to the second item. How can I do that? ...

Firewatir: Firewatir dynamic drop down issue

I am having any issue with selecting any item from the drop down. Below is the HTML from our site. The HTML looks like this <div class="x-form-field-wrap x-trigger-wrap-focus" id="ext-gen157" style="width: 170px;"><input type="hidden" id="parentEntity" name="parentEntity" value=""><input type="text" id="cmbParentEntityId" autocomplet...

Reversing a hash

I had taken from the database and sorted it according to the position. Then I had put the necessary datas into a Hash. After putting the data in hash and I printed the hash. But the result is in reverse order. So I want to reverse the hash. How can I do this? ...

Tests run from command line but not in RubyMine - No tests were found

I am trying to use RubyMine to run the tests in an existing project. Unfortunately, whenever I attempt to do so I receive the message that No tests were found and the bottom of test console output I see the message: Errors running test:units and test:functionals! Empty test suite. Process finished with exit code 1 I have tried runni...

Algorithm for matching all items with another item in same list, where some have restrictions

Given array [a, b, c, d, e, f] I want to match each letter with any other letter except itself, resulting in something like: a - c b - f d - e The catch is that each letter may be restricted to being matched with one or more of the other letters. So let's say for example, a cannot be matched with c, d c cannot be matched with e,...

I'm very sad cause migrating to Snow Leopard screwed up my ruby path.

Since I've migrated from Leopard to Snow Leopard I get $ ruby script/server Rails requires RubyGems >= 1.3.2. Please install RubyGems and try again: http://rubygems.rubyforge.org the only way to make it work is: $ /usr/bin/ruby script/server => Booting Mongrel => Rails 2.3.8 application starting on http://0.0.0.0:3000 So I guess s...

Calculate number of business days between two days

I need to calculate the number of business days between two dates. How can I pull that off using Ruby (or Rails...if there are Rails-specific helpers). Likewise, I'd like to be able to add business days to a given date. So if a date fell on a Thursday and I added 3 business days, it would return the next Tuesday. ...

RMagick + Ubuntu - wrong jpeg library?

I'm having an issue getting RMagick to behave on Ubuntu Intrepid. RMagick installed correctly, but when I attempt to use the JPEG manipulation functions, I get the following error: Magick::ImageMagickError (Wrong JPEG library version: library is 62, caller expects 80 However, when I look in /usr/local/lib, I see libjpeg.so.8.0.2 is i...

Array to Hash Ruby

Okay so here's the deal, I've been googling for ages to find a solution to this and while there are many out there, they don't seem to do the job I'm looking for. Basically I have an array structured like this ["item 1", "item 2", "item 3", "item 4"] I want to convert this to a Hash so it looks like this { "item 1" => "item 2", "...

Assigning a nested attribute with Formtastic

I've been trying to figure this one out for a while but still no luck. I have a company_relationships table that joins Companies and People, storing an extra field to describe the nature of the relationship called 'corp_credit_id'. I can get the forms working fine to add company_relationships for a Person, but I can't seem to figure out ...

How do I match a string up to the first comma (if present) with a Ruby regexp

I'm struggling to get a regexp (in Ruby) that will provide the following "one, two" -> "one" "one, two, three" -> "one" "one two three" -> "one two three" I want to match any characters up until the first comma in a string. If there are no commas I want the entire string to be matched. My best effort so far is /.*(?=,)?/ This produ...

Seed data for an American English dictionary.

I want to find seed data to load into my dictionary. I just need the word's orthographic representation (letters) and the definition. I'm looking for a single text file that contains this information to parse and then load into my db. I'm using rails so if there is a gem or plugin that can do this that would be nice if any knows about ...

How do you find the physical memory free on the machine in Ruby?

I would like to know how much physical memory is available on the system, excluding any swap. Is there a method to get this information in Ruby? ...

Issues with using subdomains with Cucumber/Capybara

I have successfully added the ability to use dynamic subdomains within my application. The issue is that when I run my Cucumber tests, I receive the following error when my application performs a redirect_to which contains a subdomain: features/step_definitions/web_steps.rb:27 the scheme http does not accept registry part: test_url.exam...

How to understand scripting language like Ruby from a C/C++/VBNET programmer perspective ?

I have been C/C++/VBNET programmer for a long time. Now Ruby advanced concept is attracting me. So I decided to learn how to use it.But the "Behavior" of Ruby used to confused me. I usually feel like can't completely control my Ruby program. Can you help me get clearly about this ? (Maybe some of your favorite guide about "Ideas" and ...

Rspec Test Error

Ruby 1.9.2, RoR 3.0.1. When I run 'rspec spec' I get this error. Can't really make sense of it. connor@connor-desktop:~/rubystore$ rspec spec /usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.0.1/lib/rspec/core/backward_compatibility.rb:20:in `const_missing': uninitialized constant Admins (NameError) from /usr/local/lib/ruby/gems/1.9.1/...

generating css file from new sass format (scss) with sinatra and haml

I am writing a sinatra app with haml and sass. When I try to link in the stylesheet with a scss extension located in my views folder I get the following error: NoMethodError at /nav.css undefined method `scss' Here is my get method get '/nav.css' do content_type 'text/css', :charset => 'utf-8' scss :nav end I have only gott...

Socket Programming - Sending/Receiving hex and strings

I have the following code in C#: Console.WriteLine("Connecting to server..."); TcpClient client = new TcpClient("127.0.0.1", 25565); client.Client.Send(BitConverter.GetBytes(0x02)); client.Client.Send(BitConverter.GetBytes(0x0005)); client.Client.Send(Encoding.UTF8.GetBytes("wedtm")); Console.Write("{0:x2}", client.GetStream().ReadByte(...

How to parse html source code with ruby/nokogiri?

I've successfully used ruby (1.8) and nokogiri's css parsing to pull out front facing data from web pages. However I now need to pull out some data from a series of pages where the data is in the "meta" tags in the source code of the page. One of the lines I need is the following: <meta name="geo.position" content="35.667459;139.70625...