Ruby Weekly News 28th February - 6th March 2005

T

Tim Sutherland

http://www.rubygarden.org/ruby?RubyNews/2005-02-28

Ruby Weekly News 28th February - 6th March 2005
-----------------------------------------------

A summary of the week's activity on the ruby-talk mailing list / the
comp.lang.ruby newsgroup. This summary is brought to you by Tim Sutherland
(TimSuth).

You can [subscribe] to the RubyWeeklyNews newsletter to be emailed a text
copy of the summary once a week.

(Meta-You may be interested to know that Paul van Tilburg has done
a mockup of a better Ruby Weekly News site, using Hobix:
http://rwn.luon.net/. I like this - Atom and RSS feeds, plus a cool
archive calendar module. Look out for http://www.rubyweeklynews.org/ next
week.)

Articles and Announcements
--------------------------

* [Chicago Ruby users]

pat eyler noticed that DHH (David Heinemeier Hansson, of [Rails]
fame) was going to be in Chicago in April, and suggested the local
Ruby users organise a meeting while he's around. Chad Fowler may
be there as well. DHH: "Sounds like fun. We had a good time at the
Omni offices when I was in Seattle. If you guys can arrange
something on Saturday, we can definitely have a session."

* [Ruby-VUG - Project Team Nopaste Underway!]

