ruby

Failed to build gem native extension - extconf.rb not found

Hi, When trying to install 'bcrypt-ruby', :lib => 'bcrypt' and 'hpricot' I get this in both cases (Using Windows XP) C:/Ruby/bin/ruby.exe: No such file or directory -- extconf.rb (LoadError) I installed from here http://rubyinstaller.org/downloads/ Rb 1.8.6, including the devkit any hints?, thanks ...

Thread.abort_on_exception doesn't work in rake task?

When I run Thread.abort_on_exception = true threads = [] threads << Thread.new do loop { sleep 1 } end threads << Thread.new do loop { sleep 1; raise } end threads.each { |t| t.join } as a straight-up ruby script, the script exits as you'd expect with abort_on_exception set to true. But when I try to run this same code as a ra...

Geohashing - recursively find neighbors of neighbors

I am now looking for an elegant algorithm to recursively find neighbors of neighbors with the geohashing algorithm (http://www.geohash.org). Basically take a central geohash, and then get the first 'ring' of same-size hashes around it (8 elements), then, in the next step, get the next ring around the first etc. etc. Have you heard of an ...

Why is this an endless loop? ActiveRecord

class Account < ActiveRecord::Base after_update :give_user_credit, :on => :update def give_user_credit credit = User.current_user.credit + 3.8 User.current_user.update_attribute(:credit, credit) end end When I use this the server hangs and when I come back to the application after a full reboot my credit is in the £1000...

How do I redirect stderr and stdout to file for a ruby script?

How do I redirect stderr and stdout to file for a ruby script? ...

How do you extend a Ruby module with macro-like metaprogramming methods?

Consider the following extension (the pattern popularized by several Rails plugins over the years): module Extension def self.included(recipient) recipient.extend ClassMethods recipient.send :include, InstanceMethods end module ClassMethods def macro_method puts "Called macro_method within #{self.name}" end ...

Ruby - How to start an ssh session and dump user into it - no Net::SSH

So I've got dozens of servers I connect to and want a simple Ruby script that provides me with a list of those servers. Picking one will start up SSH with the proper connection details and let me start using it. That's it! But, I don't want/need Ruby to keep running. If I did I could use Net::SSH and capture all output and send it back ...

const_get but for variables

So I know you can say Kernel.const_get("ClassName") and you'll get back the class to which the string corresponds in name. But what about for variables? Is there a way to do: test = "heyas" some_method_here("test") #=> "heyas" Thanks so much The fact is that I need it in more complex code, real example: class User class Validation...

Updating protected attributes using update_all in a migration

Since you cannot use the normal 'update' and 'update_attribute' methods from ActiveRecord to update a protected attribute, is the following the best way to update an attribute for a single user? User.update_all("admin = true","id = 1") I'm guessing this doesn't lie in the 'best practice' category, so I'm just curious if there is a m...

google oauth doesn't redirect to callback after authorization

I can't seem to get google to redirect to the callback url after obtaining the auth token. By redirecting the user to the following url, the user can click grant or deny access. After that the user clicks on one of the choices, the user is not redirected back to the callback url. https://www.google.com/accounts/OAuthAuthorizeToken?oaut...

Can I ensure all tests contain an assertion in test/unit?

With test/unit, and minitest, is it possible to fail any test that doesn't contain an assertion, or would monkey-patching be required (for example, checking if the assertion count increased after each test was executed)? Background: I shouldn't write unit tests without assertions - at a minimum, I should use assert_nothing_raised if I'm...

A question in rails db:migrate

Now , I execute the command line "rake db:migrate" on the window OS, but I got the problem in the console. it print couldn't find HOME environment -- expanding~/.ruby-uuid'` who can help me to solve this ? Thank you and best regards! I think i should add the home path in the window environment . but i don't know ,which folder should i ...

How do I search for a phrase using search logic?

Imagine case scenario, you have a list of recipes that have ingredients as a text. You want to see how many recipes contain "sesame oil". The problem with default searchlogic searching using Recipe.ingredients_like("sesame oil") is that any recipe with sesame AND oil would come up, when I'm searching for "sesame oil" which is a problem...

upload analogue with XSendFile?

Is there some way to use something similar to x-sendfile for uploading files, e.g. saving particular stream/parameter from request to file, without putting it wholly into memory? (In particular, with apache2 and ruby fcgi) ...

Whats up with implicit return values in Ruby?

So I've started looking at ruby, and a lot of things look nice but I'm quite put off by implicit return statements. I understand making everything return self or nil by default but not the last value of a statement. To me it looks horribly fragile (especially) if you are working with a method that doesn't plan to return something (espec...

RCov started analyzing loaded libs (including Rdoc itself) – when using rvm (Ruby Version Manager)

Context rcov 0.9.8 2010-02-28 ruby 1.8.7 (2009-06-12 patchlevel 174) [i686-darwin10.3.0] rvm 0.1.38 by Wayne E. Seguin ([email protected]) [http://rvm.beginrescueend.com/] System Ruby (rvm use system): ruby 1.8.7 (2010-01-10 patchlevel 249) [i686-darwin10] Files The test setup is a 'lib' folder containing a single file which de...

Help me sort programming languages a bit

Hi, so I asked here few days ago about C# and its principles. Now, if I may, I have some additional general questions about some languages, because for novice like me, it seems a bit confusing. To be exact I want to ask more about language functions capabilities than syntax and so. To be honest, its just these special functions that bot...

Invoke rake task from ActiveRecord observer

Can I do the following? def ModelObserver < ActiveRecord def after_save Rake::Task[name].invoke end end At the moment, this returns the following error: Don't know how to build task 'name' Any idea? ...

uninitialized constant MysqlCompat::MysqlRes (mysql gem error) on Ubuntu, not fixing

I'm on Ubuntu 10.04 x64, ruby version 1.8.7 (2010-01-10 patchlevel 249) I've read this thread first: http://stackoverflow.com/questions/1332207/uninitialized-constant-mysqlcompatmysqlres-using-mms2r-gem and tried everything that people suggested: apt-get install libmysqlclient-dev export ARCHFLAGS="-arch x86_64"; sudo gem install --no...

how do i get name of the month in ruby on Rails?

so i create in my view: <%=date=Date.today%> How do i get the name of the month out of the date? I was trying to do sth like <%= DATE::ABBR_MONTHNAMES(date.month)%> But without success. I keep getting an error: uninitialized constant ActionView::Base::CompiledTemplates::MONTHNAMES How do i initialise the constant or is the...