David A. Black | 1 Dec 2005 01:03

Re: Help constructing interesting hash?

Hi --

On Thu, 1 Dec 2005, Chris McMahon wrote:

> Suppose I have an array of arrays like
>
> [[A, B, C][1,2,3]]
>
> I can easily make a hash (using each_with_index) where one value is
> the lookup value for the other value:
>
> 1=>A
> 2=>B
> 3=>C
>
> Now suppose I have a AoA like
>
> [[A, B, C,][1,2,2]]
>
> Is there a readable way to construct a hash like
>
> 1=>[A]
> 2=>[B, C]

Here's an inject-based way:

   a.zip(b).inject({}) do |hash,(key,value)|
     (hash[value] ||= []) << key
     hash
   end
(Continue reading)

Dave Howell | 1 Dec 2005 01:02

Re: [BUG] string range membership

English speaker.

Relative new Ruby user.

My thoughts: forget it! Stop! Ahhhh! Kitchen sink!

Let's see if I've got this straight. Somebody complained because

	('1'..'10').member?('2')
	=> false

Good! The fact that Ruby will get incredibly clever with strings and 
fabricate arbitrary sequences with them is a charming trick, but they 
are arbitrary, and it is a trick.

The fact that '1', '2', ... '9','10'  is obvious doesn't make it any 
less arbitrary.

	'1'..'100'

Is that supposed to be 1, 2, 3, ... 99, 100 or 1, 10, 11, 100? Ruby 
arbitrarily decided to interpret those strings as base 10 integers.

	'a.1'..'c.3'

Quite honestly, I have absolutely no idea how Ruby would count that. 
Will I get 'a.1', 'a.2', 'a.3', 'b.1' ... or is it going to go all the 
way to 'a.9' and then start over with 'b.1'?

Ruby does NOT need more almost-but-not-quite-the-same methods! People 
(Continue reading)

Austin Ziegler | 1 Dec 2005 01:06
Picon
Gravatar

Re: Splitting a text file into sentences

On 11/30/05, Gavin Sinclair <gsinclair <at> gmail.com> wrote:
> Austin Ziegler wrote:
>>> Not true at all.  I was always taught to use double spaces after
>>> sentences in grade-school homework assignments done on plain word
>>> processors or typewriters.
>> Then, quite honestly, you were taught wrong. I was taught to use
>> double spaces with a typewriter or when using fixed-pitch fonts
>> (although that was later, since most computers and printers didn't
>> have reliable kerning routines until I was out of university).
>> Ultimately, the use of double spaces after a period is wrong *even
>> with fixed-pitch fonts*, but it was done to be clearer since the
>> width of the em-space and an en-space on a typewriter with a
>> Courier-like font is exactly the same. The two spaces *simulates* an
>> em-space in a typeset piece of work. (And that is *fact*, not
>> opinion.)
> What rot.  How can anything like that be a fact?  You're regurgitating
> the opinion of a style manual.

Um. No, I'm stating fact. This isn't mere opinion: two spaces were done
to simulate em-spaces in fixed pitch environments. That's a fact. The
reason for that may often be forgotten, but it *remains* a fact. Please
remember that I've done quite a bit of typesetting-style work in the
last year with PDF::Writer and I have to know a bit more about this than
most folks, and it's something of a hobby of mine in any case to know
about printing mechanisms.

The only *opinion* I stated was that the first poster in the chain above
(I think Jeffrey) was taught wrongly. I maintain that as true
regardless, because if he was taught two spaces without the reason why,
then there's a practice being repeated for no good reason.
(Continue reading)

Shot - Piotr Szotkowski | 1 Dec 2005 01:07
Picon

Re: Splitting a text file into sentences

Hello.

Dave Howell:

> For improved legibility, inter-sentence space should
> generally be a bit greater than inter-word space.

It's worth noting that actually turning this theory into reality seems
to apply to 'Western' (American, British, others?) typography (mostly?
only?).

I've yet to see a typical modern Polish book typeset with greater
inter-sentence spaces. Also (and, I guess, as a result of this),
I doubt I ever saw any Polish email or Usenet post with two
inter-sentence spaces, and I remember how happy I was to find
out about the 'joinspaces' vim option that finally let me reflow
paraghaprs properly, without doing a s/  / /g on them afterwards. :o)

Cheers,
-- Shot
--

-- 
        He has never been known to use a word that might send a reader
        to the dictionary.     -- William Faulkner on Ernest Hemingway
====================== http://shot.pl/hovercraft/ === http://shot.pl/1/125/ ===
Dave Burt | 1 Dec 2005 01:12
Picon

Re: Ruby, MySQL on WinXP?

> planetthoughtful wrote:
>> Hello All,
>>
>> I'm just starting out learning Ruby, having come from a PHP background.
>>
>> I've downloaded the latest stable Ruby release, and have also used the
>> GEM package manager to install Rails, but I'm a little confused about
>> how I connect Ruby to MySQL?
>>
>> The only references I can find to a Ruby driver for MySQL call for
>> compiling, and I (and many other WinXP users, I imagine) don't have a
>> copy of Visual C++ with which to do that.
>>
>> Is there no official supported driver for connecting Ruby to MySQL
>> under Windows?

You're right there's no "official supported driver".

James Britt offered:
> There is a pure-Ruby MySQL driver.
> http://raa.ruby-lang.org/project/ruby-mysql/
> might be it.

That is indeed the pure-Ruby MySQL driver. I think I've heard it doesn't 
work with MySQL 5.

There are two other ways to connect to MySQL. One is to use the MySQL ODBC 
driver (available from mysql.com) along with Ruby-DBI.

Another involves compiling MySQL, or at least finding a pre-compiled binary 
(Continue reading)

