ruby

Continuously read from STDOUT of external process in Ruby

I want to run blender from the command line through a ruby script, which will then process the output given by blender line by line to update a progress bar in a GUI. It's not really important that blender is the external process whose stdout I need to read. I can't seem to be able to catch the progress messages blender normally prints ...

Batch Looping A Model With Ruby

I know of the find_in_batches method for ActiveRecord, but this doesn't allow me to set my :order or :limit. I am trying to loop through my data, and for every 6 items I want to wrap them in a <div>. I was trying to whole... <% i = 0 @media.each do |media| %> <% if i%6 %><div class="section"><% end %> [...] <% if i%6 %></div><% en...

What exactly is a "role" in Capistrano?

What is the purpose and function of "roles" in a Capistrano recipe? When I look at sample recipes, I often see something like this: role :app, 'somedomain.com' role :web, 'somedomain.com' role :db, 'somedomain.com', :primary => true So it looks like a role is basically a server where Capistrano executes commands. If that's the case, ...

Removing anything between XML tags and their content

I would need to remove anything between XML tags, especially whitespace and newlines. For example removing whitespace and newslines from: </node> \n<node id="whatever"> to get: </node><node id="whatever"> This is not meant for parsing XML by hand, but rather to prepare XML data before it's getting parsed by a tool. To be more s...

How can I specify separate app and DB servers for Capistrano?

I'm trying to deploy a Rails app to a CentOS server running Passenger. The SVN repository and MySQL database are each hosted on separate machines. (In other words, there's a total of three separate hosts involved.) Here is my deploy.rb file (taken from the Passenger docs): set :application, 'myapp' set :repository, 'svn+ssh://user@svn...

PDFTK Alternative

We've been using a free commandline utility called PDFTK which we make a system call to from a Ruby on Rails app to split PDFs into individual pages. However, it only supports PDF Version 1.4 and back. Can anyone recommend another utility or gem/Rails plugin to similarly manipulate later version PDFs? Thanks ...

Enable dropping a file onto a Ruby script

I'm creating a small ruby script to resize images and save them in a specified directory. I'd like the application to be as transparent as possible. Is it possible to allow file dropping onto my Ruby script in all platforms? For instance, the user drags a file onto the script, which then takes the file path as an argument and resizes th...

How can I combine calls to Dir#[] in Ruby?

How could I refactor this code to use only one Dir[ ] call? Dir[ File.join('.', 'directory_a'), '*' ] + Dir[ File.join('.', 'directory_b'), '*' ] => [ contents of directory_a and directory_b ] ...

[Ruby] Updating a Hash

So I've got this hash here, and I have a loop. When the loop detects that the hash already has a value vendor = "something" -- and the loop's value is "something" -- I want it to just go to the hash and update some values (price, visits). To simplify this, basically I have an array of hashes, and when I find that I already have a hash ...

What software programming language is like Ruby?

I'm trying to learn C++, but it's hard. I'm thinking about trying to learning something else instead of C++. I prefer programming languages similar to Ruby. ...

How to enable ruby to see tk in the require tk statement?

I am starting to learn the very basics of ruby on my iMac running Leopard. The version that is now on my system is ruby 1.8.6 But, I independently also installed ( via MacPorts ) ruby 1.9 because that corresponds to the latest "PickAxe" book. The installation location for ruby 1.8.6 is in /usr/bin/ruby The installation location for ru...

Nokogiri oddness?

A sample of some oddness: #!/usr/bin/ruby require 'rubygems' require 'open-uri' require 'nokogiri' print "without read: ", Nokogiri(open('http://weblog.rubyonrails.org/')).class, "\n" print "with read: ", Nokogiri(open('http://weblog.rubyonrails.org/').read).class, "\n" Running this returns: without read: Nokogiri::XML::Document...

How to model and store recurring tasks in rails?

Cron solutions in rails are numerous and pretty good. That's not what I'm struggling with here. Instead, what I'm having trouble with is letting users create their own recurring tasks (like reminders) - specifically how to model and store these in the DB (a good UI for it is non-trivial too - would be awesome if there was code out ther...

Java/Ruby based IMAP proxy library

I'm looking to create an IMAP proxy to a custom back-end mail and document storage engine and was wondering if there are already any production-ready, stable libraries I can pull on for interacting with the client via IMAP so I just have to write the backend code for mailboxes, listing, retrieving messages, etc. ...

What is the best way to organize automatic payout at the website?

I have Ruby on Rails application. I can get money from users cards using ActiveMerchant. Now I need to make payouts to the some users based on application logic. For example, Get 10$ from Andrew Get 10$ from Mark Get 10$ from Mike ... application magic that finds who should get money ... Pay 30$ to Mark Generally, I can use not only...

Ruby to_yaml utf8 string

How can I make ruby to_yaml method to store utf8 strings with original signs but not escape sequence? ...

Ruby equivalent of Tie::FIle?

Is there a Ruby equivalent of Perl Tie::File module? ...

Why keep a copy of an app on the DB host?

A lot of Capistrano example recipes include a :db role. By default the deploy task exports the app code to all hosts in all roles. So that suggests that it's typical for people to keep a copy of their app on the DB host. Also, in Capistrano's distributed deploy.rb recipe, :deploy:migrate looks like this: task :migrate, :roles => :db, :o...

Why is attribute not saving in Rails?

I've added an "account" variable to a Rails app I'm running, and tested in the development environment with a mongrel server. Everything worked fine. I set my environment to production and use our Apache server, and suddenly nothing works. After a lot of debugging, I've found that the account variable is succesfullying being SET in my me...

Best practice: Multiple categories - best plugin for it (acts as taggable, acts as tree,...)

Hello, I'm trying to find the best solution: I have a usermodel and the user should be able to save the keywords (multiple contexts) which he is interested at. F.e. User-interessts: Sports: Checkbox(CB) fishing, CB Skyying, CB Tennis, CB Soccer Music: CB Metal, CB Techno, CB Folk, CB Charts, ... and so on... After the user saves...