ruby

Is there any command to check what plugins I am using in my RoR application?

Can I use any command to check if my application is using any plugins or not? ...

MongoDB Group using Ruby driver

I'm trying to bring back a list of year/month combinations with counts for describing blog posts. The idea is that they will be displayed like so: January 2010 (1 post) December 2009 (2 posts) ... I have managed to get this to work using the MongoDB JS shell, and it returns results in a useful format: db.posts.group({ keyf: fun...

error while trying to create DTE2 Interface object with ruby

I am trying to use ruby win32ole lib and DTE2 Interface to control visual studio 8 \ tried this require 'win32ole' ide = WIN32OLE.new('EnvDTE80.DTE2') and received this error unknown OLE server: EnvDTE80.DTE2 what am I doing wrong, can this work at all ? ...

Install Mysql Gem for Ruby along with JRUBY Gem

Hi. I have Jruby gem Mysql installed on my machine. However due to some reason, I had to move to ruby instead of ruby and everything seems to be working fine except that mysql gem for ruby isn't installed and now when I try to install Mysql gem i get following error: Building native extensions. This could take a while... ERROR: Error...

Multiple database connections in Rails

I'm writing a simpler version of phpMyAdmin in Rails; this web app will run on a web server (where users will be able to indicate the database name, hostname, username, password, and port number of one of the database servers running on the same network). The user will then be connected to that machine and will be able to use the UI to a...

Ruby Print Inject Do Syntax

Why is it that the following code runs fine p (1..1000).inject(0) { |sum, i| sum + i } But, the following code gives an error p (1..1000).inject(0) do |sum, i| sum + i end warning: do not use Fixnums as Symbols in `inject': 0 is not a symbol (ArgumentError) Should they not be equivalent? ...

negative lookbefore for a blackslash in ruby 1.9

I want to match every '[' or ']' that's not preceded by a backslash in ruby 1.9 I tried: /?<!\134[\[\]]/ and /?<!\\\\[\[\]]/ but I get a 'target of repeat operator not specified' ...

Ruby / Sinatra / HAML flash message problem

I have the following small Sinatra application (I've removed the extra unneeded code): helpers do def flash(args={}) session[:flash] = args end def flash_now(args={}) @flash = args end end before do @flash = session[:flash] || {} session[:flash] = nil end post '/post' do client = Twitte...

Ruby: Parsing a complex hash

I have a hash that goes multiple levels deep: http://gist.github.com/285350 I am trying to loop through each serving but I keep running into multiple nil[] errors even though the hash isn't nil. For example: food_hash["food"]["servings"] Returns nil.[] It might be because im half asleep but I can't seem to get down to the "serving_...

Something like getch(), textcolor() and gotoxy() in Ruby.

Hello. I want to use these functions from the conio.c library (Borland) in Ruby, specially getch(). getch() gets a key from the keyboard without press enter. textcolor() changes the color of the text in the terminal. gotoxy() moves the cursor to other position of the terminal. Someone knows the equivalents? Thanks. ...

Asynchronous HTTP request

require 'net/http' urls = [ {'link' => 'http://www.google.com/'}, {'link' => 'http://www.yandex.ru/'}, {'link' => 'http://www.baidu.com/'} ] urls.each do |u| u['content'] = Net::HTTP.get( URI.parse(u['link']) ) end print urls This code works in synchronous style. First request, second, third. I would like to send all requests...

How important is adding quiet/verbose flags to new unix tools?

I'm writing some unix-style Ruby scripts that take option flags. Normally, I write a lot of STDOUT.puts and STDERR.puts statments in these scripts. Now I'm wondering whether it's "good form" to put in --verbose or -q flags for switching on or off helpful output to STDERR. Two arguments against doing that are that it would make the p...

How to get the size of each value of a hash

hi! I have a hash, each value is an array. I want to build a new array containing the size of each value/array. Example: the hash {"A"=>["1", "2", "3"], "B"=>["b", "toto"]} the result [3, 2] thanks for your help ...

ruby / rails / mysql performance degraded on Snow Leopard

I've burned a bunch of hours on this. I'm not having problems getting things to build, but I am seeing that my test suite runs about 2x slower than when I was on OS X 10.5.x . I've spent a lot of time playing around with different optimization settings (learning to avoid homebrew's llvm-gcc compilation). I've just learned that I needed t...

How can I print information about a NET:HTTPRequest for debug purposes?

I'm new to Ruby coming from Java. I'm trying to make a http get request and I'm getting an http response code of 400. The service I'm calling over http is very particular and I'm pretty sure that my request isn't exactly correct. It'd be helpful to "look inside" the req object after I do the head request (below) to double check that the ...

Code translation, from Python to Ruby

Hi, I would like to convert a few Python lines on Ruby, from this excellent article signed by Thomas Guest at: http://wordaligned.org/articles/drawing-chess-positions (note: I'm a really bigger Python noob) Here is a copy of the original Python version: def expand_blanks(fen): '''Expand the digits in an FEN string into spaces ...

the right code flow in attached code? (ruby)

in the extract of my script code (see the first piece of code below) I use the array @post_csv_order to specify the order and key => value relationship of elements for the hash @post[post_id]. I run the assignment line @post[forum_id] = Hash[*@post_csv_order.flatten] in a loop when I collected all values (like forum_id, post_title etc)....

Unpacking 3-byte/24-bit data chunks with Ruby

I am building a pure-Ruby WAV file read/write library, learning deeper Ruby functionality as I go. It currently works well with 16-bit audio, as I am able to use String.unpack('s*') to pull individual audio samples out into an array of signed integers. I am having trouble wrapping my mind around how to go about dealing with 24-bit audio,...

How do I get an array of check boxes in haml?

Hi, I have an array of strings, called @theModels, in a routine implemented as part of a Sinatra server. These models are options for the user to select, and are obtained by the back end (the idea being, as new models are added, then the front end code should not change). I'm using haml to render html. How can I enumerate each eleme...

Sinatra Sub-Directory Views

I want to be able to get Sinatra views from sub-directories of ./views (such as ./views/admin). I know you can set the views like so: set :views, Proc.new { File.join(root, "templates") } But how would I be able to set this for only part of the file? ...