ruby

How to update a Ruby hash item inside of a loop over that hash?

I am migrating my PHP code to Ruby and at some point I need to update hash elements inside of a loop. For example: compositions.each_pair do |element,params| params['composition'].each_pair do |item,data| data['af'] /= params['af sum'] data['mf'] /= params['mass'] end end I could make it using item indexes, but it will be...

RubyGems behind a proxy: InvalidArgument

The other question (here: ) had solutions that I tried but they didn't work. I am behind a proxy at work, and can't figure out how to get RubyGems to work through it. Here's some output to help: josiah@BOX-OF-DOOOM:/etc$ export HTTP_PROXY=http://jkiehl:[email protected]:80/ josiah@BOX-OF-DOOOM:/etc$ sudo gem i c...

Where and how to handle rails exceptions?

I am currently involved in the development of a large rails application that interfaces with another product via a custom API gem. This has led to a very strange sort of error catching. For instance, when we interact with the other product, it might return an authentication error, which we expect. We then catch that error in our API g...

Eventmachine / Em-http-request / SQL throughput and architecture

I'm trying to create some code to process the twitter spritzer stream, and from the advice I'd found it seem like using ruby's eventmachine/em-http-request is a good way to do it. The basic code is below, and I'm getting ok performance, but I don't believe its able to keep up with the stream (despite running on a fairly well spec'd AWS ...

ruby loop next case example

I am trying to loop through multiple statements, but want to go through each one once, example: while count < 5 do count+= (not sure if this how ruby increments counts) puts "In condition one" next if count > 1 puts "In condition two" next if count > 1 #.. end Update 1: Thanks for the reply, what I'm trying to do is loop ...

Albacore: including only certain files/folders in a zip

Hi everyone, I'm trying to zip up the artifacts of a rake build, using Albacore's ZipTask. The solution I'm building has three projects that have artifacts that need to be zipped up individually, but only the ASP.NET MVC project will be mentioned here. Here's the directory structure of the solution: rakefile.rb solution.sln src/ (...

Should I Take Security Measures for a Small, Single-Service Server?

I have some experience with programming, but I have very little experience when it comes to the security of programs. I've written a single-service server in Ruby which runs on a Windows XP computer to be used by a Linux computer in the same lab. The lab network is also behind a firewall, so there might not be a problem there, but I real...

How to rebuild rdoc for all the installed gems?

I have several gems installed in multiple locations. What is the hard/easy way to generate/re-generate: rdoc for all these installed gems, all at once? yardoc for all these installed gems, all at once? ...

how to put embedded document into an embedded document ?

hi I have a form that has a category model and and embeded docuement called "FieldModule" and this has embedded document called "SubFieldModule" For example class Category include MongoMapper::Document key :name, String many :field_modules end class FieldModule include MongoMapper::EmbeddedDocument key :name, String ...

uninitialized constant on class from ruby gem

Hello, I am trying to implement a gem called stanfordparser which can be found here: http://stanfordparser.rubyforge.org/ It is a ruby wrapper for a java natural language parser I am developing in netbeans using ruby on rails / jruby on a windows 7 machine. My web app works fine otherwise, but when I try to add the parser wrapper it br...

Functional unwrapping of nested array

Given an array containing other nested arrays, I want to create an array containing only the elements from the first array. For example [["1", "2"], "3", [["4"]]] should evaluate to ["1", "2", "3", "4"]. I've managed to make a method that works: @@unwrapped_array = [] def unwrap_nested_array(array) if array.respond_to?('each') ...

Trace a deadlock in Ruby

I use BrB to share a datasource for various worker processes in Ruby 1.9 that I fork with Process#fork like the following: Thread.abort_on_exception = true fork do puts "Initializing data source process... (PID: #{Process.pid})" data = DataSource.new(files) BrB::Service.start_service(:object => data, :verbose => false, :host => ...

Adding files to redmine via command line

We have an automatic build system that spits out packages, regression-tested & wrapped into a neat installer, ready for end-users to d/l & deploy. We do tracking of end user support requests/bug reports via redmine. So far we uploaded the packages manually to the resp. 'Files' section of the redmine project, via the web interface. What ...

Sort an array of hashes by a value in the hash

Hello, this code is not behaving as I would expect: # create an array of hashes sort_me = [] sort_me.push({"value"=>1, "name"=>"a"}) sort_me.push({"value"=>3, "name"=>"c"}) sort_me.push({"value"=>2, "name"=>"b"}) # sort sort_me.sort_by { |k| k["value"]} # same order as above! puts sort_me I'm looking to sort the array of hashes by ...

Generating polymorphic routes from objects passed to Liquid Template engine

I'm using Liquid markup in a Rails project that I'm working on, and I'm trying to create a link_to filter. I'd like to be able to generate templates such as the following: <ul> {% for page in edition.pages %} <li>{{page | link_to_page}}</li> {% endfor %} </ul> Where I could use polymorphic routes to generate the link based on t...

drb problem? ringy-dingy won't answer...

The following code works fine as long as I don't try to run it through the distributed server. It doesn't get there... It runs fine out of delayed_job, runs fine if called directly. But if 'distrib' is true (the default) it runs right up to the call to the server and right past it without getting to the server or raising any errors. Am...

Ruby comparison operators? == vs. ===

What's the difference between == and ===? Which one should you use when? ...

DataMapper Associations, simple code, not working

I'm just begining to use DataMappers associations, just to test things out have a very simple table structure, and it's is borking. require 'dm-core' require 'dm-migrations' DataMapper.setup( :default, "sqlite3://#{Dir.pwd}/dbtest.db" ) class Account include DataMapper::Resource property :id, Serial has 1, :userp...

What to do about failed native extension builds in gem on Windows?

A couple of Rails applications I downloaded have dependencies on bson_ext which appears to be a native code library. When I run rake gems:install for the app I get the following error message: ERROR: Error installing bson_ext: ERROR: Failed to build gem native extension. d:/Ruby187/bin/ruby.exe extconf.rb checking for asprint...

Java-style annotations in Ruby and C++?

What would be the way to have java-style annotations in Ruby and in C++? (Optionally, perhaps it is a matter of taste) Are java-style annotations worth to be used, so you would recomend using them in other languages, if possible? ...