ruby

Importing gmail/yahoo/hotmail/aol address book with rails

Hello, I want to import address book of users from their gmail/hotmail/yahoo and aol address books. I am looking for a gem/plugin in rails which can help me do this. Any help is appreciated. Thanks. ...

Ruby 1.9 enumeration changes

So, I don't quite get Ruby 1.9 's changes on enumerators, but what I'd like is a lazy filtering/mapping on a collection, so for example how can I create a lazy enumerator that would be the equivalent of this ... (1..100).find_all{|x| x % 2 == 1}.map{|x| x * 2}.find_all{|x| x % 3 == 0} I tried passing a lambda to #enum_for, but it does...

How is a LocalJumpError thrown from the following lambda ?

I've been reading the Ruby Programming Language book by Flanagan-Matz Context: Difference between Proc.new and lambda w.r.t return statements The book states that a return within a lambda should not raise a LocalJumpError (since lambdas are akin to method calls). A return in a lambda just exits the lambda - not the method enclosing the...

How to pass more than one argument to a worker at backgroundrd

Hello! I'm trying to pass a list of arguments to a backgroundrb in documentation it says: MiddleMan.worker(:billing_worker).async_charge_customer(:arg => current_customer.id) but it only works for just one argument, I tried these but none worked for me args => [1,2,3] args => {:t=>"t", :r=> "r"} any ideas how to solve this?? ...

Why can't I create my database using "rake db:create"?

I've recently started reading up on Rails and while getting my development environment ready on Windows, I kept running into problems. So I opted to just work on the server space I have with asmallorange.com. Everything went smoothly until I tried created my database. When running rake db:create I get a response saying that it coul...

What is the opposite of url_for in Rails? A function that takes a path and generates the interpreted route?

Hi there, Brain's a little fried....How do I get a hash of the :controller and :action from a relative_path? This is basically the opposite of url_for. in the example below, "some_function" is the mystery function name I'm looking for...I know it's easy, just can't remember or seem to be able to find it in the docs. Like so: some_fun...

Respond to a SSH prompt before first command with ruby and Net::SSH

Hello, I'm trying to connect, using Net::SSH, to a server that immediately after login executes a script that requires input from user. The user has to enter "1" or "2" and will receive some data via in the terminal afterwards. My problem is that, although I am able to connect, I can not figure out a way to send "1\n" to the server and...

How to set rails_env for a script or batch file

I put my batch file in lib folder and use rails db configuration, active-record like this. require "#{File.dirname(__FILE__)}/../config/environment.rb" class Batch def hello Message.new do |t| t.title = "hello" t.save end end end batch = Batch.new batch.hello when excute batch ruby lib/batch.rb in developm...

Ruby Time.utc descrepencies

I'm running into discrepancies running the following command on different Ruby installations: Time.utc(2099, 12, 31, 23, 59, 59) On some systems I get an error, on some a valid response. Any ideas why this may be? ...

Building a "Semi-Natural Language" DSL in Ruby

I'm interested in building a DSL in Ruby for use in parsing microblog updates. Specifically, I thought that I could translate text into a Ruby string in the same way as the Rails gem allows "4.days.ago". I already have regex code that will translate the text @USER_A: give X points to @USER_B for accomplishing some task @USER_B: take Y p...

How to improve jRuby load time?

I have to wait quite long time (comparing to my friends machines) for executing scripts on jRuby, especially when I'm running rake tasks or tests. I've tried jRuby version 1.3.1 and 1.4.1 with and without ruby-debug gem and the same problem occurred in each configuration. The question is simple: Is there any way to improve jRuby load p...

How to Instantiate/Run a Ruby program (uses Watir) using Linux?

Scenario : I mapped a network drive on a Win XP machine and I double click a .bat file to execute this Ruby script. The .rb and .bat file reside on this networked drive. The batch file is as follows : Z: cd Z:\ABC\StatusCheck\ "C:\Program Files\Ruby\Bin\ruby.exe" Z:\ABC\StatusCheck\rubyScript.rb 6 The Ruby file is as follows : requ...

Ruby on Rails: How do you check if a file is an image?

How would you check if a file is an image? I'm thinking you could use an method like so: def image?(file) file.to_s.include?(".gif") or file.to_s.include?(".png") or file.to_s.include?(".jpg") end But that might be a little inefficient and not correct. Any ideas? (I'm using the paperclip plugin, btw, but I don't see any methods to ...

eventmachine and external scripts via backticks

I have a small HTTP server script I've written using eventmachine which needs to call external scripts/commands and does so via backticks (``). When serving up requests which don't run backticked code, everything is fine, however, as soon as my EM code executes any backticked external script, it stops serving requests and stops executing...

How do I check if a string has at least one number in it using Ruby?

I need to check to see if a string contains at least one number in it using Ruby (and I assume some sort of regex?). How would I do that? ...

Future posting with dateCreated in Wordpress via XMLRPC in Ruby

I'm reaching the end of my tether trying to schedule a new post through Wordpress' XMLRPC interface from Ruby. I am creating a new Time object and filling it with my date and time, I then call .xmlschema to get a datetime string in the correct format for Wordpress' XMLRPC interface. Unfortunately, Wordpress treats this as a string, and...

Raise exception on shell command failure?

I'm writing some scripts in Ruby, and I need to interface with some non-Ruby code via shell commands. I know there are at least 6 different ways of executing shell commands from Ruby, unfortunately, none of these seem to stop execution when a shell command fails. Basically, I'm looking for something that does the equivalent of: set -o...

In Ruby, why does a equality with nil ("Date.new == nil") return nil?

When writing some rspec today, I came across some unexpected behavior with comparing Date (and Time) instances to nil. Here's a sample using raw ruby (no Rails or other libraries): user@MacBook-Work ~ $ ruby -v ruby 1.8.7 (2008-08-11 patchlevel 72) [universal-darwin10.0] user@MacBook-Work ~ $ irb >> 1 == nil => false >> "string" == nil...

Ruby win32ole MS Access: How to find all the records updated since last export?

Hello, I am using win32ole module/library to gain access to an Access database. But I can't find as I can in Rails the created_at or updated_at columns in any of the tables in the database. I was wondering how does one finds rows that are updated, then? So I have require 'win32ole' connection = WIN32OLE.new('ADODB.Conneciton') connecito...

A problem I'm having with modules

I'm trying to define a static variable and methods in a module that will be extended/used by numerous classes. The following example demonstrates: module Ammunition def self.included(base) base.class_eval("@@ammo = [bullets]") end def unload p @@ammo #<-- doesn't work end end class Tank include Ammunition @@...