Zach Dennis announced that project [Team Nopaste] "has been
underway for around a week now". The plan is to extend the
functionality provided by the [Nopaste] site (which allows people
to post snippets of code, used for example to show code to people
on IRC without trying to paste it into the channel) to work better
with groups of people. (Edits, history, categories and access
restrictions.) It will be implemented in [Rails]. This is part of
the Ruby-VUG (Virtual User's Group) project, so contributors are
very welcome.

* [Part 2 of ONLamp.com Rails article is online],
[Whoo Hoo... We're on the Slashdot front page!]

[OnLamp.com] published [part two] of Curt Hibbs' Rails article. It
also got posted on the front page of slashdot. "In Rolling with
Ruby on Rails, I barely scratched the surface of what you can do
with Ruby on Rails. I didn't talk about data validation or
database transactions, and I did not mention callbacks, unit
testing, or caching. There was hardly a mention of the many
helpers that Rails includes to make your life easier." Part two
fills in some of these gaps.

* [FreeRIDE project - Call for help]

Laurent Julliard posted a "call for help" for the [FreeRIDE] Ruby
IDE. It has reached a state where it has a lot of useful features,
but also some weaknesses such as documentation, stability and
speed on Windows, installer for MacOS X, and "Testing, testing,
testing...". Collaborative programming was also something that
FreeRIDE developers have been interested in from the beginning,
but which no-one has yet worked on. This is a great chance for
people to start helping out!

* [Ruby VUG - For Real, No Joke, Its About Time]

Last week we reported on efforts to start a Ruby Virtual User's
Group (VUG). Much activity has occured this week, with a [wiki
site] listing channels for communication and project ideas. One of
the suggested activities is to develop the team / collaboration
plugin for FreeRIDE mentioned above.

* [new Og tutorial on RubyGarden]

George Moschovitis wrote a tutorial on his Og (ObjectGraph)
database library, and submitted it as a [RubyGarden article]. Chad
Fowler requested "If you'd like to write an article or tutorial or
conduct an interview to be published on RubyGarden.org, please
send me an email directly."

Quote of the Week
-----------------

Scott Barron did [quoth]:

"Scratch is the minimalist's web log. Scratch gives you nothing more than
the meta-weblog API for posting. Reading is done via Atom or RSS. That's
it. There's no HTML to hack up. You don't have to use the same, tired old
web log template that everyone else is using. Break out of that blue,
rounded rectangle! Be original! Thumb your nose at those primitive apes
still using the web! Use Scratch!"

Threads
-------

Interesting threads this week included:

[Any tips on migrating code from Windows to UNIX]
-------------------------------------------------

Kurt Euler was having problems getting a Ruby program that had been
developed on Windows to work in a unix system. It ran, but with no output.
James Britt said to try running with tracing: "ruby -rtracer code.rb".

[Method parameters reflection]
------------------------------

George Moschovitis wanted to use reflection to find out the names of
method parameters.

For example:

class MyClass
def simple_method(last_name, name)
end
end

method_params(MyClass, :simple_method)
=> [:last_name, :name]

"I have implement this using ParseTree, but since ParseTree uses
RubyInline which requires a C compiler, and AFAIK is not portable, I would
like a better solution."

Hal Fulton said there was no better soution at the moment. Florian Gross
noted that even EvilRuby doesn't support this. (EvilRuby wraps many
internal Ruby data structures using Ruby/DL and implements methods for
doing low-level hackery.)

[Ruby/X11]
----------

Malte Milatz asked of Ruby/X11 "Is it possible to play around with it a
bit (that, and nothing more, is what I'd like to do) without being an X11
guru? Any documentation, any tutorials for other languages that can be
applied do Ruby/X11, too?"

vruz said that you do need to know the basics of X11, since Ruby/X11 just
implements the X11 specification, without adding a layer on top. Eric
Hodel agreed, saying "Ruby/X11 is an X protocol implementation. It lacks
many of the helpful methods of Xlib, so if you'll need to write out
similar helpful wrapper methods yourself."

[Ruby Quickstart ("Tutorial on a few pages")]
---------------------------------------------

Iwan van der Kleyn will be giving an in-company presentation on a project
that uses Ruby, and needs a short introduction to Ruby that he can pass
out beforehand. James Britt posted links to some presentations.

[catting files]
---------------

Mark Probert implemented 'cat' in Ruby and found it to be much slower than
the 'cat' program on his system. (cat concatenates files, i.e. outputs the
contents of one followed by the contents of the other.) How could the
performance be improved?

Mark was calling readlines on each file and then puts'ing the result. This
meant that the data was first slurped up line-by-line into an Array before
being output. Florian Gross suggested just using read to get the data as a
String. He added, "You might get better performance by reading the files
in 4096 byte blocks or something similar."

[Calling methods in the inheritance chain...]
---------------------------------------------

gga wrote:

class A
def a
puts "A::a()"
end
end

class B < A
def a
super
end
end

class C < B
def other
A#a() # no cigar... A's methods cannot be called
end
end

How would you force Ruby to call the A version of the method from within
C? The answer is that you should never do such a thing, but if you must,
Florian Gross has the solution: "A.instance_method:)a).bind(self).call()".

[nice surprise in ruby's CVS]
-----------------------------

gabriele renzi remarked "I did my usual check out of ruby's cvs HEAD and I
discovered I can now do this (but this is marked EXPERIMENTAL):"

a = {|x| x**x }
a.call(10) => 10000000000

With Ruby 1.8 you have to do "a = proc { |x| x**x }".

George Moschovitis replied with "Great, but a(10) => 10....00 would be
better ;-)", to which Martin DeMello said "a[10] is not too terrible :)".
(George will be interested in the [functionCall] post on the [RedHanded]
blog - Matz is considering making a(10) work.)

[ruby-dev summary 25741-25780]
------------------------------

In related news, Minero Aoki posted the most recent summary of the
Japanese mailing list ruby-dev.

"Minero Aoki reported that ruby does not execute pure ruby signal handlers
while reading from a stream. e.g.

Signal.trap:)TERM) { puts 'TERM'; exit }
while true
p $stdin.gets
end

This program does not exit until $stdin.gets returns. Pure ruby signal
handlers are not executed, because calling ruby code from signal handler
is dangerous."

The summary described some of the problems that must be overcome in order
to deal with this. "We need a safe and portable solution for this
problem."

Also covered was "Proc generation without `proc', an experimental patch by
Nobu which lets you write

