ruby

Rails returns a 500-error (Not sure why)

I've been trying to get Rails working, but whenever I try to create my own view, it returns a 500 error. So, here's the steps I've followed to get where I am: I installed Ruby to C:\Ruby I installed Rubygems to C:\Ruby\rubygems-1.3.5 and ran ruby setup.rb In the cmd prompt, I installed rails using gem install rails. I created a Project...

Should I update my website from PHP to Ruby (on Rails)?

Hi! I'm an intermediate PHP web developer and I'm currently working on a website project. Being totally new to the whole business I've programmed my server side part with PHP. Now I've read everybody's using "Ruby on Rails" and it makes other languages obsolete and all that. Is that really true? Is there any value to transforming my ent...

Create binary data using Ruby ??

i was palying with the ruby sockets, so i ended up trying to put an IP packet togather, then i took an ip packet and try to make a new one just like it. now my problem is: if the packet is: 45 00 00 54 00 00 40 00 40 01 06 e0 7f 00 00 01 7f 00 00 01, and this is obviously hexadecimal, so i converted it into a decimal, then into a binary...

Properly converting a CMYK image to RGB with RMagick

I have been using the below to do a color conversion if @image.colorspace == Magick::CMYKColorspace # @image.colorspace #=> CMYKColorspace=12 @image.colorspace = Magick::RGBColorspace @image = @image.negate end It works, approximately, but the color luminosity is off. The fact that I need to negate the image...

Sinatra/Rack Sleep until Response Ready (like Exchange ActiveSync)

I'm wanting to do a lightweight push-style HTTP response in my existing Sinatra web app. Is there any mechanism that allows me to not respond to an HTTP request and keep the connection open until I wake up the connection at a future time? ...

ruby operator overloading question

i've been messing around with ruby and opengl for entertainment purposes, and i decided to write some 3d vector/plane/etc classes to pretty up some of the math. simplified example: class Vec3 attr_accessor :x,:y,:z def *(a) if a.is_a?(Numeric) #multiply by scalar return Vec3.new(@x*a, @y*a, @z*a) el...

Getting webpage content with Ruby -- I'm having troubles.

I want to get the content off this* page. Everything I've looked up gives the solution of parsing CSS elements; but, that page has none. Here's the only code that I found that looked like it should work: file = File.open('http://hiscore.runescape.com/index_lite.ws?player=zezima', "r") contents = file.read puts contents Error: tracke...

Java equivalent of Ruby ObjectSpace.each_object

I'm looking for a way to get all instantiated objects of a given type in Java. With Ruby you can use the ObjectSpace.each_object method: a = 102.7 b = 95.1 ObjectSpace.each_object(Numeric) {|x| p x } would give 95.1 102.7 ...

Tracking fitness in a genetic algorithm

I'm still hacking on my old ruby for the undead post (I know, I know, stop trying to bring the post back from the dead Chuck). But the code has gotten a little out of hand and now I'm working on a genetic algorithm to create the ultimate battle of living and dead with the fitness being how long the battle lasts. So, I've got the basics...

shoes url not working in Ubuntu?

Hello all, i have been using Shoes in windows from couple of months and it was working awesome, but now i am having Ubuntu set up on my machine and i am trying to run shoes in it but it seems like URL is not working .... i.e nothing happens when i click on it. Have anybody observed this problem. Any help on this? thanks Pradyumna ...

rails if object in an array

I need to check, if for each item in @line_items if it is in different array say @quote_items Controller: def index @line_items = LineItem.all @quote_items = QuoteItem.all end View: <% for line_item in @line_items %> <% if @quote_items.include?(line_item) %> line_item in quote item! <% else %> line_item NOT in q...

gem install error, index not found, ruby on rails

Problem: Cannot install any gem, any type. But I want to install riddle if that matters. When I run sudo gem install "gem_name" I get the following error: WARNING: RubyGems 1.2+ index not found for: RubyGems will revert to legacy indexes degrading performance. Bulk updating Gem source index for: http://gems.rubyforge.org/ What to d...

Ruby - Array method confusion

we can call the Array method in the top level like this Array(something) that makes sense to me, it's a method call without explicit receiver, and self, which is main in this case, is inserted at the front of the method call. But isn't it that this is equivalent to : Kernel.Array(something) this doesn't make sense to me. Since in t...

QtRuby: loading HTML file into QTextEdit

How do I load a custom HTML-file into QTextEdit while in runtime? ...

Nokogiri how to get the parent text and not the childs text and reference the text back to its parent

Let's say I have this sample: page = "<html><body><h1 class='foo'></h1><p class='foo'>hello people<a href='http://'&gt;hello world</a></p></body></html>" @nodes = [] Nokogiri::HTML(page).traverse do |n| if n[:class] == "foo" @nodes << {:name => n.name, :xpath => n.path, :text => n.text } end end ...

Rails, Combine multiple controllers into one interface

In rails I am making a "blog" to help me learn. I was wondering how I could incorporate the editing, creating, and deletion of Users and Posts in my admin controller. I would also include deleting comments in there too. So far I have Users, Admin (basically just to login/control everything),Comments, and posts. So how could I combine all...

How do I efficiently reject Strings in an array if they (regex) match Strings in a second array in Ruby?

I have two arrays of Strings, for example sentences and words. If any word is found in a sentence e.g. sentence =~ /#{word}/ I want to reject the sentence from the sentence array. This is easy to do with a double loop, but I'm wondering if there is a more efficient way of doing this, maybe with logical operators? ...

config.cache_classes = true affecting type coercion with RubyDBI

Environment: Rails 2.3.2 DBI 0.4.1 DBD/ODBC 0.2.4 Scenario: I have a Rails app that imports most of it's data from external SQL DBs into the Rails SQL DB via regular batch jobs. Those batch jobs start by loading the Rails environment, then proceed to make direct database connections via RubyDBI. Once I connect, I run select statements t...

ruby 1.9 -- Gem is there but it says its not?

I just installed 1.9 on my 10.6 OSX, and it runs as the "ruby1.9" command. So I'm trying to do: sudo rake1.9 install But it keeps telling me Jeweler (or a dependency) not available. Install it with: gem install jeweler rake aborted! no such file to load -- git However, if I type: gem1.9 list The jeweler gem is clear as day righ...

Can't install do_mysql gem?

I'm trying to install the do_mysql on my Snow Leopord system Macbook Pro 13", but I keep getting this error: n216-160:~ myself$ sudo gem1.9 install do_mysql Password: Building native extensions. This could take a while... ERROR: Error installing do_mysql: ERROR: Failed to build gem native extension. /opt/local/bin/ruby1.9 extconf...