ruby

CPU used by child processes spawned by ruby

If you spawn a child process in ruby (using Kernel.system for example), can it use a different CPU to the parent process? If so, can you use multiple threads (within the same CPU) in a parent process, and have each thread spawning a child process that can use a different CPU, even in ruby 1.8? (Background -- it's superscript.rb from t...

New to Rails, is this kind of performance normal?

I have an app and in it's only controller, an action is thus configured: def do_call response = <<EOF <real-time-stat> <awt type="integer">1</awt> <cc type="integer">5</cc> <cp type="integer">0</cp> <dc type="integer">0</dc> <ef type="float">100.0</ef> <rc type="integer">6</rc> <sl type="float">100.0</sl> <state type="integer">0</st...

Streaming a dynamic zip from Amazon S3

I am looking for a way to dynamically stream download a zip of files from Amazon S3. The application is hosted on EC2 and the files are stored on S3. Need to give users the ability to select from a group of files which will then get bundled up and downloaded to them. Have heard about a few Actionscript libraries (aszip and fzip) tha...

Is there a way in Ruby/Rails to execute code that is in a string?

So I have a database of different code samples (read snippets). The code samples are created by users. Is there a way in Rails to execute it? So for example I have the following code in my database (with id=123): return @var.reverse Is there a way for me to execute it? Something like: @var = 'Hello' @result = exec(CodeSample.find(...

Generate XML with soap4r without invoking the web service?

I have set up a soap4r client for a web service, and it's working fairly well. We're using it to send data from one database to another (don't bother asking about that... I know it's not optimal), but we're not entirely sure the mapping is correct, so it's often very handy to get the XML that a particular record would generate. Of cour...

Accessing item attributes in a Rails form

If I am inside a form block in Rails, e.g form_for @widget do |f| end and am thus able to do things such as f.text_field :attribute etc, how can I also find out what the value of different attributes are in order to carry out some display logic? For instance, something like form_for @widget do |f| f.text_field :some_property f....

PDF generation under ruby - block should not cut by page separator

My PDF consists of a number of blocks (actually, a list of quotations), they go one after another till the end of the document. If the text of a quotation does not fit on the page, the whole quotation should start from the top of the next page, instead of being torn apart. How can I implement that on any library under ruby? ...

Ruby server-side back end scripting tools/resources.

Hello, I am trying to learn how ruby is used in a server based back end environment. For example I want to be running a ruby script 24/7 on a server. What are the best practices for this and how does one go about doing this? Can anyone provide some resources on how to do this or if you could label what I am trying to do? I am unsure of...

Clearing the test database between unit and functional tests in Rails (factory_girl)

Recently I switched from fixtures to factory_girl to test my Ruby on Rails application. If I run rake test:units, to run the tests in my /units directory, they all run perfectly. The same is true if I run my functional tests (in my /functional directory) with rake test:functionals. However, if I simply run rake test, to run both my unit...

Ruby: Controlling printing in scientific notation

If I have an extremely long floating point number in Ruby such as: x = 123456789012345.to_f when it is displayed, say, via to_s, it appears in scientific notation: "1.23456789012345e+14" Is there any way to suppress the formatting in scientific notation, or on the other side of the coin, force it for extremely short floating poin...

Paperclip - View Issues

I am using Paperclip to upload numerous files to S3 (on production) and locally (in development) We started with images in which everything is working correctly. I recently developed a section to upload PDFs. The upload works beautifully but the view does not and this is where I need your help. This line of code: <% if product.marketi...

ncurses to external shell and back messing with keys

I have this ncurses application that is doing the standard recipe for temporarily dropping out of ncurses, running an external editor/shell/whatever, and then dropping back to ncurses when it's done. This ~almost works, except that the first few keypresses that ncurses gets afterwards are obviously bogus; ncurses thinks ^[ and A are see...

active record: create record from parent object...

this is what I mean: job has many docs. I want to create a doc, I can do: @doc = Doc.new(params[:doc]) but I'd like to enforce the parent-child relationship, since I already know the job.. something like this: @job.docs.new(params[:doc]) so that the job_id field gets ignored and only the @job object matters... does it make any se...

Should I use ON DELETE CASCADE, :dependent => :destroy, or both?

In a Rails app, I have foreign key constraints in MySQL which I set them all up manually, separate from my migrations. I'm trying to figure out whether I should use ActiveRecord's :dependent => :destroy option. For example, in my schema I have tables... users ----- log_entries ----------- user_id # Has FK constraint to users.id with ...

How to delete last line of file in Ruby?

Hey guys, probably a simple question but my google-fu is failing me and does not seem to be posted on SO yet... I basically have a file I am accessing and before I append to it I want to delete the last line from the file. Is there any efficient way of doing this in Ruby? This is what I am using to access the file: file = File.new("im...

Ruby: share common variables and methods across a set of scripts

...

for what purpose are there $deferr, $defout and why there is no $defin

For what purpose are there $deferr, $defout and why there is no $defin if there are $stderr, $stdout and $stdin, and also STDIN, STDOUT and STDERR Changing any of them will not change others ...

Importing SVG into an RMagick RVG session

We have some code that draws things using RVG in RMagick. We scale them at various sizes. What I'm trying to do is use a file that's saved as an SVG as a template. The problem is, is when I load an SVG using Magick::Image.read, and then 'use' it, it rasterizes it, and then scales it, instead of producing pretty vectors. Is there a way ...

(Ruby) Compiling dynamic applications for Windows?

Hi All, Does anyone have any insights regarding compiling Ruby code for Windows? I've tried both "Ruby2Exe" and "OCRA", but both present their own issues. Ruby2Exe keeps presenting vague or confusing warnings such as "can't modify frozen string". OCRA on the other hand seems to want to run your script and assumes that there are no dy...

Subtracting one Array from another in Ruby

I've got two arrays of Tasks - created and assigned. I want to remove all assigned tasks from the array of created tasks. Here's my working, but messy, code: @assigned_tasks = @user.assigned_tasks @created_tasks = @user.created_tasks #Do not show created tasks assigned to self @created_not_doing_tasks = Array.new @created_tasks.e...