ruby

Ruby regex matching strings from an array?

I'm sort of new to regexs with Ruby, (or I suppose regex in general), but I was wondering if there was a pragmatic way to match a string using an array? Let me explain, say I have a list of ingredients in this case: 1 1/3 cups all-purpose flour 2 teaspoons ground cinnamon 8 ounces shredded mozzarella cheese Ultimately I need to split...

Ruby: How can I edit the contents of a CSV file?

As a follow up to this question, how can I edit the contents of a CSV file? I ultimately need to replace all instances of something and I need to do that before I open the file for parsing (with FasterCSV). So, using Ruby I need to open, edit, and save the CSV file. ...

Moving a file containing a space in ruby using FileUtils

Hi everyone, I'm using Mac OS X and I'm trying to write a little script that moves a file to a specific folder. I'm using the FileUtils API since I don't want to run system specific commands (system("mv a b"). The script looks something like this: #!/usr/bin/env ruby require 'rubygems' require 'escape' require 'fileutils' absolut_inp...

Heroku: Running imagemagick w/ paperclip

I have installed image magick on my mac os x computer and now I want to deploy it to heroku. I've installed the the paperclip plugin on heroku but I get this error when uploading an image: Paperclip::CommandNotFoundError I had this error before when I didn't have imagemagick instaledl on my computer before but now that I want to deplo...

Ruby/Rails - How to convert seconds to time?

I need to perform the following conversion: 0 -> 12.00AM 1800 -> 12.30AM 3600 -> 01.00AM ... 82800 -> 11.00PM 84600 -> 11.30PM I came up with this: (0..84600).step(1800){|n| puts "#{n.to_s} #{Time.at(n).strftime("%I:%M%p")}"} which gives me the wrong time, because Time.at(n) expects n to be number of seconds from epoch: 0 ...

mailing list using JQuery, Sinatra, HAML fails with "undefined" email address

Somehow, a simple form I have to sign up for a mailing list (which adds an email to a Google Apps Group, using gdatav2rubyclientlib) seems to fail occasionally. The form is submitted via POST through jQuery, and the Sinatra app (running on nginx/Passenger) handles the POST and emails me a confirmation. Occasionally, I get emails that "...

Rack rack.input variable getting truncated?

I wrote a piece of Rack Middleware to automatically unzip compressed request bodies. The code seems to be working just fine, but when I plug it into my rails app, I get a failure "Invalid JSON" from ActionController::ParamsParser. As a debugging mechanism, I'm writing both the zipped content, and the unzipped content to a file (to make...

portable ruby 1.9.2

Hi, I tried to make a portable(small sized) Ruby(1.9.2) that I can save in my repository, so whenever developer checked out the source code, they can build the code with Rake without having Ruby installed. AllInOneRuby works with Ruby version 1.8.7, but doesn't work with ver 1.9.2. from the comment at running-ruby-and-rake-and-albacore...

Cucumber Step Definition Regex Exclude Help

I need some help with a regular expression in a Cucumber step definition file. Many of my steps are of the type: Given I am on the search page I use this general pattern for most of my step definitions, and use the default Webrat regex to pick it up that looks like this: Given /^(?:|I )am on (.+)$/ do |page_name| visit path_to(p...

Migrating to Retrospectiva

Hey folks, We're interested in an Agile PM System and have picked out Retrospectiva, we really need to be able to migrate tickets out of our existing system and was interested in taking a look at the migration scripts. In there wiki they link to two scripts (trac and collaboa) http://retrospectiva.org/wiki/Migration However taking a l...

Ruby assignment inside an iterator

I want to convert the name "JOHN DOE-SMITH" to "John Doe-Smith" using the code: name = "JOHN DOE-SMITH" name_split = name.split(/\s/) name_split.each do |x| if x =~ /-/ name1, name2 = x.split(/-/) x = name1.capitalize + "-" + name2.capitalize else x.capitalize! end end puts name_split.join(" ") ...

does sinatra support all xmlhttp.readyState statuses?

my sinatra app returns only xmlhttp.readyState state 1 and 4. The Ajax request is processed and sinatra correctly returns its result. I wonder if I can get all xmlhttp.readyState states from sinatra. my sinatra code is like require 'rubygems' require 'sinatra' require "sinatra/reloader" require 'Haml' get '/index2?' do haml :...

Best way to create a blog with static pages in Ruby

I just visited the Static Website Generation on Ruby toolbox and I don't know which of applications listed there is best suited for a little blog engine. Basically I need: an index page with 1..5 of latest articles with shortened content; possibility to add few main pages and a menu to access them (breadcrumb optional); show articles s...

unable to load libtidy.dylib

Hi, I'm trying to run on my mac os 10.6 a Ruby script that apparently requires libtidy. I spent an hour trying to find an information on how to get libtidy installed. 'gem install tidy' didn't help I'm amazed that I was unable to find the answers in google :/ ...

How to divide feature and scenario in Cucumber ?

I need to manage some uses in system, so user management is a feature , and add/delete user is a Scenario? I want to know one principle to design them, thanks ...

Some sort of Ruby "Interrupt"

So here's what I'm doing -- I have a ruby script that prints out information every minute. I've also set up a proc for a trap so that when the user hits ctrl-c, the process aborts. The code looks something like this: switch = true Signal.trap("SIGINT") do switch = false end lastTime = Time.now while switch do if Time.now.min ...

How to increase max pool size in active record

Error "ActiveRecord::ConnectionTimeoutError - could not obtain a database connection within 5 seconds. The max pool size is currently 5; consider increasing it.:" How do I increase the max pool size ? DB CONNECTION DB_CONN = ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :dbfile => DB_FILE) ...

How to integrate Carrier site using rails application

Hi All, I am integrating the UPS, USPS, DHL and FEDEX with my rails application. For that i am using 'trackify' plugin to find the carrier type for given Tracking Number and for also finding the XML response from the respective tracking site. I want complete guide for each of the above about How to Integrate Tracking API's? ...

How do I remove the longest prefix that appears in an array?

I have two arrays, search and target. I want to find the longest sequence of elements of search that starts from the beginning of search and which also appears in the same consecutive order in target. Then I want to return a copy of target with those elements removed. Here are some examples: search = [4, "apple", 6, "turnip"] target = ...

How unique is PHP's __autoload()?

PHP's __autoload() (documentation) is pretty interesting to me. Here's how it works: You try to use a class, like new Toast_Mitten()(footnote1) The class hasn't been loaded into memory. PHP pulls back its fist to sock you with an error. It pauses. "Wait," it says. "There's an __autoload() function defined." It runs it. In that function...