x = {|a| p a } # == proc {|a| p a }
x.call

x = (do |a| p a end) # == proc do |a| p a end
x.call

[DIY "matrix" screensaver! try: ruby -rtracer -rsocket -enil]
-------------------------------------------------------------

Sam Roberts found a bug which caused Ruby to print out something that
reminded him of the Matrix output. This inspired some programs that look
even more like the Matrix, including the following by Jannis Harder:

puts"\e[2J\e[0;11r";$>.sync=m="\e[C";c='/,-=<>*+.:&%$'.split'';k=[!1]*25
z=",rekcah ybuR rehtona tsuJ".reverse;while k.index(!1);i=-1;print"\eM"*
7,"\e[H",k.map{|q|q ?" ":c[rand(13)]},"\e[6H",k.map{|q|u=z[i+=1,1];q ?u:
m},"\n",k.map{|q|q ?" ":m};k[rand(25)]=sleep 0.1;end;puts"\e[2J\e[r"+z#J

[Parsers vs. Homemade "Parsing" via REs]
----------------------------------------

Randy Kramer wanted to convert some TWiki marked-up text into HTML. He had
the (correct) impression that many or most wikis, including twiki, used
multiple regular expressions for interpreting markup, rather than using a
"real" parser. What are the tradeoffs between these two options, which is
faster and what is a good parsing library for Ruby?

Austin Ziegler explained that the "biggest problem with regexen is not
speed -- they're FAST. The biggest problem is interaction of regexen.
Ruwiki solves this, in part, by adding priorities to token." Nikolai
Weibull added "The place for regular expressions are not in describing
grammars, but tokens" and thought RACC was the right library to be using.

why the lucky stiff said that he actually prefers writing parsers in C,
using a combination of Bison and Re2c.

"I hope no one is using RedCloth's parser as an example. It's awful. It's
like when Ron Popeil injects garlic into a turkey using that freaky flavor
syringe and you're like, "Grrrosss, he killed the turkey, polished it up
and forced it to be a junkie." RedCloth is all the regexps from
textile.php and markdown.pl forced into a hot, enclosed area --

It's a breeding ground for moth and ringworm. I have two evil Bad Luke
hands afterwards, which first try to strangle me and, failing that, then
go after people on the street with Ron Popeil's patented rib cage shears."

[Erb: terminating a script?]
----------------------------

Lloyd Zusman had an erb web page and wanted to be able to end processing
part way through the script, similarly to the PHP technique of <?php exit;
?>.

The equivalent erb solution, <% exit %> terminates the entire web
application.

Lloyd later posted his own solution, which modifies erb by placing a
lambda around the eval call in the ERB class. This allows break or return
to be used to finish processing.

[How to print an array with at most 2 digits for float?]
--------------------------------------------------------

mepython had floats like 84.9535929148379, but wanted to print them to two
decimal places. Robert Klemme gave a solution using sprintf. You can use
sprintf("%.2f", a) to get a string containing a representation of the
float a, restricted to two decimal places.

