ruby

Simple custom range in Ruby

I have a Rails named_scope which is using a condition to pull specific days of the week from the table like so: :conditions => [ 'EXTRACT(DOW FROM bookdate) IN (?)', (1..6).to_a ] The 1..6 date range will be a variable depending on the dates the user wants, Which produces this SQL (EXTRACT(DOW FROM bookdate) IN (1,2,3,4,5,6) My pr...

How to make proper ECDSA with Ruby & OpenSSL::PKey::EC

I'm trying to make elliptic curve digital signature with Ruby EC class, but my Objective-C validation code (made with libcrypto ECDSA_verify()) fails to recognize it. #!/usr/bin/env ruby require "rubygems" require "base32" require "openssl" msgHash = OpenSSL::Digest::SHA1.digest("Message text") key = OpenSSL::PKey::EC.new("secp160r1")...

Installed fxruby over macports, now rubygems is broken

Hi, using OS X 10.5.6 I installed fxruby using $sudo port install rb-fxruby As suggested in the book. It works, my hello world program worked correctly. Now, though, other code that I have written is broken, whenever I try to use any code that relies on a gem, it does not work. When I do $ruby -e "require 'rubygems'" in my code, i...

Is Ruby 1.9.1 actually ready and faster for a new Rails deployment?

I'm not going to make this into a Rails vs Framework X discussion, there's plenty of those already. After seriously contemplating what framework I'm going to use for my next deployment, I decided it's very difficult to pass up the out of the box REST exposure Rails gives you for minimal work back. This is something that requires slightly...

ruby script not being called successfully with svn's post commit hook script

what could be the possible reason that my ruby script is not being called successfully? note that when i manually execute the post-commit script like so: /var/svn/eweds/hooks/post-commit /var/svn/eweds 151 works just fine, the way my ruby sript is called in the post-commit script is like this: ruby /home/pmind/public_html/eweds/scri...

Ruby Gsub! question

params[:hello] # => "Some params value" hello = params[:hello] hello.gsub!("whatever","") params[:hello] # => "" I don't understand, can someone please explain why the params[:hello] gets modified by the gsub! ? I expected the hello string to be modified, but not the params hash. ...

What's a good place to learn Ruby? What is it primarily used for? [Desktop or Web or Mobile]

A few years ago a friend of mine suggested I learn Ruby. I've since learned PHP and VB.NET but I never got around to Ruby. Where can I start with Ruby? Also, as a side note: What is Ruby primarily used for? How would you describe it in comparison to PHP? Python? VB? EDIT: How can I get it set up on Ubuntu 9.04? Vista or 7 Home Prem?...

how to sort an array of arrays by three or more elements (ruby)

I have csv file with 14 columns and I want to sort it in ruby by 6th column then by 2nd and then by 11th column. There is nice method .sort_by but it works only for two columns, doesn't it. And array_of_arrays.sort_by {|e| [e[2], e[0],e[1]],} doesn't work. so let's say in the sample below I want it to be sorted by 3rd,1st,2nd columns ...

deploy rake task as if it were a common script

I like the rake task structure and rake utilities.. I want to create a script that can do many things, and rake seems the logical choice. I want to know how can I make it look like a regular script: ./myscript.rb cake:bake as opposed to rake -f myscript.rb cake:bake any idea? Of course, rake must still be installed etc.. simply to ...

undefined method `form_for' for module `ActionView::Helpers::FormHelper'

Argh! Everything has been totally fine, then all of a sudden I started getting this error when I was doing a 'rake db:migrate' And I get the same thing when I try to restart the rails server. rake aborted! undefined method 'form_for' for module `ActionView::Helpers::FormHelper' Confirmation that I'm running a current version: mm-MacBo...

undefined local variable or method

Ok this worked: Student.transaction do if @student.test! y = @student.rooms.first book = Book.find(:first, :conditions => ["room_id = ?", y]) It's strange. I wanted to get the last record not first, yet it thought first was the last and worked. Not sure why. ...

Rcov: Why is this code not being considered covered?

Here's my controller: class MyController < ApplicationController include MyHelper def index get_list_from_params do |list| @list = list respond_to do |format| format.html format.xml { render :xml => @list } format.json { render :json => @list } end end end end ...the helper tha...

Multiple delivery confirmations per message with Ruby SMPP

I am using the ruby smpp library to send/receive SMS. Right now we are sending messages to two different servers, using the ruby-smpp library. One of them works perfectly, but the other one sends multiple DELIVRD confirmations for each messages. And by multiple I mean hundreds of confirmations per message in some cases. Does anyone know...

[ruby] how to open hyperlink page from a client side.

this is what I want to do. a href="javascript:sayHello('an nyung')"> click here /a this code is in a server side. and I wanna to call this link from a client side by using ruby. is there any way to do this? ...

Somehow not assigning a class with Ruby

On runtime, my code often come into an undefined method error for the method mate. As far as I can figure, a Person somehow slips through the cracks sometime along the code's exucution, and manages not to have an allele assigned to it. Code (disclaimer, not the best formatted): class Allele attr_accessor :c1, :c2 def initialize(c1...

How do I log every method that's called in a Ruby program?

I've inherited a large pile of Ruby code that's, frankly, close to impossible to understand for a mortal like myself. It's actually Rspec unit test code, but the structure is "highly unusual" to put it nicely. What I'd like to be able to do is run the code, and have the following information logged somewhere: every method that gets i...

ruby win32api & structs (VerQueryValue)

I am trying to call the standard Win32 API functions to get file version info, using the win32-api library. The 3 version.dll functions are GetFileVersionInfoSize, GetFileVersionInfo, and VerQueryValue. Then I call RtlMoveMemory in kernel32.dll to get a copy of the VS_FIXEDFILEINFO struct (see Microsoft documentation: http://msdn.mic...

Do something after creating, and before destroying

How can I have a block execute whenever an instance of a DataMapper class is a created, and another before it is destroyed? ...

How do I resolve a permission error installing a custom built gem?

I'm attempting to build my first ruby gem and all seemed to go well until I attempted to install the gem. I'm using RVM so no need for 'sudo gem install' here. First I attempted to do the following: jim:~/Desktop/spectest \ [git:master] → rake manifest (in /Users/jim/Desktop/spectest) Cleaning - pkg rm -rf pkg Building Manifest Man...

In Rails, can an internal request be generated that behaves identically to an HTTP request?

Within my Rails application, I'd like to generate requests that behave identically to "genuine" HTTP requests. For a somewhat contrived example, suppose I were creating a system that could batch incoming HTTP requests for later processing. The interface for it would be something like: Create a new batch resource via the usual CRUD met...