ruby

can Ruby get the filenames in a folder if they have Unicode characters (on Windows Vista)?

i was writing a script on Windows Vista to move the files in a folder to another hard drive, but found that Ruby 1.8.6 or 1.9 both would get back filenames with Unicode characters in it replaced by "??????" so for example, the filename "Chart for ???????.doc" is returned so the file cannot be moved at all... i used filename.each_byt...

is mod_rails or Phusion Passenger finally the answer to Ruby on Rails Deployment?

I read from some books that Phusion Passenger is the answer to easy Ruby on Rails deployment. But my friend said that first there was Apache + bunch of Mongrels, and then lighttpd, and then nginx, and now Passenger, and it seems endless... he also said he uses dreamhost which uses Passenger, and sometimes he sees his request not being ...

How to run a basic asynchronous job within sinatra ?

I'd like to run a basic asynchronous job exec('curl -0 '+url) from a sinatra app, I've tried to do that with fork and detach but it seems bogus. (I'm on windows) ...

`autoload` raises an error but `require` does not (ruby)

In my Ruby program, I'm trying to lazy-load a library (crack for the curious). If I do this: require 'rubygems' require 'crack' Everything is working fine. However, when I try this: require 'rubygems' autoload :Crack, 'crack' A LoadError is raised. (no such file to load -- crack) Why is this error being raised? Is it because 'cra...

How to stop the 'gem' utility from accessing my home directory?

When I run gem install <somegem> command the gem utility tries to access my home directory. It contains some non-latin characters and installation fails because of that. For example: E:\ruby\bin>gem install <somegem> ERROR: While executing gem ... (Errno::ENOENT) No such file or directory - C:\Documents and Settings\<user> I...

Can Rails Migrations be used to convert data?

I'm trying to convert a column in my Rails app, for arguments sake let's pretend I'm trying to change the age column in my users table to a string representation rather than an int. In my migration I have this; def.self up add_column :users, :age_text, :string users = User.find(:all) users.each do |u| u.age_text = ...

can we rename our Rails folders and not have any side effects?

when starting Ruby on Rails programming, I will use rails first rails second and try out things in these "first" and "second" projects but as they get more mature i want to check them into SVN and develop further, so can i rename them into "superapp" or "web30" and check into SVN and develop further without any side effects? I...

How do deal with OpenX XMLRPC authentication / sessions

I am having trouble with Openx; here is the issue OpenX::Services::Base.connection returns the class variable @@connection which is populated by OpenX::Services::Base.connection if it has previously not been initialized. The problem with it being a class variable is that it persists across connections, which means if there is a lull i...

Google Analytics Alternative for a Rails Application

I am working on a project using Ruby on Rails and I need to monitor web requests to generate traffic analytics (hits, unique visitors etc), but I have been instructed that using an external service, such as Google Analytics, is unacceptable (don't ask me why, I may break down and cry). I can however, use a plug in or anything else which...

Learning Objective C without a Mac

I do not have a Mac, or an iPhone. However, the concept of taking C and making it more dynamic towards the idea of smalltalk, python or ruby is really attractive to me. I'd love to start on objective C. Is objective C just a syntax superset of C or is it really like C. As in, can it be compiled with gcc etc..? I do most of my program...

In Rails, how do I access the Request.ServerVariables like you do in ASP?

I want to access a given Requests ServerVariables, but I can't seem to find anything on Google on how to get access to the Server Vars of the request object. How do I do this or am I doomed to simply never know? An example of why I'd want to do this (but not actually what I want to do): User logs in, and you want to store the IP addres...

Set path for original images using paperclip in Rails?

The situation I have a simple model with an attached image using paperclip, which has a couple of processed styles for it (thumbnail, full, feature). At this point it works as it should, and makes a directory structure for each object in /public/assets/foo/, containing subdirectories for original, thumbnail, full, and feature. The prob...

Highlighting a textfield value.

Hi guys i am using a dropdownlist which have the value please specify other, when that value is selected in prompts out a textfield which has the value please specify other, but for the user to type in anything in the textfield he has to delete the value manually..i am looking for a code which can delete the value automatically when the ...

Is there a good DNS server library in ruby?

I want to create a test DNS server in ruby, but could not find anything suitable. I found pnet-dns(http://rubyforge.org/projects/pnet-dns/). This project is incomplete and buggy. Is there any alternative? ...

Sort a list of objects by using their attributes in Ruby

I have a list of Fruit structs called basket. Each Fruit struct has a name (a string) and a calories (an integer). I would like to sort basket so that: The Fruits with the highest calories appear first. For example, a fruit with 500 calories appears before a fruit with 400 calories. If two Fruits have equal calories, the Fruit whose na...

SimpleDB library with joins in Ruby

Is there a Ruby library for Amazon's SimpleDB that can generate joins from Ruby classes? For example, if you define Ruby classes for Game and Ball, and each Game has one Ball, code should be generated that queries for the appropriate Ball given an instance of Game, much in the way ActiveRecord works. RightAWS is the most popular Ruby A...

Randomly long DB queries/Memcache fetches in production env

I'm having trouble diagnosing a problem I'm having on my ubuntu scalr/ec2 production environment. The trouble is apparently randomly, database queries and/or memcache queries will take MUCH longer than they should. I've seen a simple select statement take 130ms or a Memcache fetch take 65ms! It can happen a handful of times per request,...

Is there a better way to find the location of a minimum element in an Array?

Right now I have def min(array,starting,ending) minimum = starting for i in starting+1 ..ending if array[i]<array[minimum] minimum = i end end return minimum end Is there a better "implementation" in Ruby? This one still looks c-ish. Thanks. ...

Which Algorithm Does Ruby's Sort method use?

When I sort an Array using the native sort method, which algorithm does RUBY decide to use? Is it data-dependant (i.e If the data is small it uses X algorithm else uses Y algorithm)? Is it a stable sort? What is the average time complexity? ...

Please introduce a multi-processing library in Perl or Ruby

In python we can use multiprocessing modules. If there is a similar library in Perl and Ruby, would you teach it? I would appreciate it if you can include a brief sample. ...