[Phone Typing (#21)]
--------------------

James Edward Gray II summarised last week's [Ruby Quiz] - to develop a
better algorithm for typing text messages on cellphones. (Reducing the
number of keys that must be pressed.)

One of the issues it discusses is using 'optparse' for parsing
command-line arguments.

[optparse: on() vs on_tail()]
-----------------------------

On that topic, James spun off another thread wondering what the difference
bewteen on() and on_tail() is in 'optparse'.

Thomas Kirchner responded: "on_head is useful for general, common options
that most everyone needs, so that they appear first. on() adds everything
to the middle in order. on_tail is good for generic options like --help or
--version that aren't vital, but should be there. Or at least that's how I
use it :)"

[Soks rocks (but now need "deep" search capability)]
----------------------------------------------------

Bil Kleb wrote "Some folks from our newly-formed "Innovation Institute"
scheduled a meeting to talk with me and my officemate, Bill Wood, about
"what we were doing" and if any of it could be incorporated into their
world." (Bil works at NASA.)

It turned out that they had been having problems with getting a "knowledge
management system" up and running. "They said all they wanted was
"unfettered add, search, upload, and open discussion"."

After the meeting, Bil decided to setup the Soks wiki implementatation,
"and I'll be damned if not within 4 hours I had there entire site humming
on Soks -- If they would have hired me for the original job, I could have
absconded with $75k/hr!" The director was very pleased with this, but
added that they wanted "full text search" - to be able to search inside
Word, Powerpoint and PDF documents. How would Bil add this feature?

Dave Burt said that Win32OLE could be used to extract data from Word and
Powerpoint in order to update search indices. Martin DeMello thought it
would be best to use an existing full-text search engine like [webglimpse]
or [lucene].

[Arrays - create, filtering and returning]
------------------------------------------

Yannick Turgeon was learning Ruby and had some questions about filtering
Arrays.

Say I want to create an array of all pair numbers from 2 to 100, do I
have to write:

a = []
2.step(100, 2){|v| a.push(v)}

is there a way I could do in one single line:
a = ...

...

2- From this newly created array, if I want to extract only those numbers
mutiple of 5 (10,20, ...), are you coding something like:

b = a.collect{|v| v.modulo(5) == 0 ? v : nil}.compact

It seems like a miss a function here which should be called something like
"extract" or "find_all".

Assaph Mehr answered

a = (2..100).select { |n| n%2 == 0 }
b = a.find_all { |n| n%5 == 0 }

"Usually if you think of a method name it's already in there, and does
what you expect :)"

