ruby

Ruby check if smth is mounted(--bind) in this directory

Hi mount /project on /mount_1 type none (rw,bind) /project on /mount_2 type none (rw,bind) /project on /mount_3 type none (rw,bind) How to check with ruby(not shell!!) if some dir is mounted on /mount_X? Is there something easier then opening /proc/mounts and looking for /mount_X there? ...

Ruby : Datamapper don't insert in database.

I a have the following datamapper ressource : class Job include DataMapper::Resource storage_names[:default] = 'job' property :id, Serial property :at, Integer, :required => true, :min => 0 property :name, Float, :required => true, :default => 0 property :cpu, Float, :required => true, ...

Mysql gem with MAMP

Hi, I'm running MAMP for local development on Snow Leopard (64bit obviously). I'm trying to run a rake task for a ruby on rails application and get the following error: " !!! The bundled mysql.rb driver has been removed from Rails 2.2. Please install the mysql gem and try again: gem install mysql. !!! The bundled mysql.rb driver has be...

How to setup a Sinatra app under Apache with Passenger?

Let's say I have the simplest single-file Sinatra app. The hello world on their homepage will do. I want to run it under Apache with Phusion Passenger, AKA mod_rails. What directory structure do I need? What do I have to put on the vhost conf file? I understand I need a rackup file. What goes in it and why? ...

In Ruby, is there an Array method that combines 'select' and 'map'?

I have a Ruby array containing some string values. I need to: Find all elements that match some predicate Run the matching elements through a transformation Return the results as an array Right now my solution looks like this: def example matchingLines = @lines.select{ |line| ... } results = matchingLines.map{ |line| ... } re...

C#/Java/Ruby - Hash Alogrthym for Passwords - Cross-Lang/Platform

What is a good password hashing algorithm to use from C#, if later on you may know that there are going to be Java and Ruby programs that may also need to 'login'/authenticate a user. Anything out of the box in .NET that translates well to other languages and is easy to use. ...

ruby atomic operations in multithreaded environment

Are push and pop operations for arrays atomic? Can i safely run i = array.pop ... array.push(i) in GIL-threaded env? ...

How to tell bunlder where the Gemfile is?

I'm trying to run a ruby script from cron, the script uses bundler to manage gem dependencies, since cron does not run in $PWD I get a 'Could not locate Gemfile' error form bundler every time, which makes sense since Gemfile is not in the currrent path when running from cron. Is there a way to tell bundler to use a Gemfile not in the cu...

edit with vim in irb

Hi, I'm trying to set up editing within irb using vim as described in this vimcast: http://vimcasts.org/episodes/running-vim-within-irb/ I did the gem install interactive_editor and it seemed to install the gem to /home/me/.gems/ruby/1.9.1/gem/interactive_editor, and I also edited my .irbrc file and added: require 'rubygems' require '...

What is a clean way to use a "/" in a part of a URL.

In an MVC framework, I have a model with an "identifier" field. This field can be whatever is used by the user as their unique identifier. I then use this identifier field in URLs to access the relevant resources. /people/<identifier>/ In one such case, the user is using identifiers of the format 00/000. The quick among you will have ...

AWS S3 with Rails problems with caching and reloading.

I have a bit of code like so which works fine if the file in question doesn't already exist. if AWS::S3::S3Object.exists? file_name, bucket.name + path_to_images puts "file exists (deleting)" AWS::S3::S3Object.delete file_name, bucket.name + path_to_images, :force => true end AWS::S3::S3Object.store file_name, File.read(file_pa...

What is a short, simple, useful, cool, impressive, or geeky Ruby code?

For examples, @second = 2 @foo = @first || @second || @third p @foo #=> 2 and p [1, 2, 3].map(&:to_s) #=> ["1", "2", "3"] I'm looking forward to reading an interesting code! Thanks :) ...

How to tell ruby on rails, not to insert to a column ?

I have a table, with merge replication on it (SQL Server 2005). There is a rowguid column. I want RoR to ignore this column, and not insert into this, and not include this when generating the INSERT statement. ...

Ambiguous Column Naming in Select List -- DataMapper for Ruby

In DataMapper, I have tables like this: Foo === id Integer other_columns Whatever Fuzz === id Integer other_columns Whatever For associations: class Fuzz has 1, :foo, :child_key => :id end When I call: Fuzz.first.foo DataMapper generates SQL like this: select raw_sql_.* from(SELECT "ID", "OTHER_COL...

Convert a class to a subclass on instantiation

I'm writing a framework for querying the Mediawiki API. I have a Page class which represents articles on the wiki, and I've also got a Category class, which is-a Page with more specific methods (like being able to count the number of members in the category. I've also got a method Page#category? which determines if an instantiated Page o...

Difference between Ruby 1.8.6 and 1.8.7?

What are the main reasons or pros/cons somebody would choose to work in 1.8.6 over 1.8.7 or vice versa? So far I can only find this answer, which is from the latest version of the Agile Rails beta e-book: "Rails 3.0 requires requires Ruby version 1.8.7 or Ruby 1.9.2-preview3. (It is known not to work on Ruby versions 1.8.6, Ruby 1.9.1...

Observe field is not doing anything

I want a search field to start outputting results once a user starts typing. This is my view: <%= observe_field 'keyword', :url => { :action=> 'search_results' }, :frequency => 0.5, :update => 'results', :loading => "$('.spinner').show()", :complete => visual_effect(:slide_down, "results", :d...

Amazing Micro Applications and Open Source Projects

As time goes on people are finding smaller, more efficient ways to do things. I'm really impressed at some of the amazing things people have made that are so incredibly simple. Our quest for "a better wheel" has lead to things like a 3Kb javascript framework, a 1kB ORM, a tweet sized framework & DI container, an entire forum in 1kb, a 9...

forcing a specific gem version as the default?

Let's say I've got three gems installed: package-0.4.0, package-0.5.0, and package-0.5.0-jbfink (I've built the -jbfink one because I made very minor alterations to 0.5.0's source and want to distinguish it from the official releases) . Is there a gem (or other command) to make one the default? Right now I've got all three installed, b...

Ruby chainable method / array

How do I implement the '<<' to have the same behavior when used as a chainable method? class Test attr_accessor :internal_array def initialize @internal_array = [] end def <<(item) @internal_array << :a @internal_array << item end end t = Test.new t << 1 t << 2 t << 3 #t.internal_array => [:a, 1, :a, 2, :a, 3] p...