4th - 10th July 2005
Ruby ‘Weekly’ News is a summary of the week’s activity on the ruby-talk mailing list / the comp.lang.ruby newsgroup, brought to you by Tim Sutherland.
Articles and Announcements
- Rails day results are in
Carl Woodward noted that the Rails Day official results are in. This was a contest to write the best web application you could in Rails – in 24 hours.
1st: Sheets, by Cyrus Farajpour and Robert Bousquet.
2nd: YubNub, by Jonathan Aquino.
3rd: Fichebowl, by Brandt Kurowski, Ben Tucker, and Aaron Michal.
From the site, “Congratulations to all of the winners and the runners up! We’d like to give a special thanks to the sponsors, supporters, and participants for making the first Rails Day a great success. – The Rails Day Team”.
User Group News
- PDX.rb July meeting
- Hamburg.rb - 2005-07-06 / 18:00
Phil Tomson announced that PDX.rb, the Portland Ruby Brigade, were having their July 2005 meeting on the 11th.
Stephan Kämper reminded the group that Hamburg.rb were meeting on the 6th of July in Stresemannstraße 144, Hamburg, Germany.
Jonas Hartmann: “Anyone up for some Frankfurt.rb meetings btw?”
Link of the Week
“lesscode.org is a place to advocate, discuss, and practice the art of using less code to get more done. We shun complexity and challenge the status-quo when it impedes our ability to simplify our development tools and processes. We appreciate Python, Ruby, LAMP, REST, KISS, worse is better, and talk like a pirate day.”
Arrrrrr!
Threads
HOWTO: gem install sqlite3
basi typed “gem install sqlite3”, and was prompted to select either ”<Ruby>” or ”<mswin32>”.
Selecting the latter succeeded, but when he went back and chose ”<mswin32>” there was a message “ERROR: Failed to build gem native extension”.
“Do I need to install both options?”
Alex Fenton said that you only need to install one of the options. The ”<mswin32>” option is provided for Windows systems. These typically lack a C compiler, so are not able to use the generic ”<Ruby>” version that will attempt to compile a Ruby extension.
HTTP.get problem
Ken Kaplan was having trouble getting a simple program from
Programming Ruby to work. It used Net::HTTP to retrieve
a webpage, however it would hang calling HTTP#get.
He had tried turning off ZoneAlarm (personal firewall software), but there was no difference.
Ezra Zygmuntowicz said that this was an issue with ZoneAlarm. Uninstalling ZoneAlarm would solve the problem – closing it is not sufficient.
Ezra also pointed to a
blog post by Jeff Nadeau, ZoneAlarm Woes,
which describes the problem.
(Windows provides a mechanism for converting a socket into a
handle that can be used with functions like WriteFile.
Ruby uses this so that sockets in Windows and unix systems work
in a similar way. Unfortunately, ZoneAlarm breaks this method.)
ruby-dev summary 26325-26385
Masayoshi TAKAHASHI posted the latest summary of the Japanese list ruby-dev.
XMLRPC and shebang lines were discussed.
Major web host supports Rails
bertrandmuscle noted that “One of the biggest web hosts on the internet (Dreamhost) now supports Rails!”
Later in the thread, Mathew wrote:I could really use a Java version of Rails; I’ve been referring to this hypothetical project as “Java on Crutches”.
[Sorry Java fans :-) ]
Inference Engine (#37)
James Edward Gray II posted this week’s Ruby Quiz.
“There was an interesting thread on Ruby Talk recently about Truth Maintenance Systems (TMS). One reason to use a TMS is to validate inferences, given certain truths. We’ll focus on that application here.
This week’s Ruby Quiz is to build an inference engine that is capable of answering questions based on the provided truths.”
Dynamic languages and the CLR
Michael Campbell posted a link to an article by Joel Pobar discussing techniques for implementing dynamic languages on the .NET CLR.
watir and iframes?
Armin asked “did anybody use watir on a page with iframes?” (Watir is a tool for testing web pages. It allows you to write Ruby code to script the IE browser.)
James Britt pointed to the relevant section of the Watir user guide:
it is as simple as using e.g. ie.frame("menu").
SerializableProc (#38)
James Edward Gray II also posted the next quiz.
“I’m a Proc addict. I use them all over the place in my code. Because of that, whenever I end up needing persistence and I call Marshal.dump() or YAML.dump() on some object hierarchy, I get to watch everything explode (since Procs cannot be serialized).”
“This week’s Ruby Quiz is to build a Proc that can be serialized.”
“It should support being serialized by Marshal, PStore, and YAML and otherwise behave as close to a Proc as possible.”
Fault Tolerant DRb?
Kirk Haines began “Assume you are using a DRb service for….something. It doesn’t matter what.” How could you make the service work in a fault tolerant way?
Ara.T.Howard replied “i’ve done tons of ha (high availability) setups before for stateful and stateless machines. suffice it to say it is almost un-imaginably complex.” He pointed out a couple of things which must be considered, and said “these problems are solved – but it’s still amazingly hard to get right. check out the linux-ha project”.
Ara also linked to the rb_spread project, which allows Ruby to participate in Spread reliable multicast groups.
modifying pickaxe 2 pdf
Botp Peña asked if it would be possible for him to modify the PickAxe 2 PDF. (The second edition of Programming Ruby.) Also, “is it legal to change it?”
“I want to put notes, extra samples, links, references, etc… and maybe include interactive forms”.
Sascha Ebach did an experiment, and found that it did work.
Dave Thomas responded,Feel free to annotate to your heart’s content. If you had a paper book, we wouldn’t stop you writing in the margins. Why would we stop you with a PDF?
As you say, it would be wrong to distribute your PDF (annotated or not), but what you do with it in the privacy of your own home is your business :)
Win32OLE and remote servers?
Hal asked whether Win32OLE could be used to talk to a COM object on a remote machine. (DCOM.)
daz gave a link to a post from 2002 that shows how to do this: pass a machine name as the second parameter toWin32OLE.new.
accessing index inside map
Botp Peña asked how to do a map, but using an index inside the block.
He wanted to be able to take the array [1, 2, 3, 4, 5, 6] and double each element, apart from those
at the second and fifth positions.
_(This writeup instead uses an example involving an array of letters - a [misguided?] attempt to make the solutions given slightly easier to understand.)_
daz said that David A. Black “was once President of Citizens for MWI, Inc.” -
he advocated adding a map_with_index method to
the standard library. David disputed this characterisation: there’s
no “was once” about it, he still thinks it’s a good idea.
map_with_index can be implemented in the following way:
class Enumerable
def map_with_index
a = []
each_with_index { |x, i|
a << yield x, i
}
a
end
end
It can then be used as below:
letters = ['a', 'b', 'c']
ary = letters.map_with_index { |x, i| x + i.to_s }
p(ary) # -> ["a0", "b1", "c2"]
Nobu gave an alternative suggestion: use the enumerator library.
An example:
require 'enumerator'
letters = ['a', 'b', 'c']
ary = letters.enum_for(:each_with_index).map { |x, i| x + i.to_s }
p(ary) # -> ["a0", "b1", "c2"]
The enum_for method returns a new Enumerator
object, which wraps the original but with a different each method.
(In this case, letters.each_with_index.)
Because methods in Enumerable such
as map are implemented
in terms of each, they pick up the new behaviour.
Botp Peña found enum_for a little confusing, and Matz
poked in with an interesting idea.
“We have vague plan to make enumerating method to return Enumerator when no block is given in the future”. This would enable the above example to be rewritten as:
require 'enumerator'
letters = ['a', 'b', 'c']
ary = letters.each_with_index.map { |x, i| x + i.to_s }
p(ary) # -> ["a0", "b1", "c2"]
Botp Peña agreed that this was indeed clearer than enum_for,
but felt that map_with_index was even clearer.
Matz responded, “Yes. But when we add map_with_index, we might be asked to add collect_with_index, detect_with_index, inject_with_index, and all other enumerable methods _with_index as well.”
Nobu thought of adding Enumerator#with_index, and
provided a patch to implement it. Usage:
require 'enumerator'
letters = ['a', 'b', 'c']
ary = letters.map.with_index { |x, i| x + i.to_s }
p(ary) # -> ["a0", "b1", "c2"]
Matz asked him to commit this patch.
RubyConf 2005 Registration now open
Chad Fowler announced that registrations for the Fifth International Ruby Conference – RubyConf 2005 – were now open.
“Pre-registration numbers are amazingly high in contrast to years past. All signs point to this year’s conference standing out as a turning point.”
The conference this year is in San Diego, California, and is held October 14-16.
Ruby as mathematical language
none attached some correspondence he had with
Yoshiki Tsunesada to do with the latter’s rb-gsl
library. (An interface to the GNU Scientific Library.)
none aimed to start a conversation about what libraries
Ruby needs to be an “intuitive and powerful math language”.
narray – a library providing efficient
N-dimensional arrays with numerical methods for tasks
like solving linear equations.
Ara also gave a tantalising link to a wiki page entitled TheScientificRubyProgrammingBook, which claims to be “Coming Soon To a Pragmatic Bookseller Near You!”, authored by Ara and Justin Crawford, and edited by Dave Thomas.
The wiki page was part of the SciRuby site, “a portal for all things scientific and ruby.”
Programming the Lego robots using Ruby technology
Victor Reyes asked if he could program Lego Mindstorm robots using Ruby.
daz referred him to the lego-mindstorms package on RubyForge, however Shashank Date pointed out that this was an API for controlling the robots, not programming them.
yield does not take a block
Daniel Brockman noted that under Ruby 1.9.0, the following are not allowed:
yield { .. }
yield &..
However, these are:
Proc.new.call { .. }
Proc.new.call &..
“This is an oversight, right?”
Nobu thought that it was, and posted a patch to enable the first two forms.
Matz wasn’t so sure: “yield is a keyword to pass a value (and control) to the block attached to the method. I feel strange when I see yield passes a block to an outer block.”
James Britt asked “Is that good strange or bad strange?”
Matz: “I feel bad strange. Do you?”
James Britt: “No. Good strange.”
Daniel Brockman: “I feel strange when I see these are not equivalent”.
Remember, “your least strangeness is NOT Matz’ least strangeness!” (the cult of why).