(Note: select and find_all do exactly the same thing, they are just two
different names for the same method. Which one you use depends on which
"sounds better" in the context you're using it.)

[Anyone writing Ruby scripts for Slony-1?]
------------------------------------------

Alan Garrison asked if anyone had Ruby scripts for [Slony], "an
asynchronous replication+failover package for PostgreSQL". It currently
comes with some Perl scripts. A couple of people were interested in
developing some Ruby tools around this.

[Windows automation]
--------------------

Martin Kahlert wanted to "automate" a Windows GUI application by
manipulating fields and buttons from Ruby. Dave Burt suggested using
Ruby/DL to call Windows API functions like SendMessage().

Paul pointed out [win32-guitest] and daz described [AutoIt]. AutoIt
provides a COM interface for controlling Windows applications that Ruby
can access using Win32OLE.

[Seeking advice on rb_secure and other sandboxy stuff]
------------------------------------------------------

Daniel Berger noticed that rb_secure() and rb_tainted_string_new() are
often used in C extensions for Ruby. He wanted to know when these should
be used, and why pure Ruby code very rarely deals with these issues.

Florian Gross explained that string "tainting" is used when data comes
from an external, untrusted source. (Such as an environment variable or
web query string.) Tainting is used to remind developers to filter the
string before passing it to "dangerous" functions like system() which pose
a security risk if arbitrary user data can be used with them.

Note that tainting can be used on arbitrary objects, not just strings.

[mod_ruby & rails doc?]
-----------------------

Aquila wanted information on using mod_ruby with Rails. Jeffrey Dik
pointed to some examples, and David Heinemeier Hansson suggested using
FCGI instead:

"mod_ruby uses one interpreter per Apache process, which means that apps
walk all over each other in the namespaces. At least for Rails, that's not
acceptable, so it's 1 app per Apache setup if you want mod_ruby.

FCGI is a much better setup for Rails. You don't fill up a ton of Apache
processes with your app (so apache processes serving static files and
images stay small) and you can have as many apps per apache setup as you'd
like.

I've found FCGI to be 10-15% faster in my tests with Rails."

[indent.rb <- does such a beast exist?]
---------------------------------------

Ben Giddings asked for a standalone Ruby application or library to indent
Ruby code. It wasn't in Ruby, but Ryan Phillips gave a solution using the
vim editor: vim -c "normal ggVG=" test.rb.

[RAA Status & The Problem with Ruby]
------------------------------------

Curt Hibbs re-posted a blog entry by "Sean" which issues a couple of
criticisms of Ruby - "Libraries are in an awful state. It appears nearly
half of them are abandoned." Sean also thought library documentation
wasn't good enough.

"These two problems are serious enough that I'd suggest that Matz and
community establish specific standards for denoting how libraries are
packaged, documented, and version dependencies (with third party product,
C libraries, other Ruby libraries, etc.) are designated. I'd also suggest
that RAA come up with a mechanism for denoting abandoned libraries vs.
ones that simply don't need to be ugpraded. Maybe an auto-email once a
quarter to the developer?"

Curt reiterated Sean's point with "What is really bad about this is that
many of the libs that are current are *way* better than your average
library, and a few are simply *brilliant*. Many people (especially
newcomers) don't know this because this brilliance of drowned out in a sea
of dead-ends."

The [Ruby Production Archive] (RPA) was discussed. This is a "controlled
repository of Ruby libraries and applications, managed by a dedicated team
that will ensure consistency and proper QA". The differences between RPA
and RubyGems were covered.

Other thoughts revolved around improving the [Ruby Application Archive]
(RAA), for example, by adding a ranking system with one-to-five stars. Tom
Copeland said that [RubyForge] has an "activity percentile" rating
(borrowed from [sourceforge]), but it is difficult to understand.

James Britt: "I get the sense that this blogger's opinion was based
entirely on what he saw at the RAA. RAA has pretty much fallen off my
radar; If I'm looking for a Ruby app or lib I turn to RubyForge or Google.
The RAA has tended to be too incomplete or out-of-date."

Richard Kilmer responded with "The RubyForge team has always viewed RAA as
THE project metadata repository for the Ruby community." "Our idea was to
have RubyForge projects auto-populate the RAA as those projects release
files, edit their metadata, etc. Its an integration effort that we have
not had the time to do yet, that's all."

Matz weighed in: "I think there's need for both a packaging "system" and a
package repository. I wish for a sound cooperation of the former
(rubygems?) and the latter (rpa?). I'd happy to merge the packaging system
(with which both teams can agree) in the standard Ruby."

"Improving RAA is another story. Maybe we should add it a few more
features, such as

* rating system
* dead link check
* accepting update information from anyone (pages will be updated after
the moderator check)"

[License of the Ruby user's guide ?]
------------------------------------

We reported on this thread last week - the Ruby User's Guide had been
translated to French and the programmers behind [RubyFR.org] wanted to get
permission for the translation. Matz asked if the CC-BY license would be
okay. (CC-BY is the Creative Commons [Attribution License]. It gives
freedom to modify, distribute, use for commercial purposes etc. so long as
the original author is given credit.)

Jean-Denis Vauguet said that this would work very well, and added "oh, and
I would like to thank Tim for quoting my twice in his Ruby Weekly News ;)
("quote of the week", is there any greater honour for a noob?)". That's
three times now and counting :)

[pugs]
------

Martin DeMello introduced [Pugs], a project to implement the Perl6 spec in
Haskell.

"The ultimate aim is to bootstrap a self-hosting perl6 implementation" -
i.e. to allow Perl developers to implement Perl6 in Perl6.

[A wish: Simple database]
-------------------------

Hal Fulton wrote "I sometimes wish for a very simple database with the
following features:"

1. Distributed as part of Ruby
2. Can work without storing entire database in memory
3. Available cross-platform
4. Database files are readable cross-platform

Hal doesn't care if the database uses SQL or not, or if the library is
especially efficient. He usually uses DBM, but it fails (3) and (4).
Marshal violates (2). There were many suggestions from the group,
including several that satisfied (2), (3) and (4):

