ruby

Something to use for graphing numbers

Is there some sort of application/API with which I can graph sets of numbers(line graph)? I will be interfacing with an external device which will provide me with some readings(via a custom format through a /dev/cua file) at a rate of about 1000 readings per second. I want to be able to graph this as a line graph. So I will need to be...

including rake tasks in gems

1) Is there a 'best' place for rake tasks inside of gems? I've seen them in /tasks, /lib/tasks, and I've seen them written as *.rb and *.rake -- not sure which (if any) is 'correct' 2) How do I make them available to the app once the gem is configured in the environment? ...

How can I answer a POST request with a static file in Sinatra?

In Sinatra, if you have a "GET /images/photo1.jpg" request... you can save a lot of time by making a "public" directory. Any route not found is assumed to be inside your "public" directory. However this seems to work just for GET requests. Is there a way to do something similar for POST requests? Either: Turning on some static method...

rails routes params find for a form

Hello, I am having a bit of trouble with my rails application. It short, its a social networking app where users have a profile, have submissions, and can comment on submissions. My routes are as follows: map.connect '/:username', :controller => 'users', :action => 'show' map.connect '/:username/:id', :controller => 'submissions', :...

How to load a Web page and search for a word in Ruby

How to load a Web page and search for a word in Ruby?? ...

How can I have two columns in one table point to the same column in another with ActiveRecord?

I run the risk of palm-to-forehead here, but I can't quite figure out how to do this with Rails' ActiveRecord sugar. I have a tickets table that has two columns (submitter_id and assignee_id) that should each reference a different user from the users table (specifically the id column in the users table). I'd like to be able to do things...

Escaping \ in regular expressons in Ruby

Hi All, I'm new to ruby and came across an interesting problem yesterday. I was parsing a file and some lines of the file ended with "\". I wanted to use gsub to find and replace it. I tried '\' and /\/ and neither one correctly matched "\". I ended up getting around it by using a combination of chop and strip but it left me thinking ...

Using Ruby for platform-independent application.

I want to write a desktop application using Ruby. I want it platform-independent and with rich GUI. How to start? What tools? ...

Showing status of current request by AJAX

Hi everyone, I'm trying to develop an application which modifies a couple of tasks of the famous Online-TODO List RememberTheMilk (rememberthemilk.com) using the REST API. Unfortunately the modifying takes a lot of time, so I want to give a feedback to the users. My idea was just to display a couple of text lines (e.g. modifying task 1...

HTTP Logging in rails?

Does anyone know of a plugin / gem that will log any HTTP requests your rails app may be making when responding to a request? For example if you are using HTTParty to hit an API, how can you see what outbound requests are coming out of your rails app? ...

How can i learn regex for ruby.

How can i learn regex for ruby? (for a dummie) ...

How to test file manipulation

I hear that accessing to database is wrong in testing. But what about file manipulation? Things like, cp, mv, rm and touch methods in FileUtils. If I write a test and actually run the commands (moving files, renaming files, making directories and so on), I can test them. But I need to "undo" every command I ran before running a test ag...

How to get Regex to ignore URL strings

Hi, I have the following Regexp to create a hash of values by separating a string at a semicolon: Hash["photo:chase jarvis".scan(/(.*)\:(.*)/)] // {'photo' => 'chase jarvis'} But I also want to be able to have URL's in the string and recognize it so it maintains the URL part in the value side of the hash i.e: Hash["photo:http://www...

Installing Rake: invalid gem format

I installed Ruby on WinXP. Used rubyinstaller-1.8.6-p383-rc1.exe. Ran gem install rake Get error: Error installing rake: invalid gem format for C:/Ruby/lib/ruby/gems/1.8/cache/rake-0.8.7.gem I've tried deleting the cache folder but i keep getting the same error. Tried with Ruby 1.9.1 too. Same error. What am i doing wrong? ...

How to send emails from ruby using a gmail account, for example?

Hi, I'm kind of new at ruby on rails, and I've read many tutorials about this, but I still can't figure out what's wrong. I already set up the environment.rb with the following lines at the bottom: ActionMailer::Base.delivery_method = :smtp ActionMailer::Base.default_content_type = "text/html" ActionMailer::Base.smtp_settings = { ...

Ruby/Rails: get elements from array where indices are divisible by x

How could I implement this? I think my solution is very dirty, and I would like to do it better. I think there is an easy way to do this in Ruby, but I can't remember. I want to use it with Rails, so if Rails provides something similar that's ok, too. usage should be like this: fruits = ['banana', 'strawberry', 'kiwi', 'orange', 'grapef...

PHP giving different hash calculation than ruby, how can I fix?

PHP code: function compute_signature($key, $hash_string) { $digest = hash_hmac("sha1", $hash_string, $key, true); return base64_encode($digest); } Ruby Code: digest = HMAC.digest(Digest.new(SHA1), Base64.decode64(key), HashString) return Base64.encode64(digest.to_s()).chomp() Could this be a charset iss...

Explicitly specify default method target in Ruby?

Is there a best practice in Ruby when it comes to explicitly specifying method targets even when unnecessary? class Foo def meth1 puts "bar" end def meth2 # is this better? self.meth1 # or this? meth1 end end ...

Adding by block in ruby

I posted a similar question to this not too long ago in regards to formatting a MySQL query using a block and got very good responses, but they were very specific to the problem at hand. This time around, I'm dealing with getting the .sum()s of rows in a table. Here's what I've got now: def balance balance = 0 items.each do |item| ...

Getting Ruby code to work, creating SHA1 hash from given string and key

I have a small code snippet that I'm trying to get to work in Ruby. digest = HMAC.digest(Digest.new(SHA1), Base64.decode64(key), HashString) return Base64.encode64(digest.to_s()).chomp() I tried it as follows: hashstring = "POST application/octet-stream Thu, 05 Jun 2008 16:38:19 GMT /rest/objects date:Thu, 05 Jun 2008 16:38:19 GMT g...