ruby

duplicating the md5 raw_output flag (raw bytes) in PHP 5 with Ruby's md5

Due to an absurd SOAP authentication scheme I need to md5 hash an API key with some other parameters. Unfortunately the only sample code provided is written in PHP and, for reasons I find unfathomable, it requires that the md5 hashing use the optional raw_output flag in PHP (http://php.net/manual/en/function.md5.php) which causes it to ...

Is there a way to get the expanded gzip file size without actually expanding?

Since expanding a large gzip file takes quite long time (sometimes over half a minute), I'd like to know the expanded size before I start the expansion (for progression report purpose). Is there a way of knowing it without actually expanding? Update: For file larger than 4G bytes (expanded size), there's no sure way of knowing the size...

How can my Rails app accept RAILS_GEM_VERSION minor version bumps

My rails project has this line in /config/environment.rb # Specifies gem version of Rails to use when vendor/rails is not present RAILS_GEM_VERSION = '2.3.2' unless defined? RAILS_GEM_VERSION As we now have 2.3.5 as the most recent upgrade, is there a way to make my environment.rb accept minor version bumps? (without I have to explic...

how to configure netbeans for ruby on rails ?

how to configure netbeans for ruby on rails ? ...

Set the font color in prawn

Im using prawn to generate a PDF output in a rails app. How do i change the color of the outputted text? ...

Alternatives to Yahoo Pipes

I've used Yahoo Pipes for some prototyping, but I'm unwilling reluctant to use it in full production as we'll have no control over it uptime etc. Is there an (ideally open source) alternative that I can run on my own server? Or any application that can convert a pipe into PHP or Ruby? ...

How do I sort this list ?

I have a list of lists. List<List<T>> li = { {a1,a2,a3 ... aN}, {b1,b2,b3 ... bN}, ... }; double foo(List<T> list) { // do something // e.g {1,2,3} // it = 1 + 2 + 3 return it; } Now I want to sort li in such a way that higher the foo(x) for a x higher it should appear in a sorted list. What is the best w...

Ruby: attr_accessor generated methods - how to iterate them (in to_s - custom format) ?

I need a Class which has an semi-automatic 'to_s' method (to generate XML in fact). I would like to iterate through all the automatic methods set up in my 'attr_accessor' line: class MyClass attr_accessor :id,:a,:b,:c end c=MyClass.new So far I'm doing a basic: c.methods - Object.methods => ["b", "b=", "c", "c=", "id=", "a", "a...

How to modify the default RoR behavior to AJAX CRUD?

I want a table to do CRUD, but I want it in an Ajax way, how can I modify the default RoR behavior, any suggestions on that? I tried comment these code in destroy method, but it don't work, it saw missing the destroy.erb: respond_to do |format| format.html { redirect_to(categories_url) } format.xml { head :ok } end ...

Ruby on Rails: How to gather values for child tables from a form?

Referencing question #2013421, I have the following RoR models: class Game < ActiveRecord::Base has_many :piles end class Pile < ActiveRecord::Base belongs_to :game end For the sake of argument, suppose Game has an attribute name, and Pile has an attribute type, both string. There are precisely 10 piles per game. I would like a ...

Another way to write: if some_variable && some_valiable.size == 2

Hi there, In Ruby & in RoR I oft find myself testing whether an object exists, then whether an object's properties match some criteria. Like so: if params[:id] && params[:id].size == 40 ...do stuff end Is there a more efficient way to do this? Something like: if params[:id].size == 40 rescue false but without using the rescue? ...

Rendering a Rails view to string for email

I'd like to send emails from a table every night at midnight, so I've created a model to track all communications to be sent. This Communication model stores who the letter is to, from, and the contents of the letter to be sent as html. The user enters a criteria to match for whom the letter is intended: state, country, favorite color,...

How do you prevent flash[:notice] from being rendered twice when redirecting from ApplicationController

I have a simple method in the ApplicationController that, when called, may set a 'flash[:notice]' then redirect to the root_url. The problem is that even though that method is only called once, the root URL renders that flash[:notice] TWICE. Here's a the method (which is a before_filter used in other controllers, and is defined in the ...

Ruby Program/Problem

Given a string of characters as input, without using regular expression or pattern matching, how to get the output, if the characters matches aaa should output 1 and if the characters matches aBa should output 2. (Note: Should not re-process characters so as to output both “1” and “2” when processing the same input) So for example: giv...

how to use WMI to discover a running batch (.bat) filename?

Currently with WMI's Win32_Process, I seem unable to detect if a batch file is currently running all it lists is CommandLine of cmd.exe, without telling me which batch file that particular cmd.exe is running. Anybody have any insights there? code snippet (ruby-wmi) many_args = 'batch_file.bat' procs = WMI::Win32_Process.find(:all) pro...

How to force Jruby to use inbuilt Ruby 1.9 instead of Ruby 1.8 which is default?

I have developed a Ruby on Rails application and successfully deployed on Weblogic using Jruby and Warbler (which creates a war file based on the settings in config/warble.rb). I believe although Jruby comes with inbuilt Ruby 1.8 and 1.9, by default it uses 1.8 and I want to test the same rails application in Ruby 1.9 within JRuby as I...

Rails app Hangs and Ruby uses 100% CPU

I have an apache2 server running Phusion Passenger. On this machine I have two virtual hosts setup each look like this (path's are different for the 2nd virtualhost...but other directives are the same) ServerName beta.mysite.us DocumentRoot "/var/www/beta/mysite/public" <Directory "/var/www/beta/mysite/public"> RewriteEng...

Name conflict when installing a ruby gem

I am hosting a ruby gem repository which hosts several of my gems for my applications. I am running into some problems when I try to install one of my gems that has the same name as a gem on rubyforge. gem.config --- :benchmark: false :update_sources: true :verbose: true :backtrace: false :sources: - http://gems.rubyforge.org - http:/...

inserting variable into find conditions => SQL query

ok, so probably best if i just paste code and then explain search = "your horses" exp1 = "" exp2 = "" myarray = search.split(/ /) mylength = myarray.length #this would return 2 in this case mylength.times do exp1 += "AND name LIKE ? " #this gives--> AND name LIKE ? AND name LIKE ? end fo...

dumb question alert: use *both* ruby on rails and python possible?

Hi, the front end and end-user data-collection we want to build in RoR since it's just some simple forms connected to a database. The integration with other external api's such as twitter and facebook and parsing of the data entered by the users we want to do in python, mostly because the developer for that part knows python. Is that p...