ruby

Is there an ideal transfer format for iphone web services?

I'm designing the back-end for an iphone application. I'd like to use Core Data. Is there an ideal transfer format for iphone apps? I'm leaning towards JSON unless there's some custom binary thing. I'm probably using ruby on the backend. For example, in the Flex/Flash world, you can install a small piece on your server that lets you se...

Sort an enumerable in descending order

What's the best way to sort an Enumerable in descending order? I've been doing @array.sort.reverse or @array.sort_by{|song| song.title }.reverse I suppose I could do something like @array.sort{|a, b| b.title <=> a.title}, but I find this hard to read and verbose. ...

Can DataMapper properties appear in multiple composite indexes?

I found that this issue had been discussed in Ticket #58 of DataMapper, apparently way back in 2007, but I can't find how to do it in the latest version (dm-core-0.10.2). I want to define two composite indexes, each of which are partially based on a certain property. I was hoping I could do this... class Stat include DataMapper::Resou...

loading an entire linked list in a single Ruby/MySQL query

I'm storing linked lists of data in records that look like this: CREATE TABLE IF NOT EXISTS `data_nodes` ( `record_id` int(11) NOT NULL, `prev_node` int(11) NOT NULL, `data` varchar(200) NOT NULL, PRIMARY KEY (`record_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; where prev_node is the record_id of the previous item in the list,...

Wrap a foreign API into a Ruby class

I use HTTParty to consume a foreign API, but how can I convert the response into a Ruby class or Rails model? ...

How to show errors that occur in a modular Sinatra Application which is hosted by Passenger?

I have an application class class MyApplication < Sinatra::Base # ... do something ... end and a config.ru file # ... load libraries ... run MyApplication I usually use Passenger as my development environment which works perfectly fine for a normal – non-modular – Sinatra application. But in this case I have no error output inste...

Ignoring apostrophes in sphinx indexes

In my sphinx config file, I have the following: ignore_chars: "U+0027" charset_table: "0..9, a..z, _, A..Z->a..z, U+00C0->a, U+00C1->a, U+00C2->a, U+00C3->a, U+00C4->a, U+00C5->a, U+00C7->c, U+00C8->e, U+00C9->e, U+00CA->e, U+00CB->e, U+00CC->i, U+00CD->i, U+00CE->i [SNIP]" (The charset_table entry is from here: http://speeple.com...

Protecting the content of public/ in a Rails app.

I'm maintaining a Rails app that has content in the public/ folder that will now need to be protected by a login. We're considering moving those folders of files into a path outside of public/ and writing a Rails controller to serve up the content. Before we begin writing this, I was curious if anyone else has ran into this sort of pro...

Can't install ruby 1.9.1 on MacOSX 10.6

Hi all, I can't seem to be get Ruby installed on my Mac. These are the steps I've taken so far: Downloaded the package from Ruby's site (http://www.ruby-lang.org/en/downloads/) Unpacked it running { tar xzvf ruby-1.9.1-p376.tar.gz } Went into the new ruby folder, and configured using {./configure} This is where the error happens. ...

Sorting an array by two values

Suppose I have an_array = [[2, 3], [1, 4], [1, 3], [2, 1], [1, 2]] I want to sort this array by the first value of each inner array, and then by the second (so the sorted array should look like this: [[1, 2], [1, 3], [1, 4], [2, 1], [2, 3]]) What's the most readable way to do this? ...

How can I compile Ruby to Javascript?

I'm working on a piece of logic that I would like to express on the server as well as in the browser. Something like validating a form where there must be certain logical relationships between the elements based on what has already been entered. So... If I can write the logic once and somehow end up with both Ruby and with Javascript, I...

quotes issue (ruby)

any idea how I can pass correct argument to xpath? There must be something about how to use single/double quotes. When I use variable parser_xpath_identificator = "'//table/tbody[@id=\"threadbits_forum_251\"]/tr'" gives me an incorrect value or parser_xpath_identificator = "'//table/tbody[@id="threadbits_forum_251"]/tr'" gives me an ...

is there a hash equivalent to a custom 'class variables'? (ruby)

I used hash of hashes to store settings in my code. I wonder if I can have something like class variable that is the same for all instances of the class for my @profile hash. So both profiles below would have general profile variable equal to both of them. I want the solution to use hash. @profile = { "vB4Discussions" => { #profile...

How to parse SOAP response from ruby client?

Hi I am learning Ruby and I have written the following code to find out how to consume SOAP services: require 'soap/wsdlDriver' wsdl="http://www.abundanttech.com/webservices/deadoralive/deadoralive.wsdl" service=SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver weather=service.getTodaysBirthdays('1/26/2010') The response that I get...

Rails ACL plugin that works with devise/warden?

As title, warden is very pluggable, I wonder if there is anything works with warden/devise? ...

How to use bundler gem binaries in path

I just started using bundler for gem packaging in vendor/. The problem is with certain gems (like rspec and cucumber) that have binaries. The binary path that is under my_app/vendor/gems/ruby/1.8/...cucumber-0.6.2/bin/ is not in my path, therefore when I go to run cucumber i get command cannot be found. What is the easiest way to execu...

Make dynamic method calls using NoMethodError handler instead of method_missing

Hello there, I'm trying to make an API for dynamic reloading processes; right now I'm at the point where I want to provide in all contexts a method called reload!, however, I'm implementing this method on an object that has some state (so it can't be on Kernel). Suppose we have something like WorkerForker.run_in_worker do # some cod...

Regex: Match this string

I can't figure this out: 22.584\r\n\t\t\tl-6.579-22 I want to match the "\r\n\t\t\t" and replace with a single space " ". Problem is the number of "\t", "\r", and "\n" fluctuates, as do the surrounding characters. Help! ...

Rails: How do I write tests for a ruby module?

I would like to know how to write unit tests for a module that is mixed into a couple of classes but don't quite know how to go about it: Do I test the instance methods by writing tests in one of the test files for a class that includes them (doesn't seem right) or can you somehow keep the tests for the included methods in a separate f...

Will upgrading gems break old Rails applications?

I have bunch of Rails apps running on Rails 1.x. I need to upgrade the gems so the question is, will these old apps still work after I upgrade gems? Thank you. ...