ruby

mysql gem looking for an earlier version of libmysqlclient.16.dylib

I just upgraded to Mac OSX Snow Leopard, and recompiled mysql (5.1.39) with the Snow Leopard XCode. I also reinstalled the latest mysql gem. Now, when running rake db:migrate in a rails app, I get dyld: NSLinkModule() error dyld: Library not loaded: /usr/local/mysql/lib/libmysqlclient.15.dylib Referenced from: /usr/local/lib/ruby/...

How to implement a "callback" in Ruby

I'm not sure of the best idiom for C style call-backs in Ruby - or if there is something even better ( and less like C ). In C, I'd do something like: void DoStuff( int parameter, CallbackPtr callback ) { // Do stuff ... // Notify we're done callback( status_code ) } Whats a good Ruby equivalent? Essentially I want to call a ...

Rails ajax methods.

I have a method I want to call using AJAX in rails but I have no idea how to do so. The method is private and has no view. Right now all it SHOULD do is replace a div tags html to show a flash[:notice]. ...

Ruby on Rails: setting future "publishing" dates for blog postings

Hello, I'm trying to set blog postings to publish at certain dates in the future. I have in my Posting model: named_scope :published, :conditions => ["publish_at <= ?", Time.now] I'm using this in my controller to call the published postings: @postings = Posting.published The development server works fine, but I believe the pro...

Rhomobile supports graphics?

Does the rhomobile support drawing with 2-d(3-d) graphics or is the graphic capabilities limited to static images? ...

Reading content from Multiple Text Files

Looking for help in doing this: I have a directory full of text files that are named with a numerical ID. Each text file contains the body of a news article. Some news articles are segregated in different parts, so they are in different text files. The names are such 1001_1.txt, 1001_2.txt (These files contain two different pa...

How to do a getPixel() in Ruby on Win32?

How can you do a getPixel() in Ruby on Win32? It is either to get a pixel in a window or on the screen (dc == null). ...

How to capture a part of a screen using Ruby on Windows?

Instead of using some third party app, I'd like to write an app in Ruby that when invoked, will capture the full screen and save it in c:\screenshot\snap000001.png The graphic package is readily there, but how can you capture a region from the full screen so as to save it? This program is to be invoked by some hot-key, such as settin...

Clean install of Ubuntu Karmic, Ruby 1.8.7 (2009-04-08 patchlevel 160), jkraemer-acts_as_ferret (0.4.4), Rails 2.3.4 -- Errors with AAF

I have a fresh install of Ubuntu Karmic, Ruby and Rails. I checkout out a working (production) application. Created the databases and ran the rake tasks. Made sure I had all the required gems of which acts_as_ferret by Jens Krämer was one of them. Everything appears to be installed correctly. The gems are listed in environment.rb inclu...

Annoying Webrat/Selenium Warning when changing domain names

When I'm working with AJAX + Webrat in Selenium mode, I'll often have to specify real domains and subdomains. Consequentially I'll get this message a lot: 14:00:45.222 WARN - you appear to be changing domains from http://test.host:3001 to http://elabs.test.host:3001/dashboard this may lead to a 'Permission denied' from the...

Can Ruby print out time difference (duration) readily?

Can Ruby do something like this? irb(main):001:0> start = Time.now => Thu Nov 05 01:02:54 -0800 2009 irb(main):002:0> Time.now - start => 25.239 irb(main):003:0> (Time.now - start).duration => "25 seconds" (the duration method doesn't exist now)... and similarly, report 23 minutes and 35 seconds 1 hour and 33 minutes 2 days and 3...

Dynamic Inherritance in Ruby

Hi guys, I'm trying to make a Ruby class that is very flexible as to its type and hopefully can inherit properties from a number of other classes depending on the values its initialized with: class Test def initialize(type,etc) case type when "stringio" inherit_from_stringio_with_data(etc) when "list" inherit_...

Merging contents of array / hash (keys and contents) in Ruby

Arg! Someone replied with an answer, just as I edited the below! So I've put it back to what I had before. ** Original array setup ** myArray = [{"papers"=>[[1,2,3],[1,3,2]], "value"=>"1"}, {"papers"=>[[2,1,3],[2,3,1]], "value"=>"1"}, {"papers"=>[[1,2,3],[1,3,2]], "value"=>"0.5"}] I need to merge the contents ...

Ruby AlterEgo: Is there a way to find out what was the transition called in on_enter/on_exit/anywhere?

As title, I am talking about the alter-ego gem (http://alter-ego.rubyforge.org). I need to determine if I am going to execute my validation depending on the transition called. The best alternative I have now is add a callback to transition, but that's rather clumsy as I have to do it on every transition. ...

Create process as user in ruby

The following code is in a file called run.rb, the idea is to run ruby as a different user so I can do some testing. require 'rubygems' require 'win32/process' domain = 'WORLDWIDE' user_name = 'user' password = 'password' rubyScript = 'ruby test.rb' Process.create(:command_line => rubyScript, :domain => domain, :with_logon => user_name...

copy files from IIs6.0 server to client machine without showing file dialog window on click of button in ASP.NET 3.5

Hi, File.VBS file should be copied from IIS6.0(File.VBS file will be deployed in IIS along the ASP.NET3.5 application) server to Client “TEMP” folder with out opening the file download dialog box. Thanks! ...

ActiveRecord.find(array_of_ids), preserving order

When you do Something.find(array_of_ids) in Rails, the order of the resulting array does not depend on the order of array_of_ids. Is there any way to do the find and preserve the order? ATM I manually sort the records based on order of IDs, but that is kind of lame. UPD: if it's possible to specify the order using the :order param an...

How to document Ruby code?

Are there certain code conventions when documenting ruby code? For example I have the following code snippit: require 'open3' module ProcessUtils # Runs a subprocess and applies handlers for stdout and stderr # Params: # - command: command line string to be executed by the system # - outhandler: proc object that takes a pipe o...

Share global logger among module/classes

What is the best (proper) way to share a logger instance amongst many ruby classes? Right now I just created the logger as a global $logger = Logger.new variable, but I have a feeling that there is a better way to do this without using a global var. If I have the following: module Foo class A class B class C ... class Z end ...

Ruby App MVC framwork (not web)

Has anyone heard of a Ruby MVC framework for Apps/Scripts? When Rails appeared - it was a revolutionary tool because it brought MVC to the masses of web developers and for once forced them to use design patterns and conventions. I'm looking for something like that but for scripting mundane admin tasks that are to be ran from cron or by ...