Dave Howell | 1 Dec 2005 01:36

Re: Splitting a text file into sentences


On Nov 30, 2005, at 15:35, Matthew Smillie wrote:

> On Nov 30, 2005, at 22:02, Dave Howell wrote:
>
>> you can solve all "Mr./Dr./Ph.D." cases by the fact that if a word 
>> starts with a cap and ends with a period, it's not a sentence.
>
> I'm not sure that's a very good rule, Dave. There are two sentences 
> here.
>
> The above rule may catch titular abbreviations, but over-generalises 
> to produce a false negative in the above example.

I hadn't intended to provide a single magical rule that was perfect in 
isolation, after all. {chuckle}

"Ph. D." is not a sentence. But where do you break
	My name is Dave, Ph. D. Pleased to meet you.
vs.
	You need my Ph. D. friend Dave to help you.

I don't think having a list of abbreviations and titles will improve 
that situation much, although it's a lot more work and almost certain 
to be incomplete. Any/every rule will have failures; avoiding them is 
what takes you into that whole natural language high-octane engine 
situation.

However, if you also use the *other* "rule" I mentioned, then you don't 
have a problem. "Dave Howell" appears just a couple lines earlier, 
(Continue reading)

Daniel Sheppard | 1 Dec 2005 01:37
Picon
Favicon

Re: Point an element in Hash Object

I thought something like this was in facets... maybe it was one of those
other library collections... either way I can't find what I'm looking
for, so here's an implementation which probably screws up with some
corner cases.

class Reference
    instance_methods.each { |m| undef_method m unless /__.*__/ === m}
    def initialize(&block)
         <at> block = block
    end 
    def method_missing(*args, &block)
         <at> block.call.send(*args, &block)
    end
end

my_hash = {}
my_hash["one"] = "First"
my_hash["two"] = "Second"
my_hash["three"] = "Third"
my_hash["four"] = Reference.new{my_hash["one"]}
my_hash["five"] = Reference.new{my_hash["four"]}

my_hash["one"] = "Modify"
p my_hash["four"]
=> "Modify"
p my_hash["five"]
=> "Modify"

> -----Original Message-----
> From: list-bounce <at> example.com 
(Continue reading)

Srinivas Jonnalagadda | 1 Dec 2005 01:45

Re: If like smalltalk

An interesting difference, though, is that the Smalltalk version 
utilizes the language's capability to accept multiple blocks in a method 
call -- 'ifTrue: [ ... ] ifFalse: [ ... ]'.  In the Ruby version given, 
it needs to have a (may be) hack to return the value of the original 
condition, from the 'if' block.

JS

Austin Ziegler wrote:
> On 11/30/05, Jules Jacobs <julesjacobs <at> gmail.com> wrote:
> 
>>Hi, I have a question about Ruby if constructs. Why aren't they like
>>smalltalk if's, where you have a boolean class and two subclasses: true
>>and false. They both have these methods: ifTrue and ifFalse. If you use
>>a block with a ifTrue on a True object, it will be yielded. If you use
>>it on a false object, nothing will happen.
> 
> 
> They aren't like Smalltalk ifs because Ruby isn't Smalltalk. That
> said, people have been able to make things that work remarkably
> similar to the Smalltalk stuff. Do a search in the archives and you
> should find it.
> 
> -austin
> --
> Austin Ziegler * halostatue <at> gmail.com
>                * Alternate: austin <at> halostatue.ca
> 

(Continue reading)

AlexG | 1 Dec 2005 01:47
Picon
Picon
Favicon

Re: WWW::Mechanize with frames

Thanks for the reply. I tried to follow the links to the separate
frames but I end up back where I started, so I'm thinking there is
something more complicated going on at the server-end, perhaps do with
the PHPSESSID? I'm using Net::HTTP rather than WWW::Mechanize to try to
see what's going on more clearly. I first ask for this page:

www.brenda.uni-koeln.de/php/result_flat.php4?ecno=1.1.1.1

If I load this on the browser it returns a page with three frames one
of which contains the info I want. In the script it returns this HTML:

<html>
<head>
<title>
BRENDA: Entry of alcohol dehydrogenase(EC-Number 1.1.1.1 )
</title>
</head>
<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Frameset//EN\"
\"http://www.w3.org/TR/html4/frameset.dtd\">
<frameset cols="190,*" border="0">
<frame name="navigation"
src="flat_navigation.php4ecno=1.1.1.1&PHPSESSID=9643cd58a9774b07c768c97eeb4ef257"
frameborder="no">
<frameset rows="110,*" border="0">
<frame name="header"
src="flat_head.php4ecno=1.1.1.1&organism=&PHPSESSID=9643cd58a9774b07c768c97eeb4ef257"
frameborder="no">
<frame name="flat"
src="flat_result.php4?ecno=1.1.1.1&organism%5B%5D=&PHPSESSID=9643cd58a9774b07c768c97eeb4ef257"
frameborder="no">
(Continue reading)

Gavin Sinclair | 1 Dec 2005 01:52
Picon
Gravatar

Re: Splitting a text file into sentences


Austin Ziegler wrote:
> On 11/30/05, Gavin Sinclair <gsinclair <at> gmail.com> wrote:
> >> [...] The two spaces *simulates* an
> >> em-space in a typeset piece of work. (And that is *fact*, not
> >> opinion.)
>
> > What rot.  How can anything like that be a fact?  You're regurgitating
> > the opinion of a style manual.
>
> Um. No, I'm stating fact. This isn't mere opinion: two spaces were done
> to simulate em-spaces in fixed pitch environments. That's a fact.  [...]

Fair enough.

Gavin


Gmane