ruby

How to convert a string or integer to binary in Ruby?

Let's say I need to make integers 0..9 and math operators + - * / binary strings. So 0 = 0000, 1 = 0001, etc.. Is there a way to do this with Ruby 1.8.6 without using a library? ...

How do you communicate between Rake tasks?

Let's say I have a target who needs to compile some files. That target has another target as a prerequisite, one that obtains the files. Let's say this: task :obtain do # obtain files from somewhere end task :compile => :obtain do # do compilation end Let's say that the :obtain target doesn't always places the files in the same f...

Why isn't Python installed on Windows by default?

Or any other normal scripting language for that matter. I know there is VBScript and JScript. But I don't really like those for any kind of computing. I would really love to have python or ruby (or perl) interpreter installed with windows by default so when I write small console applications I wouldn't need to distribute whole python in...

json parse error in ruby - unexpected token at

Hi, I get errors at a lot of places when trying to retrieve ticker symbols for US companies from http://d.yimg.com/autoc.finance.yahoo.com/autoc?callback=YAHOO.Finance.SymbolSuggest.ssCallback&query=Wal-Mart I have tried to: resp = Net::HTTP.get_response(URI.parse(url)) data = resp.body qwe = data.split("symbol") p qwe[1] arr1 = ...

Query with Ruby on Rails

Hi: I'm struggling with a rails query. Finally, I want to make a JSON response with the following contents: A listing of all countries which have at least one company, associated through "Address" and a count of how of how many companies reside in a country. Here is my simple model structure: class Country < ActiveRecord::Base has_...

Custom ERB tag replacement

How can I get ERB to replace tags in a format other than <%= %> for example: {{ }} Thanks ...

How to read form-data with ruby

Hi, In my controller the result of request.body.read is: ============= --AJAX-----------------------1267183973160 Content-Disposition: form-data; name="1261400603_page_white_word.png"; filename="1261400603_page_white_word.png" Content-Type: application/octet-stream thefile --AJAX-----------------------1267183973160 Content-Disposition...

Understanding Symbols In Ruby

Despite reading this article, I'm still confused as to the representation of the data in memory when it comes to using symbols. If a symbol, two of them contained in different objects, exist in the same memory location, then how is it that they contain different values? I'd have expected the same memory location to contain the same val...

Ruby open-uri, returns error when opening a png URL

I am making a crawler parsing images on the Gantz manga at http://manga.bleachexile.com/gantz-chapter-1.html and on. I had success until my crawler tried to open a image (on chapt 273): bad URI(is not URI?): http://static.bleachexile.com/manga/gantz/273/Gantz[0273]_p001[Whatever-Illuminati].png BUT this url is valid I guess, because I...

Rails I8n: Use default locale when the requested locale (from HTTP header) is not available?

Hi: In my Rails ApplicationController I have added the following methods (from rails guide docs) to support I8n based on http accept language header info. Is there a way to check if the requested locale is available and if not, use the 'english' default locale as marked in environment.rb? Otherwise I get "translation missing" when an unk...

Ruby (or Python) Instead of Shell

Since I am conversant in Ruby, I am about to script a few things on OSX using it. But then I thought, perhaps I am missing the boat. I know a lot of reasons to prefer Ruby over Bash (or whatever sh-compatible command language interpreter), but I don't know any reasons not to. What is the upside of programming the shell directly? I inten...

Installing Ruby choices

I need to setup my laptop for ruby development. At the moment I use MAMP Pro for my PHP apps, but now I'm branching out into Rails development I feel that I should get setup correctly. Are there any advantages to using SQLite rather than MySQL for local developing and then deploying it to a MySQL database? Am I on the right track? Any ...

Is it possible to use in a Rakefile tasks from another one?

I have some Rake tasks I'd like to use in my Rakefiles. Is it possible to include tasks defined in one rakefile from another rakefile? ...

How do I override the RJS MIME Type in Rails 2.3?

I have an app running Rails 2.3.5 that has a JSON API for much of it. A contractor came in and did some work on the app and used RJS in a few places. Some of those controller actions that are using RJS for the main web site also need to be part of the API. The problem is that JSON API requests trigger the RJS responses, which is not w...

How to install gems from RubyForge?

I am trying to install ruby-mp3info as a gem on my computer. Running sudo gem install ruby-mp3info seems to work OK. In my environment.rb file, I added config.gem "ruby-mp3info". When I try to run the server, it fails, claiming I have some missing gems Following the error message's advice: Run `rake gems:install` to install the missing ...

Memcached rails api - multi set support

Is there a way to set multiple keys of a Memcached instance in one call in Rails? i.e. cache.set_multi("k1" => "v1", "k2" => "v2") ...

Ruby regular expression end of line

I am trying to find the variables in a string, e.g. "%0" can not be found. %1 Please try again %2 I need to know how each variable ends (space, period, end of line) cause I will check for the existence of same variable in the translated version of this string. Text comes from a CSV and strings do not end with a line break. I am able ...

Linked List Dependent Select Boxes

So I haven't been doing this for long but I'm completely stuck on this. I have a model which looks like this (simplified for brevity): class ReqBreakdown < ActiveRecord::Base belongs_to :next_level #nil if lowest level belongs_to :previous_level #nil if highest level belongs_to :requirement_level end I need a way to build these...

How can I manage a long running process from a Rails app?

I'm building an app to learn Rails, and I'm not sure how to go about this. I have a form, where the user enters some data. The data is validated, and a server side process should start ( the process may take from 5 minutes to 2 hours ). I'd like to be able to know the state of the process at all times and to be able to kill it. The thi...

Ruby: wrong argument type nil (expected Data)

I'm getting the error: wrong argument type nil (expected Data) Here's my code (names have been changed to protect the innocent ;) ): old_foos.each do |foo| foo.bars.each do |old_bar| if new_foo.bars.any? {|new_bar| new_bar.name == old_bar.name} #assume new_foo is properly set check = 1 end end end if check == 1 d...