ruby

How to download fast lots of web pages in ruby? Parallelizing download?

I need to scrape(using scrAPI) 400+ web pages ruby, my actual code is very sequential: data = urls.map {|url| scraper.scrape url } Actually the code is a bit different (exception handling and stuff). How can I make it faster? How can I parallelize the downloads? ...

Ruby and Ruby on Rails crash course syllabus

I intend to design an induction plan or you can say a crash course syllabus for developers starting to learn Ruby and Ruby on rails. I am not sure about number of topics to be covered (And the depth of coverage) as this is a 3 day course (24 to 27 hours). Also, newbies tend to compare ruby with existing object oriented programming vetera...

Detect if running with administrator privileges under Windows XP

I am trying to work out how to detect whether a user is running with admin rights under Windows XP. This is fairly easy to do in Vista/Win7 thanks to the whoami command. Here's a snippet in Ruby for how to do it under Vista: Note, the following link now incorporates the solution suggested by muteW http://gist.github.com/65931 The trou...

Vary the command/pathmap run in a rake rule based on which target is running

I'm trying to write a Rakefile that both builds my code normally when I run rake compile but puts the targets in a different directory and builds with -DTEST when I run rake test. I cannot for the life of me figure out how to do it, though. I've got something like this at the moment: SRC = FileList['src/*.erl'] OBJ = SRC.pathmap("%{sr...

How to alias ActiveRecord class methods dynamically in a rails plugin?

I'm having trouble removing some duplication I've introduced in a rails plugin. The code below modifies the find and calculate methods of ActiveRecord in the same way, but I've been unable to remove the duplication. The find and calculate methods below make use of the super keyword which is one hurdle as the super keyword can only be u...

Is this the proper way of denying remote connections to jssh on Linux ?

I don't know if jssh has any security built-in. While testing web apps, I would only like to be able to connect to jssh from localhost. I added the following lines to iptables : iptables -A INPUT -p tcp -s 0/0 --dport 9997 -j LOG iptables -A INPUT -p tcp -s 0/0 --dport 9997 -j DROP will they provide the security I need? EDIT : this ...

How can I fix this warning produced when I run my Test::Unit tests

I'm getting this warning in my Test::Unit output... /usr/local/bin/ruby -I.:lib:test -rtest/unit -e "%w[test/functional/sessions_controller_test.rb].each { |f| require f }" | unit_diff -u Loaded suite -e Started .../Users/ethan/project/mtc/contactdb/app/views/sessions/new.html.haml:30: warning: multiple values for a block parameter (0 f...

Iterating over substrings of equal size

I want to convert my String object to Enumerable of its 1-sized substrings (not chars), how can I do this efficiently in Ruby? ...

Do I need to manually create a migration for a HABTM join table?

Hello. I'm struggling now to get HATBM working correctly. I have a beaten scanario: articles and tags. I presume, HABTM should be used here, since it is a many-to-many relationship. I don't know however if I should manually create a join table (articles_tags in this case). My code currently as follows: class Article < ActiveRecord::Ba...

Splitting string into pair of characters in Ruby

I have a string (e.g. "AABBCCDDEEFF") and want to split this into an array with each element containing two characters - ["AA", "BB", "CC", "DD", "EE", "FF"]. ...

Ruby win32ole - how to pass a VARIANT parameter?

I am trying to automate the Windows Task Scheduler using Ruby. I am using Ruby 1.8 under Windows Vista. The RegisterTaskDefintion method of the TaskFolder object takes two VARIANT parameters for the username and password. Any attempt to pass a string into these parameters results in a 'method_missing' exception: This does not work: r...

Ruby On Rails is slow... ?

I'm writing a web application to monitor a furniture factory production flow. It has thousand of data to handle. So far, I run RoR on Mongrel + MySQL and it's really really slow (2-4min for some views). When I look at RoR logs, it seems that database queries aren't slow (0-10ms). Is RoR slow when it converts database data to object ? Is...

How can I force gem to upgrade to gem 1.3.1

I am trying to install a gem like this: C:\InstantRails\rails_apps\foodmarksthespot>ruby script/plugin install git://github.com/lazyatom/engines.git Which returns this message: Rails requires RubyGems >= 1.3.1 (you have 1.2.0). Please `gem update --system` and try again. But when I try to update using: gem update --system it say...

Detecting overwriting of ruby test methods

If you write a test class like class MyTest < Test::Unit::TestCase def setup end def test_1 flunk end def test_1 assert true end end the first test_1 is ignored. Although it looks like a stupid mistake, it can happen with copy and paste programming. Apart from running grep test test_me.rb | wc and comparin...

Why would C# ProcessStartInfoRedirectStandardOutput cause xcopy process to fail

This is a bit of a pain because I now don't have the code in front of me, but I'll try to explain. I have a simple C# application that kicks off a Ruby script (it does a couple of other things, so it generates a batch file and executes that). I am using the C# process object and I set the following redirectstandardoutput = true redirec...

Are Ruby class member variables OK now?

Hi, Last May at Railsconf on Portland, I went to a presentation where it was argued that, in Rails, Ruby class member variables, like @@foo, are dangerous because they are inherently unthreadsafe. I researched the question afterward and I never found a link that really fleshed out the question. I would appreciate a pointer to a good ...

What Rails plugins would you like to see?

What behavior have you had to implement in your Rails applications that you feel could exist nicely as a plugin? What plugin functionality have you searched for in the past but couldn't find? What existing Rails plugins could be improved or extended, and how? ...

count duplicate elements in ruby array

I have an sorted array like this: ['FATAL <error title="Request timed out.">', 'FATAL <error title="Request timed out.">', 'FATAL <error title="There is insufficient system memory to run this query.">'] I would like to get something like this (does not have to be a hash): [{:error => 'FATAL <error title="Request timed out.">', :count...

Loading Iron Ruby DSL files on demand

Hi, Currently I have an application that stores metadata information written in a boo internal DSL. I store the metadata in seperate .boo files that I load if and when I need them like this: IConfigReader reader = factory.Create(BUILD_FILE_NAME); I would like to take advantage of Iron Ruby's or indeed Ruby's meta programming by conve...

Getting the name of an instance variable

Looking through the rails 2.3 RC1 release note I see this: # Equivalent of render :partial => 'articles/_article', :object => @article render @article So somehow the render method is finding out the that object passed int it is assigned to an instance variable with the name article. How does it do this? ...