ruby

How do I extract a date range from a csv using perl/php/grep/etc?

Is there a way to take text like below (if it was already in an array or a file) and have it strip the lines with a specified date range? For instance if i wanted every line from 2009-09-04 until 2009-09-09 to be pulled out (maybe this can be done with grep?) how would I go about doing so? date,test,time,avail 2009-09-01,JS,0.119,99....

XML Parser for Ruby

Looking for something similar to xerces for parsing an xml file in ruby. I saw the native processor REXML and another called hpricot (though I can't find any documentation on hpricot, the links all appear to be dead). I'm looking for something that would parse an xml document via SAX2 in ruby. TIA. ...

Ruby: How to either set a variable to 0 or, if it is already set, increment by 1

I know of the ||= operator, but don't think it'll help me here...trying to create an array that counts the number of "types" among an array of objects. array.each do |c| newarray[c.type] = newarray[c.type] ? newarray[c.type]+1 ? 0 end Is there a more graceful way to do this? ...

How do I make Firefox open a file with an ampersand in the filename?

I've written some Ruby code to inspect ZIP-files as part of an internal company process. The way we usually launch this code is from a web browser. When you click to download the file, you select "open with" and specify the full path to a small batch file. This one-line batch file looks like this: \\mathworks\public\Matthew_Simoneau\...

Ruby CGI.unescapeHTML generating strange charactors

I have backed up a bunch of markdown formatted comments into an XML document. This of course meant I needed to HTMLescape them. When I try to use CGI.unescapeHTML it adds a bunch of strange characters into the markup that do not render well in all browsers. Specifically, it replaces two spaces with "\302\240 ", but not consistently. ...

datamapper multi-field unique index

In Datamapper, how would one specify the the combination of two fields must be unique. For example categories must have unique names within a domain: class Category include DataMapper.resource property :name, String, :index=>true #must be unique for a given domain belongs_to :domain end ...

Ruby on rails: Render 2 partials or figure out the kind of class and object is...

I want to display different types of objects in the same ajax called controller function. I want to render out when I send back an ajax call. The problem is I want the "title" attribute of one object and the "name" attribute of another object. I can't render 2 partials and can seem to figure out how to check the type of object an object ...

Does ruby have the ability to split a directory string?

In ruby, I'm able to do File.dirname("/home/gumby/bigproject/now_with_bugs_fixed/32/FOO_BAR_2096.results") and get "/home/gumby/bigproject/now_with_bugs_fixed/32" but now I'd like to split up that directory string into the components, ie something like ["home", "gumby", "bigproject", "now_with_bugs_fixed", "32"] Is there a way t...

Why am I getting two very different results from these two functions

this is copied from http://www.zenspider.com/ZSS/Products/RubyInline/Readme.html, the "home" of rubyinline, adding/moding as indicated in the comments require 'rubygems' #added this, doesn't run otherwise require 'inline' class MyTest def factorial(n) f = 1 n.downto(2) { |x| f *= x } f end inline do |builder| bui...

Java (6) Hash & Array alternatives that behave more like their Ruby counterparts

Having been spoiled by ruby for so long, I now find myself having to do some Java development (Eclipse RCP). I'm wondering if anyone knows of alternatives to HashMap & ArrayList that have some of the sugar of ruby. The verbosity of dealing with an ArrayList of HashMaps drives me bonkers. I'm also interested in finding other Ruby langua...

ActiveRecord interfering with Logger

It appears that using ActiveRecord (which requires ActiveSupport) messes with the Logger class, resulting in difficulties. This can be seen with some example code: require 'rubygems' #require 'activerecord' require 'logger' log = Logger.new(STDERR) log.sev_threshold = Logger::INFO log.datetime_format = "%Y-%m-%d %H:%M:%S" log.debug "...

RubyGems refuses to update from 1.3.1 to 1.3.5

I can't update the rubygems from 1.3.1 to 1.3.5. I've tried the following commands with no luck(logged in as the root) gem update --system gem update rubygems gem update rubygems -v 1.3.5 gem install rubygems-update -v 1.3.5 The response for the first three command is Updating RubyGems Nothing to update while for the last one t...

What is an Algorithm to Diff the Two Strings in the Same Way that SO Does on the Version Page?

I'm trying to diff two strings by phrase, similar to the way that StackOverflow diffs the two strings on the version edits page. What would be an algorithm to do this? Are there gems, or other standard libraries that accomplish this? EDIT: I've seen other diffing algorithms (Differ with Ruby) and they seem to result in the following: >...

How to reload partial pages in Rails using RJS ?

Hi Currently i am working on a rails project . where i have to reload a partial page . For example Create action def create # Some transaction to the database respond_to do |format| format.html {render :text => 'Add post' } format.js end end In my views posts/create.js.rjs i would like to reload the users/...

How to render all records from a nested set into a real html tree

I'm using the awesome_nested_set plugin in my Rails project. I have two models that look like this (simplified): class Customer < ActiveRecord::Base has_many :categories end class Category < ActiveRecord::Base belongs_to :customer # Columns in the categories table: lft, rgt and parent_id acts_as_nested_set :scope => :customer_...

What's wrong with Aptana RadRails Eclipse update site?

I'm trying to install Aptana Studio as Eclipse plugin in Eclipse 3.3 (Europa), and I'm following instructions on this link. However, the recommended update address for Eclipse 3.3 http://update.aptana.com/install/studio/3.2/ returns the following error message: "Unable to access site: "http://update.aptana.com/install/studio/3.2/" [Serv...

Aliasing activerecord methods inside plugin

I'm trying to write a plugin that aliases some methods in ActiveRecord in the following fashion: class Foo < ActiveRecord::Base include MyOwnPlugin acts_as_my_own_plugin :methods => [:bar] def bar puts 'do something' end end Inside the plugin: module MyOwnPlugin def self.included(base) base.class_eval do ...

Is there a python library/module for creating a multi ssh connection?

I've been searching for a library that can access multiple ssh connections at once, Ruby has a Net::SSH::Multi module that allows multiple ssh connections at once. However I rather prefer coding this in Python, are there any similar SSH module for python? ...

Strip signatures and replies from emails

I'm currently working on a system that allows users to reply to notification emails that are sent out (sigh). I need to strip out the replies and signatures, so that I'm left with the actual content of the reply, without all the noise. Does anyone have any suggestions about the best way to do this? ...

Having problems with net::ssh::multi can't require it! Ruby

So I've tried to install net::ssh::multi on mac using gems: gems install net-ssh-multi The installation went fine, however when I type: require 'net/ssh/multi' it says load error. I have no idea whats wrong with what I'm doing! ...