* [KirbyBase]. It keeps data in plain-text, delimited files. (Suggested
and written by Jamey Cribbs.)

* [sqlite]. (Suggested by James Britt.)

* [FSDB]. From the RAA description, "FSDB is a file system data base.
FSDB provides a thread-safe, process-safe Database class which uses
the native file system as its back end and allows multiple file
formats and serialization methods. Users access objects in terms of
their paths relative to the base directory of the database."
(Suggested by Michael Neumann.)

Hal Fulton followed up with "Matz: Can we put some kind of standardized
trivial database in the Ruby distribution? If so, what should it be?"

[Roman Numerals (#22)]
----------------------

James Edward Gray II dealt out the latest [Ruby Quiz]. "This week's quiz
is to write a converter to and from Roman numerals."

New Releases
------------

* [YARV - Yet Another RubyVM 0.2.0]

SASADA Koichi released the latest work on his Ruby virtual
machine. New features include an assembler and architecture
documentation (in Japanese). This project is supported by IPA
(Information-technology Promotion Agency, Japan) "Exploratory
Software Project (youth)".

* [Amrita2 1.9.2 and reverse engineering]

Taku Nakajima updated Amrita2, an XML/XHTML templating library. It
includes a "reverse spec generation" feature, which turns a static
HTML file into a Ruby script, using templates.

* [using PHP sessions in Ruby]

Raphael Bauduin released the first version of a library that
allows you to use PHP sessions in Ruby web applications, including
accessing and modifying strings, arrays and hashes from PHP.

* [ruby-breakpoint 0.5.0]

Florian Gross re-packaged ruby-breakpoint into a separate library
(previously, it was only available as part of Rails).
ruby-breakpoint provides remote debugging capabilities allowing,
for example, a developer to connect to a running web application,
inspect its state and change the code.

* [Brrain, another Brainf*** interpreter]

Bertram Scharpf wrote a Ruby interpreter for the Brainf***
language. "Brainf*** is a programming language consisting of eight
instructions and yielding weird pieces of code even when doing
simple things." In response, Florian Gross wrote his own
interpreter, with some differences including infinite memory in
both directions.

* [Orbjson, a JSON-RPC ORB for JavaScript/Ruby interaction]

James Britt released the first version of an ORB (Object Request
Broker) for communicating between Ruby and Javascript (using
JSON-RPC).

* [deplate 0.7.1]

Thomas released deplate, a tool for converting a wiki-like markup
format into LaTeX, HTML, HTML slides or DocBook.

* [DataVision 0.9.0 released]

Jim Menard unleashed a new version of DataVision, a Java-based
reporting tool which can be controlled using the Bean Scripting
Framework, for example from JRuby.

* [RubyGems 0.8.6]

Chad Fowler posted a quick followup to last week's release of
RubyGems 0.8.5, fixing a small but potentially inconvenient bug.

* [Scratch 1.0]

Scott Barron announced a new application he'd developed in Rails.
It is a web log system, but probably not what you'd expect -
instead of producing web pages, it only provides Atom and RSS
feeds.

* [Ruby API for Yahoo Search Web Services]

Premshree Pillai wrote a Ruby API for the Yahoo! web service. "Not
very elegant and all. Prolly someone else could come up with
something nice." NAKAMURA, Hiroshi posted a much shorter
proof-of-concept that uses the SOAP library to simplify things.

* [RVG moves to beta with 0.4.0]

Tim Hunter posted the first beta of RVG, a 2D graphics API based
on SVG. RVG is written in pure-Ruby, and requires RMagick. Text
rendering has been significantly enhanced in this release.

* [Nitro + Og 0.11.0]

George Moschovitis released new versions of Nitro and Og. Nitro is
a web application framework, and Og is an object-relational
mapper. Apache and Oracle are now supported out of the box, Og
comes with documentation and many other improvements were made.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,056
Messages
2,570,443
Members
47,089
Latest member
Bobby2025b

Latest Threads

Top