ruby

Benefits of Sinatra for a web service like controller

I am writing a simple ruby controller that just needs to respond as a webservice to a bunch of mobile clients. Someone told me I should look into Sinatra. What is the point of using Sinatra for something this simple? He mentioned that it would be "faster" but how can a wrapper on top of something make it faster? I don't want to overco...

How to convert n arrays of length m into m arrays of length n?

I'm trying to convert this: [ [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12] ] into this: [ [1, 5, 9], [2, 6, 10], [3, 7, 11], [4, 8, 12] ] Is there a build-in function to do this? If it's not, what's the shorter and cleaner way? ...

Linux command for a ruby script

Hi , how could I run a ruby script as a command in linux. I have this script which access the lib but i have to run it as teraData.rb i want to run it as teradata (or some meaningful command ) with args on linux from any command promt. Where should i place the script and what should I do? I am kinda new to linux so please help ...

Running MRToolkit hadoop jobs on AWS elastic map/reduce

Hi All, Loving MRToolkit -- great to get away from Java while writing Hadoop jobs. It has become apparent that the library was written to interface with an EC2 cluster, and not with Amazon's elastic map/reduce system. Does anybody have insights into running jobs defined using the toolkit on elastic map/reduce servers? It isn't readil...

How can I get Textile to create links out of plain URL's?

Many of my users are typing in plain URL's and not using the Textile format for creating links. I would like Textile to just make the URL's linkable to the URL's. I don't really need to worry about XSS or anything malicious because it is an internal network with a very small group of users. What would be the best way to go about achievin...

rails awesome nested set show all cats, sub cats, and sub sub cats

Hello, I saw this post http://stackoverflow.com/questions/2059920/ruby-on-rails-awesome-nested-set-plugin but I am wondering how to do the same thing without using node? I am also wondering what exactly this node is doing in the code itself. In my categories view folder i have _category.html.erb and a _full_categores_list.html.erb. ...

increment value in a hash

I have a bunch of posts which have category tags in them. I am trying to find out how many times each category has been used. I'm using rails with mongodb, BUT I don't think I need to be getting the occurrence of categories from the db, so the mongo part shouldn't matter. This is what I have so far @recent_posts = current_user.rec...

Heroku deployment error

In a windows environment I am getting the following error when trying to deploy to Heroku C:/Ruby/lib/ruby/gems/1.8/gems/heroku-1.9.13/lib/heroku/commands/base.rb:32:in ': No such file or directory - git remote (Errno::ENOENT) from C:/Ruby/lib/ruby/gems/1.8/gems/heroku-1.9.13/lib/heroku/commands/ba se.rb:32:in shell' ...

Rails 404 error for Stylesheet or JavaScript files

Rails can't load (404 error) CSS & JS files on production but has no problem loading them in development. I'm using Capistrano for deployment and running Rails 3. My path on development is /www/myapp but my path on production is /www/myapp/current. The application itself seems to work fine, so the issue seems to be isolated to CSS/JS f...

More Advanced Control Over Delayed Job workers retry

So I'm using Delayed::Job workers (on Heroku) as an after_create callback after a user creates a certain model. A common use case, though, it turns out, is for users to create something, then immediately delete it (likely because they made a mistake or something). When this occurs the workers are fired up, but by the time they query ...

Things to consider when creating a web framework

I am not trying to create yet another web framework. For one of the applications I am working on, I want to create a custom framework. I don't want to use any already available framework. What are the common things to consider? What should be the architecture? Thanks :) ...

Validate arguments in Ruby?

I wonder if one should validate that the arguments passed to a method is of a certain class. eg. def type(hash = {}, array = []) # validate before raise "first argument needs to be a hash" unless hash.class == Hash raise "second argument needs to be an array" unless array.class == Array # actual code end Is it smart to do th...

Ruby - chaining methods and returning array

I have some methods for a class which return arrays like ["1", "3", "2", "6", "2"]. It is ok that these are string arrays, not numeric. I have another method that takes an array, and turns it into a single string like this 1 3 2 6 2. class Turn def initialize @rolls = 1 @dice = [] end def roll @roll = [] x = 5 - @dice.le...

%w{ models }.each do |dir| in Rails means?

In Rails guide this came up: %w{ models }.each do |dir| Could someone explain for me what %w{ models } means? Never seen it before. Is it ruby or rails specific. Thanks ...

Parse issues when trying to use "Examples" section in Cucumber feature

No luck in googling on this error message features/manage_hand_evaluator.feature: Parse error at features/manage_hand_evaluator.feature:21. Found examples when expecting one of: comment, py_string, row, scenario, scenario_outline, step, tag. (Current state: step). (Gherkin::Parser::ParseError) Here's the setup I have for Examples secti...

Loop doesn't terminate upon checking a condition

This loop does not terminate after I type x. I'm really new to Ruby, and so far, it is so much different than what I learned before - quite interesting, total = 0 i = 0 while ((number = gets) != "x") total += number.to_i i += 1 end puts "\nAverage: " + (total / i).to_s Any help is greatly appreciated. ...

Ruby on Rails -- not grokking

I've been learning a lot about web technologies recently and I want to put together a neat little website to play with html, css, javascript, flash, and what have you. I know that as far as the web browser is concerned all I need to do is send a text file (usually HTML) from my server using HTTP over TCP. I've gone through a couple o...

GridFS in Ruby: How to upsert?

Does GridFS have an upsert? For example, if i want to save an image with a specified _id, and one with that same _id already exists, i want it to overwrite (update) it. Otherwise, insert it. Thanks! Matt ...

Including SMSFu gives an error. How do I fix it?

How do I go about using SMSFu? I have a Posts controller and I have cloned the sms-fu files into my plugin folder. But when I include SMSFu and refresh my application, I get this error uninitialized constant PostsController::SMSFu. Where am I going wrong? Thanks. ...

Where should i put my rubygems after installation?

Suppose I installed some ruby gems using gem install gemname. Where should I install them, and when what directory should I run gem install rubygems-update-1.3.1.gem from? ...