ruby

Plotting GPS info with Ruby

I'm looking for ways to programmatically convert my GPS logs to images and would like to do this in Ruby... if that's an acceptable tool. I have no GIS background whatsoever but as a programmer i think it's an interesting problem to look at. Here is what I have come up with so far. First you'll need some kind of graphing library. I went...

ruby link-grammar error in wchar.h

I'm trying to install the ruby link-parser as per http://deveiate.org/projects/Ruby-LinkParser Running through 'make' i get the following error /usr/include/wchar.h:53 error: parse error before '{' token /usr/include/wchar.h:63 error: parse error before '}' token make[2]: *** [analyze-linkage.lo] Error 1 make[2]: Leaving directory '/h...

Fake a type-cast in Ruby?

Given the following Ruby code, and given I have an instance of Klass, how can I call the do_stuff method on my Klass instance. I want to cast my Klass instance to Subklass. I understand type-casting this is not possible in Ruby - is there a way to fake it? class Klass ... end class Subklass < Klass ... def do_stuff ... end ...

ruby, evaluation multiple conditions in an array

So maybe I have this all wrong, but I'm sure there is a way to do this, say I have a an if statement, that I want to return true if all the conditions in an array evaluate as true. say I have this: def real_visitor?(location, request, params) valid_location = [ params['referrer'] == 'us', params['bot'] != 'googlebot', 5 ...

Ruby: Get currently logged in user on windows

In C# I can get the current user of a web app using the HttpContext, however, I can't figure out how to do this in Ruby. Is there any way of doing this? FOR THOSE OF YOU SAYING IT IS IMPOSSIBLE, HERES PROOF: http://www.codeproject.com/KB/aspnet/How_to_NT_User_Name.aspx ...

Mock methods that receives a block as parameter

I have a scenario more or less like this class A def initialize(&block) b = B.new(&block) end end I am unit testing class A and I want to know if B#new is receiving the block passed to A#new. I am using Mocha as mock framework. Is it possible? ...

ActiveRecord custom SQL in Ruby

I need to perform these SQL below, but I couldn't get the result. newid=Header.find_by_sql( "SELECT coalesce(max(transaction_id),0)+1 AS id FROM transaction_headers WHERE transaction_year = #{Time.now.year} AND transaction_type='#{fields[:transaction_type]}'" ) But I can't seem to get the result to newid. The only value I ...

Resizing windows using Ruby?

I am trying to resize the window of another open application via ruby but I am not sure how to go about doing this. I am guessing this may be possible using the Ruby Win32API, but to be honest I don't really know where to start looking. If one of you guys could point me in the right direction it would be greatly appreciated. ...

Ruby on Rails Formbuilder/HAML display-only fields don't seem to work

I'm trying to use Ruby on Rails' Formbuilder and HAML to edit a model that has some fields that can only be edited a creation. I still want to display them, but I don't want them editable. I've struggled trying to do this and make the form look presentable. So, if the field is editable, I use = f.text_field :price_code_1, :label_...

Preventing Nokogiri from escaping characters?

I have created a text node and inserted into my document like so: #<Nokogiri::XML::Text:0x3fcce081481c "<%= stylesheet_link_tag 'style'%>">]> When I try to save the document with this: File.open('ng.html', 'w+'){|f| f << page.to_html} I get this in the actual document: &lt;%= stylesheet_link_tag 'style'%&gt; Is there a way to di...

How to implement database views in Ruby on Rails

I'm just wondering how to implement database views in Ruby on Rails. Can you guys put some working example? And thank you for every advises and examples. ...

Can Shoes.rb Create Self-Contained Applications?

It's encouraging that Shoes (the Ruby GUI framework) has excellent packaging functionality, but I'm concerned that it doesn't actually 'wrap' itself around created applications. Packaging for OSX outputs a shoes installer and a shoes file in a .app system. Is there any way that shoes could create a .app that contains shoes - that doesn't...

Why is Python faster than Ruby?

They seem to share a lot of the same characteristics but as far as I can tell, Python 2.5 is faster than 1.8.7 by a lot. Is there a deeper underlying reason behind this? ...

Is there a way to call ruby1.9 without loading rubygems?

So ruby 1.9 is really nice in that it'll automatically require rubygems, and hence when you call require 'somegem' without first requiring rubygems it'll work, and that's generally awesome. But I have a ton of shell scripts using ruby, and they generally don't rely on rubygems. Shell tools should run instantly, and loading rubygems for ...

Where is that modified version rails3 running on macruby?

http://www.macruby.org/blog/2010/04/30/macruby06.html In MacRuby blog. They said that: This release also passes about 85% of RubySpecs, is able to run a modified version of Rails 3, and implements better support for Ruby 1.9 encodings. How can I get that modified version rails3? Google cannot give me answer. ...

Base64.decode64 in ruby returning strange results

Hi all, I'm having problems in decoding a string using Base64.decode64 in Ruby. As a test, I'm using this site that decodes strings in php: https://rnd.feide.no/simplesaml/module.php/saml2debug/debug.php. As a test, I'm using this string: fZJNT%2BMwEIbvSPwHy%2Fd8tMvHympSdUGISuwS0cCBm%2BtMUwfbk%2FU4zfLvSVMq2Euv45n3fd7xzOb%2FrGE78KTRZXw...

Associations in ActionMailer Template

I have an ActionMailer Model (Notifier) and a view for the mail. In my controller i build an Array (access_data) that looks like this: access_data = [] users.each do |user| access_data << {'subscriptions' => user.subscriptions, 'login' => user.login} end When i create a "normal" view, i can do this: <% access_data['subscriptions']....

Perl equivalent of Ruby's `reject!`?

I need to walk over an array, and conditionally delete elements, in Perl. I know about slice, but am not sure how to use it in a foreach context. In Ruby, there is reject!: foo = [2, 3, 6, 7] foo.reject! { |x| x > 3 } p foo # outputs "[2, 3]" Is there a Perl equivalent? ...

Why I got a unknown action??

I have a "manageUser" page, the route is like that: map.manageUsers "manageUsers", :controller => "users", :action => "manageUsers" and, it like a index of user, but provide a ban button for admin to ban the user, so, I have something like this: <% @users.each do |user| %> <td><%=h user.username %></td> <td><%= link_t...

how to access this element

I am using Watir to write some tests for a web application. I need to get the text 'Bishop' from the HTML below but can't figure out how to do it. <div id="dnn_ctr353_Main_ctl00_ctl00_ctl00_ctl07_Field_048b9dfa-bc64-42e4-8bd5-b45385e5f45b_view" style="display: block;"> <div class="workprolabel wpFieldLabel"> <span title="Please s...