[#267026] attr_reader — 7stud 7stud <dolgun@...>

On p. 30-31 of "Programming Ruby (2nd ed)", there is this example:

15 messages 2007/09/01

[#267065] Seeing the source — Michel Cabili <michel.cabili@...>

Hello. I'm new to Ruby (and also to scripting languages).

38 messages 2007/09/01

[#267086] Help with leap year programing — HB <hbqian@...>

Hi, All,

19 messages 2007/09/01

[#267106] Singleton Modules rather than Singleton Classes — Trans <transfire@...>

This recently came up in the thread entitled "Python-style

14 messages 2007/09/01

[#267113] Parsing query parameters from hyperlink — "lrlebron@..." <lrlebron@...>

I am trying to parse strings like this

11 messages 2007/09/01
[#267128] Re: Parsing query parameters from hyperlink — Robert Klemme <shortcutter@...> 2007/09/01

On 01.09.2007 19:34, lrlebron@gmail.com wrote:

[#267184] How does ruby handle overloading? — pongba <pongba@...>

Matz once replied on Cedric's blog that

13 messages 2007/09/02

[#267261] subject line — "Devi Web Development" <devi.webmaster@...>

I don't know who would make this sort of decision, but could we put

103 messages 2007/09/02
[#267397] Re: subject line — Trans <transfire@...> 2007/09/03

[#267633] Re: subject line — Chad Perrin <perrin@...> 2007/09/04

On Tue, Sep 04, 2007 at 04:01:56AM +0900, Trans wrote:

[#267655] Re: subject line — Trans <transfire@...> 2007/09/04

[#267656] Re: subject line — Chad Perrin <perrin@...> 2007/09/04

On Wed, Sep 05, 2007 at 08:54:22AM +0900, Trans wrote:

[#267665] Re: subject line — "Rimantas Liubertas" <rimantas@...> 2007/09/05

> Any time you tell someone to completely change the tools (s)he uses,

[#267744] Re: subject line — Chad Perrin <perrin@...> 2007/09/05

On Wed, Sep 05, 2007 at 10:12:53AM +0900, Rimantas Liubertas wrote:

[#267266] Re: subject line — Dan Zwell <dzwell@...> 2007/09/02

Devi Web Development wrote:

[#267481] Re: subject line — Bil Kleb <Bil.Kleb@...> 2007/09/04

Chad Perrin wrote:

[#267506] Re: subject line — John Joyce <dangerwillrobinsondanger@...> 2007/09/04

Respectfully, no, unless it's very short. I suggest sort by the To:

[#267510] Re: subject line — "Robert Klemme" <shortcutter@...> 2007/09/04

I vote against, basically because I believe the issue can be solved

[#267514] Re: subject line — "Peter Cooper" <peter@...> 2007/09/04

I vote against. Those with the firehose of ruby-talk gushing into their

[#267282] assigning to hash keys when there is a default value? — 7stud -- <dolgun@...>

Can someone explain why there is a difference in the second line of

41 messages 2007/09/03
[#267283] Re: assigning to hash keys when there is a default value? — dblack@... 2007/09/03

Hi --

[#267286] Re: assigning to hash keys when there is a default value? — 7stud -- <dolgun@...> 2007/09/03

unknown wrote:

[#267310] Re: assigning to hash keys when there is a default value? — Peña, Botp <botp@...> 2007/09/03

From: 7stud -- [mailto:dolgun@excite.com]

[#267330] Re: assigning to hash keys when there is a default value? — 7stud -- <dolgun@...> 2007/09/03

Pe単a, Botp wrote:

[#267335] Re: assigning to hash keys when there is a default value? — "Russell Norris" <rsl@...> 2007/09/03

I don't think this is a bug, kittens. since h[2] returns a value [eventhough it's not set], it causes h[2] to evaluate so the assignmentnever happens. x ||= y just means give me x or set x to y if there'sno value for x. h[2] _does_ have a value if only a default one.

[#267338] Re: assigning to hash keys when there is a default value? — dblack@... 2007/09/03

Hi --

[#267344] Re: assigning to hash keys when there is a default value? — "Russell Norris" <rsl@...> 2007/09/03

I learned that x ||= y means set x to y unless x, so I don't see the

[#267431] Re: assigning to hash keys when there is a default value? — Peña, Botp <botp@...> 2007/09/04

From: sconds@gmail.com [mailto:sconds@gmail.com] On Behalf Of Russell Norris:

[#267511] Re: assigning to hash keys when there is a default value? — "Robert Klemme" <shortcutter@...> 2007/09/04

2007/9/4, Pe, Botp <botp@delmonte-phil.com>:

[#267325] Re: assigning to hash keys when there is a default value? — "Robert Klemme" <shortcutter@...> 2007/09/03

2007/9/3, dblack@wobblini.net <dblack@wobblini.net>:

[#267318] Filling individual cells in a grid — Joop Van den tillaart <tillaart36@...>

Hi guys,

32 messages 2007/09/03
[#267326] Re: Filling individual cells in a grid — "Todd Benson" <caduceass@...> 2007/09/03

On 9/3/07, Joop Van den tillaart <tillaart36@hotmail.com> wrote:

[#267329] Re: Filling individual cells in a grid — Joop Van den tillaart <tillaart36@...> 2007/09/03

> With your current code...

[#267341] Re: Filling individual cells in a grid — Joop Van den tillaart <tillaart36@...> 2007/09/03

Is there no one else who can help me out a bit?

[#267348] Re: Filling individual cells in a grid — Morton Goldberg <m_goldberg@...> 2007/09/03

On Sep 3, 2007, at 8:40 AM, Joop Van den tillaart wrote:

[#267363] Re: Filling individual cells in a grid — Joop Van den tillaart <tillaart36@...> 2007/09/03

Wow, thanks for your help...

[#267868] Re: Filling individual cells in a grid — Joop Van den tillaart <tillaart36@...> 2007/09/06

Joop Van den tillaart wrote:

[#267885] Re: Filling individual cells in a grid — Morton Goldberg <m_goldberg@...> 2007/09/06

On Sep 6, 2007, at 7:44 AM, Joop Van den tillaart wrote:

[#267899] Re: Filling individual cells in a grid — Joop Van den tillaart <tillaart36@...> 2007/09/06

hi thanks for your help,

[#267964] Re: Filling individual cells in a grid — Morton Goldberg <m_goldberg@...> 2007/09/06

On Sep 6, 2007, at 11:38 AM, Joop Van den tillaart wrote:

[#267984] Re: Filling individual cells in a grid — Morton Goldberg <m_goldberg@...> 2007/09/06

On Sep 6, 2007, at 4:47 PM, Morton Goldberg wrote:

[#268074] Re: Filling individual cells in a grid — Joop Van den tillaart <tillaart36@...> 2007/09/07

Morton Goldberg wrote:

[#268630] Re: Filling individual cells in a grid — Joop Van den tillaart <tillaart36@...> 2007/09/11

Hi guys,

[#268645] Re: Filling individual cells in a grid — Morton Goldberg <m_goldberg@...> 2007/09/11

[#268647] Re: Filling individual cells in a grid — Joop Van den tillaart <tillaart36@...> 2007/09/11

Morton Goldberg wrote:

[#268677] Re: Filling individual cells in a grid — Morton Goldberg <m_goldberg@...> 2007/09/11

On Sep 11, 2007, at 7:57 AM, Joop Van den tillaart wrote:

[#268695] Re: Filling individual cells in a grid — Morton Goldberg <m_goldberg@...> 2007/09/11

On Sep 11, 2007, at 2:03 PM, Morton Goldberg wrote:

[#268705] Re: Filling individual cells in a grid — Morton Goldberg <m_goldberg@...> 2007/09/11

On Sep 11, 2007, at 4:34 PM, Morton Goldberg wrote:

[#267357] with — Matthias Wächter <matthias@...>

Sorry folks if this was raised already, but google is not very

14 messages 2007/09/03

[#267370] wierd floating point output — Matthias Wächter <matthias@...>

Folks,

14 messages 2007/09/03
[#267371] Re: wierd floating point output — dblack@... 2007/09/03

Hi --

[#267373] Re: wierd floating point output — Matthias Wächter <matthias@...> 2007/09/03

On 03.09.2007 19:51, dblack@wobblini.net wrote:

[#267433] Programming Ruby For Newbies — Jin Dynasty <jin.the.miner@...>

Howdy there,

25 messages 2007/09/04

[#267457] Ruby is much slower on linux when compiled with --enable-pthread? — "Adam Kramer" <akramer@...>

Hi,

18 messages 2007/09/04

[#267469] Best IDE for ruby and rails development — AJay Maurya <amaurya@...>

36 messages 2007/09/04
[#267471] Re: Best IDE for ruby and rails development — "Thomas Preymesser" <thopre@...> 2007/09/04

On 04/09/07, AJay Maurya <amaurya@brickred.com> wrote:

[#267476] Re: Best IDE for ruby and rails development — Arthur Murauskas <arthur.murauskas@...> 2007/09/04

On Tuesday 04 September 2007 10:31:23 AJay Maurya wrote:

[#267569] running ruby — yahdoco <yahdoco@...>

Hi Everyone...I am a very new ruby user. I have downloaded ruby to my

28 messages 2007/09/04
[#267574] Re: running ruby — Konrad Meyer <konrad@...> 2007/09/04

On Tuesday 04 September 2007 11:20:05 am yahdoco wrote:

[#267594] Re: running ruby — yahdoco <yahdoco@...> 2007/09/04

I sill have the same two problems:

[#267573] Embedded vs. Non-embedded Tests — Trans <transfire@...>

As far as I know, Facets is the only large project that uses embedded

14 messages 2007/09/04
[#267579] Re: Embedded vs. Non-embedded Tests — "Rick DeNatale" <rick.denatale@...> 2007/09/04

On 9/4/07, Trans <transfire@gmail.com> wrote:

[#267723] Multiple Assignments: Newbie question — "Z T" <zoater@...>

When I run my program:

15 messages 2007/09/05

[#267783] before, after and around Ruby 1.9 — Trans <transfire@...>

Any chance Ruby 1.9 will have before, after and around method

40 messages 2007/09/05
[#267816] Re: before, after and around Ruby 1.9 — Yukihiro Matsumoto <matz@...> 2007/09/05

Hi,

[#267825] Re: before, after and around Ruby 1.9 — Joel VanderWerf <vjoel@...> 2007/09/06

Yukihiro Matsumoto wrote:

[#267797] question on bottleneck of ruby — Roger Pack <rogerpack2005@...>

Question: if I made the statement "Ruby is slower than some other

26 messages 2007/09/05
[#267807] Re: question on bottleneck of ruby — khaines@... 2007/09/05

On Thu, 6 Sep 2007, Roger Pack wrote:

[#271288] Re: question on bottleneck of ruby — Roger Pack <rogerpack2005@...> 2007/09/27

Thanks Kirk.

[#271298] Re: question on bottleneck of ruby — "Francis Cianfrocca" <garbagecat10@...> 2007/09/27

On 9/27/07, Roger Pack <rogerpack2005@gmail.com> wrote:

[#267857] Symbols and frozen strings — Brian Candler <B.Candler@...>

I just had a thought.

13 messages 2007/09/06

[#267871] Count and Say (#138) — Ruby Quiz <james@...>

The three rules of Ruby Quiz:

21 messages 2007/09/06

[#267941] Is this a bug or a feature? — Martin Jansson <martialis@...>

irb(main):002:0> i=1

13 messages 2007/09/06

[#268006] help me condence my code? — "Simon Schuster" <significants@...>

I know this could be more idiomatic to ruby.

23 messages 2007/09/07

[#268052] read a specific line from a file — Bulhac Mihai <mihai.bulhac@...>

how can i read only a line from a txt file?

18 messages 2007/09/07

[#268108] Netbeans, Eclipse and ruby! How to...? — "André Cardoso" <thyandrecardoso@...>

well, i should start to say that i'm pretty new to ruby!!

15 messages 2007/09/07

[#268307] Bug in lambda? — kevin cline <kevin.cline@...>

This looks like a pretty serious bug. It seems that lambda-

36 messages 2007/09/09
[#268323] Re: Bug in lambda? — dblack@... 2007/09/09

Hi --

[#268485] Re: Bug in lambda? — "Robert Klemme" <shortcutter@...> 2007/09/10

2007/9/9, dblack@wobblini.net <dblack@wobblini.net>:

[#268316] module_function :func vs. MyModule.func? — 7stud -- <dolgun@...>

The following produce the same output:

16 messages 2007/09/09

[#268362] Hash — Ron Green <rongreen1@...>

What is the purpose of string hash? What would you use it for?

21 messages 2007/09/09

[#268403] What Linux distribution to choose for learning Ruby and Ruby on Rails — "Slavo Furman" <slavof@...>

Hi!

82 messages 2007/09/09
[#268413] Re: What Linux distribution to choose for learning Ruby and Ruby on Rails — "M. Edward (Ed) Borasky" <znmeb@...> 2007/09/09

-----BEGIN PGP SIGNED MESSAGE-----

[#268418] Re: What Linux distribution to choose for learning Ruby and Ruby on Rails — "Slavo Furman" <slavof@...> 2007/09/09

Thanks for all answers... :)

[#268425] Re: What Linux distribution to choose for learning Ruby and Ruby on Rails — "M. Edward (Ed) Borasky" <znmeb@...> 2007/09/10

-----BEGIN PGP SIGNED MESSAGE-----

[#268427] Re: What Linux distribution to choose for learning Ruby and Ruby on Rails — Reid Thompson <reid.thompson@...> 2007/09/10

M. Edward (Ed) Borasky wrote:

[#268439] Re: What Linux distribution to choose for learning Ruby and Ruby on Rails — "M. Edward (Ed) Borasky" <znmeb@...> 2007/09/10

-----BEGIN PGP SIGNED MESSAGE-----

[#268444] Re: What Linux distribution to choose for learning Ruby and Ruby on Rails — Reid Thompson <reid.thompson@...> 2007/09/10

M. Edward (Ed) Borasky wrote:

[#268451] Re: What Linux distribution to choose for learning Ruby and Ruby on Rails — "M. Edward (Ed) Borasky" <znmeb@...> 2007/09/10

-----BEGIN PGP SIGNED MESSAGE-----

[#268545] Re: What Linux distribution to choose for learning Ruby and Ruby on Rails — Ezra Zygmuntowicz <ezmobius@...> 2007/09/10

Hi~

[#268595] Re: What Linux distribution to choose for learning Ruby and Ruby on Rails — "M. Edward (Ed) Borasky" <znmeb@...> 2007/09/11

-----BEGIN PGP SIGNED MESSAGE-----

[#268606] Re: What Linux distribution to choose for learning Ruby and Ruby on Rails — Chad Perrin <perrin@...> 2007/09/11

On Tue, Sep 11, 2007 at 12:00:57PM +0900, M. Edward (Ed) Borasky wrote:

[#268611] Re: What Linux distribution to choose for learning Ruby and Ruby on Rails — "M. Edward (Ed) Borasky" <znmeb@...> 2007/09/11

-----BEGIN PGP SIGNED MESSAGE-----

[#268614] Re: What Linux distribution to choose for learning Ruby and Ruby on Rails — bob@... (Bob Proulx) 2007/09/11

M. Edward (Ed) Borasky wrote:

[#268405] Re: What Linux distribution to choose for learning Ruby and Ruby on Rails — Marcin Raczkowski <mailing.mr@...> 2007/09/09

Slavo Furman wrote:

[#268750] Re: What Linux distribution to choose for learning Ruby and Ruby on Rails — hemant <gethemant@...> 2007/09/12

On 9/10/07, Marcin Raczkowski <mailing.mr@gmail.com> wrote:

[#269173] Re: What Linux distribution to choose for learning Ruby and Ruby on Rails — "Shot (Piotr Szotkowski)" <shot@...> 2007/09/15

hemant:

[#269182] Re: What Linux distribution to choose for learning Ruby and Ruby on Rails — "Todd Benson" <caduceass@...> 2007/09/15

On 9/15/07, Shot (Piotr Szotkowski) <shot@hot.pl> wrote:

[#269199] Re: What Linux distribution to choose for learning Ruby and Ruby on Rails — "M. Edward (Ed) Borasky" <znmeb@...> 2007/09/15

Todd Benson wrote:

[#268433] Re: What Linux distribution to choose for learning Ruby and Ruby on Rails — Trans <transfire@...> 2007/09/10

[#268436] Re: What Linux distribution to choose for learning Ruby and Ruby on Rails — "M. Edward (Ed) Borasky" <znmeb@...> 2007/09/10

-----BEGIN PGP SIGNED MESSAGE-----

[#268447] Re: What Linux distribution to choose for learning Ruby and Ruby on Rails — Trans <transfire@...> 2007/09/10

[#268513] Re: What Linux distribution to choose for learning Ruby and Ruby on Rails — Chad Perrin <perrin@...> 2007/09/10

On Mon, Sep 10, 2007 at 12:07:42PM +0900, Trans wrote:

[#268517] Re: What Linux distribution to choose for learning Ruby and Ruby on Rails — Lionel Bouton <lionel-subscription@...> 2007/09/10

Chad Perrin wrote the following on 10.09.2007 18:46 :

[#268539] Re: What Linux distribution to choose for learning Ruby and Ruby on Rails — Chad Perrin <perrin@...> 2007/09/10

On Tue, Sep 11, 2007 at 01:54:42AM +0900, Lionel Bouton wrote:

[#268557] Re: What Linux distribution to choose for learning Ruby and Ruby on Rails — Lionel Bouton <lionel-subscription@...> 2007/09/10

Thanks for the answer, that was an interesting reading. I've some

[#268565] Re: [OT] Re: What Linux distribution to choose for learning Ruby and Ruby on Rails — Chad Perrin <perrin@...> 2007/09/10

On Tue, Sep 11, 2007 at 05:38:32AM +0900, Lionel Bouton wrote:

[#268570] Re: [OT] Re: What Linux distribution to choose for learning Ruby and Ruby on Rails — Chad Perrin <perrin@...> 2007/09/10

On Tue, Sep 11, 2007 at 07:00:50AM +0900, Chad Perrin wrote:

[#268658] undefined method `+' for nil:NilClass (NoMeth — Mahen Surinam <neoanderson12@...>

Dear All,

14 messages 2007/09/11

[#268663] Camping or Merb — "Eduardo Tongson" <propolice@...>

Hi folks,

19 messages 2007/09/11

[#268672] Graphics... why so shrouded in mystery? — Weston Campbell <silvershockwave@...>

I've been working with ruby for quite a while now, and I still don't

13 messages 2007/09/11

[#268761] what is this syntax: \001\002 ? — 7stud -- <dolgun@...>

Hi,

15 messages 2007/09/12

[#268786] copy/paste line numbers with code — Max Williams <toastkid.williams@...>

I'm writing up my project report and want to include line numbers with

12 messages 2007/09/12

[#268802] IronRuby — Lloyd Linklater <lloyd@2live4.com>

I have heard disturbing things about IronRuby. The short version is

36 messages 2007/09/12
[#268828] Re: IronRuby — Greg Donald <greg@...> 2007/09/12

On Thu, 13 Sep 2007, Lloyd Linklater wrote:

[#268833] Re: IronRuby — "Felix Windt" <fwmailinglists@...> 2007/09/12

> -----Original Message-----

[#268911] Re: IronRuby — Charles Oliver Nutter <charles.nutter@...> 2007/09/13

Bill Kelly wrote:

[#268918] Debug — "coolgeng coolgeng" <coolgeng410@...>

With the Rails, I build a project connecting the MySQL. But When I change

17 messages 2007/09/13

[#268970] Cross-platform Home Directory? — Trans <transfire@...>

I have a little app that needs to store session data. I assume the

19 messages 2007/09/13

[#269047] IP to Country (#139) — Ruby Quiz <james@...>

The three rules of Ruby Quiz:

32 messages 2007/09/14

[#269063] How many computers in the house? — Todd Burch <promos@...>

I went to the Lone Star Ruby Conference last week. 7 of us went out to

41 messages 2007/09/14

[#269125] Unicode — Zephyr Pellerin <ztz@...>

I hate to discuss something related to the development timeline, I know

26 messages 2007/09/15
[#270180] Re: Unicode — "Michal Suchanek" <hramrach@...> 2007/09/21

On 15/09/2007, Zephyr Pellerin <ztz@nxvr.org> wrote:

[#269140] one line to print the statement AS WELL AS the evaluated value like in C — kendear <summercoolness@...>

i wonder in Ruby, is there a line method to do something like in C

11 messages 2007/09/15

[#269214] Newbie help — Ali Koubeissi <ali.koubeissi@...>

Hey, I've started with Ruby two days ago, and I have some questions.

19 messages 2007/09/16

[#269251] Ruby Forum > Ruby Talk > comp.lang.ruby ? — Kenneth LL <kenneth.kin.lum@...>

so it seems like Google created Ruby Talk and anything posted to Ruby

25 messages 2007/09/16

[#269315] Newbie: what's Ruby idiom for word-by-word input? — Alex Shulgin <alex.shulgin@...>

Hi,

16 messages 2007/09/16
[#269326] Re: Newbie: what's Ruby idiom for word-by-word input? — Robert Klemme <shortcutter@...> 2007/09/16

On 16.09.2007 21:08, Alex Shulgin wrote:

[#269407] Re: Newbie: what's Ruby idiom for word-by-word input? — Alex Shulgin <alex.shulgin@...> 2007/09/17

On Sep 17, 12:19 am, Robert Klemme <shortcut...@googlemail.com> wrote:

[#269441] Re: Newbie: what's Ruby idiom for word-by-word input? — William James <w_a_x_man@...> 2007/09/17

On Sep 17, 4:30 am, Alex Shulgin <alex.shul...@gmail.com> wrote:

[#269357] Tk Ruby / Fx Ruby / Wx Ruby — "Jayson Williams" <williams.jayson@...>

I have looked at these three GUI's for Ruby, and would like to know

12 messages 2007/09/17

[#269440] group array elements in groups of two — Emmanuel Oga <oga_emmanuel_oga@...>

A better way to do this? :

13 messages 2007/09/17

[#269450] how to use tuple as hash key — SpringFlowers AutumnMoon <summercoolness@...>

in Python, a hash key cannot be [1,2,3] but must be (1,2,3), a tuple.

13 messages 2007/09/17
[#269453] Re: how to use tuple as hash key — Stefano Crocco <stefano.crocco@...> 2007/09/17

Alle luned狸 17 settembre 2007, SpringFlowers AutumnMoon ha scritto:

[#269562] The meaning of a = b in object oriented languages — Summercool <Summercoolness@...>

30 messages 2007/09/18

[#269596] finding string matches, in order, in a file — Peter Bailey <pbailey@...>

Hi,

19 messages 2007/09/18
[#269601] Re: finding string matches, in order, in a file — William James <w_a_x_man@...> 2007/09/18

[#269605] Re: finding string matches, in order, in a file — Peter Bailey <pbailey@...> 2007/09/18

William James wrote:

[#269627] Re: finding string matches, in order, in a file — William James <w_a_x_man@...> 2007/09/18

On Sep 18, 8:28 am, Peter Bailey <pbai...@bna.com> wrote:

[#269631] Re: finding string matches, in order, in a file — Peter Bailey <pbailey@...> 2007/09/18

William James wrote:

[#269637] Re: finding string matches, in order, in a file — William James <w_a_x_man@...> 2007/09/18

On Sep 18, 10:27 am, Peter Bailey <pbai...@bna.com> wrote:

[#269616] CPU Usage not near 100% when running code — SpringFlowers AutumnMoon <summercoolness@...>

I tested some computation intensive Ruby code. When running, the CPU

11 messages 2007/09/18

[#269732] How to print FULL stacktrace of exception w/ line #? — Andrew Chen <meihome@...>

The ruby interpreter prints out a full trace of the exception.

12 messages 2007/09/19

[#269779] how can I remove all the comments in my c program. — Vellingiri Arul <hariharan.spc@...>

Dear Friends,

25 messages 2007/09/19

[#269813] YAML & readlines & modify text files — Dan George <endege@...>

Hello,

16 messages 2007/09/19
[#269834] Re: YAML & readlines & modify text files — Stefano Crocco <stefano.crocco@...> 2007/09/19

Alle mercoled19 settembre 2007, Dan George ha scritto:

[#269879] Re: YAML & readlines & modify text files — Dan George <endege@...> 2007/09/19

On Sep 19, 5:27 pm, Stefano Crocco <stefano.cro...@alice.it> wrote:

[#269888] Re: YAML & readlines & modify text files — Stefano Crocco <stefano.crocco@...> 2007/09/19

Alle mercoled19 settembre 2007, Dan George ha scritto:

[#269910] Re: YAML & readlines & modify text files — Dan George <endege@...> 2007/09/19

On Sep 19, 9:22 pm, Stefano Crocco <stefano.cro...@alice.it> wrote:

[#269913] Re: YAML & readlines & modify text files — Stefano Crocco <stefano.crocco@...> 2007/09/19

Alle mercoled19 settembre 2007, Dan George ha scritto:

[#269925] Re: YAML & readlines & modify text files — Dan George <endege@...> 2007/09/19

On Sep 19, 11:03 pm, Stefano Crocco <stefano.cro...@alice.it> wrote:

[#269816] How to compute Sunrise / Sunset ? — Joe Joe <joepetrini@...>

I need to compute sunrise/set times in ruby for a given long lat. Does

12 messages 2007/09/19

[#269862] special Array method about Unix pathes — unbewusst.sein@... (Une B騅ue)

15 messages 2007/09/19

[#269873] scraping web pages for cisco products — Chuck Dawit <chuckdawit@...>

16 messages 2007/09/19

[#269902] Do C Extensions Block Ruby? — "Wayne E. Seguin" <wayneeseguin@...>

Does a C extension running in a ruby-thread block all ruby threads

16 messages 2007/09/19
[#269904] Re: Do C Extensions Block Ruby? — Nobuyoshi Nakada <nobu@...> 2007/09/19

Hi,

[#269924] Re: Do C Extensions Block Ruby? — Joel VanderWerf <vjoel@...> 2007/09/19

Nobuyoshi Nakada wrote:

[#269971] Is there any separate editor for ruby? — Vellingiri Arul <hariharan.spc@...>

Hai Friends,

13 messages 2007/09/20

[#270018] Idiomatic Ruby for Array#extract / Range#length? — "Sammy Larbi" <sam@...>

During the monthly meeting of our code dojo, we were surprised by a couple

27 messages 2007/09/20
[#270039] Re: Idiomatic Ruby for Array#extract / Range#length? — Xavier Noria <fxn@...> 2007/09/20

On Sep 20, 2007, at 2:28 PM, Sammy Larbi wrote:

[#270047] Re: Idiomatic Ruby for Array#extract / Range#length? — "Rick DeNatale" <rick.denatale@...> 2007/09/20

On 9/20/07, Xavier Noria <fxn@hashref.com> wrote:

[#270051] Re: Idiomatic Ruby for Array#extract / Range#length? — Xavier Noria <fxn@...> 2007/09/20

On Sep 20, 2007, at 5:39 PM, Rick DeNatale wrote:

[#270056] Re: Idiomatic Ruby for Array#extract / Range#length? — "Rick DeNatale" <rick.denatale@...> 2007/09/20

On 9/20/07, Xavier Noria <fxn@hashref.com> wrote:

[#270065] Re: Idiomatic Ruby for Array#extract / Range#length? — "Rick DeNatale" <rick.denatale@...> 2007/09/20

On 9/20/07, Rick DeNatale <rick.denatale@gmail.com> wrote:

[#270084] Re: Idiomatic Ruby for Array#extract / Range#length? — Xavier Noria <fxn@...> 2007/09/20

On Sep 20, 2007, at 7:26 PM, Rick DeNatale wrote:

[#270110] I am new to Ruby and I could use some expert advice as to how I can make this code run faster. — Ruby Maniac <raychorn@...>

I am new to Ruby and I could use some expert advice as to how I can

62 messages 2007/09/20
[#270145] Re: I am new to Ruby and I could use some expert advice as to how I can make this code run faster. — Brian Adkins <lojicdotcom@...> 2007/09/21

On Sep 20, 6:02 pm, Ruby Maniac <raych...@hotmail.com> wrote:

[#270149] Re: I am new to Ruby and I could use some expert advice as to how I can make this code run faster. — John Joyce <dangerwillrobinsondanger@...> 2007/09/21

[#270236] Re: I am new to Ruby and I could use some expert advice as to how I can make this code run faster. — Ruby Maniac <raychorn@...> 2007/09/21

On Sep 20, 7:16 pm, John Joyce <dangerwillrobinsondan...@gmail.com>

[#270239] Re: I am new to Ruby and I could use some expert advice as to how I can make this code run faster. — "Todd Benson" <caduceass@...> 2007/09/21

On 9/21/07, Ruby Maniac <raychorn@hotmail.com> wrote:

[#270305] Re: I am new to Ruby and I could use some expert advice as to how I can make this code run faster. — "Nobuyoshi Nakada" <nobu@...> 2007/09/22

Hi,

[#270575] Re: I am new to Ruby and I could use some expert advice as to how I can make this code run faster. — "Ilmari Heikkinen" <ilmari.heikkinen@...> 2007/09/24

On 9/22/07, Nobuyoshi Nakada <nobu@ruby-lang.org> wrote:

[#270115] How fast does your Ruby run? — SpringFlowers AutumnMoon <summercoolness@...>

How fast does your Ruby run?

114 messages 2007/09/20
[#270118] Re: How fast does your Ruby run? — Todd Burch <promos@...> 2007/09/20

SpringFlowers AutumnMoon wrote:

[#270167] Re: How fast does your Ruby run? — Charles Oliver Nutter <charles.nutter@...> 2007/09/21

Todd Burch wrote:

[#270168] Re: How fast does your Ruby run? — Charles Oliver Nutter <charles.nutter@...> 2007/09/21

Charles Oliver Nutter wrote:

[#270182] Re: How fast does your Ruby run? — gga <GGarramuno@...> 2007/09/21

Seems like a pretty silly test, but okay...

[#270468] Re: How fast does your Ruby run? — David Orriss Jr <codethought@...> 2007/09/23

SpringFlowers AutumnMoon wrote:

[#276142] Re: How fast does your Ruby run? — Daniel Schömer <daniel.schoemer@...> 2007/10/27

Gentoo Linux on Intel Pentium 4 2.40GHz (512 KB cache):

[#276152] Re: How fast does your Ruby run? — Charles Oliver Nutter <charles.nutter@...> 2007/10/27

Daniel Scher wrote:

[#276153] Re: How fast does your Ruby run? — "M. Edward (Ed) Borasky" <znmeb@...> 2007/10/27

Charles Oliver Nutter wrote:

[#276191] Re: How fast does your Ruby run? — Charles Oliver Nutter <charles.nutter@...> 2007/10/27

M. Edward (Ed) Borasky wrote:

[#270161] Re: [ANN] Metadata 1.0-rc2 — Peña, Botp <botp@...>

From: Ilmari Heikkinen [mailto:ilmari.heikkinen@gmail.com]

6 messages 2007/09/21

[#270245] CplusRuby - Gluing C and Ruby — Michael Neumann <mneumann@...>

Hi all,

22 messages 2007/09/21

[#270320] sequel problem: no such file to load -- mysql (LoadError) — Michael Andreasen <ventosus@...>

Hi, i tried to learn about sequel (and Ruby) and got this problem

10 messages 2007/09/22

[#270377] Getting started with Ruby (noob confusion) — Nunya Business <sasnso4a5w12kb8@...>

Hi everyone!

16 messages 2007/09/22

[#270451] Recent Criticism about Ruby (Scalability, etc.) — "forrie@..." <forrie@...>

I presume most people here read today's article on Slashdot which had

80 messages 2007/09/23
[#270729] Re: Recent Criticism about Ruby (Scalability, etc.) — "Phlip" <phlip2005@...> 2007/09/25

> I presume most people here read today's article on Slashdot

[#270760] Re: Recent Criticism about Ruby (Scalability, etc.) — Chad Perrin <perrin@...> 2007/09/25

On Tue, Sep 25, 2007 at 01:04:21PM +0900, Phlip wrote:

[#270789] Re: Recent Criticism about Ruby (Scalability, etc.) — Ruby Maniac <rubymaniac@...> 2007/09/25

On Sep 25, 1:15 am, Chad Perrin <per...@apotheon.com> wrote:

[#271162] Re: Recent Criticism about Ruby (Scalability, etc.) — Chad Perrin <perrin@...> 2007/09/26

On Tue, Sep 25, 2007 at 10:40:04PM +0900, Ruby Maniac wrote:

[#272380] Re: Recent Criticism about Ruby (Scalability, etc.) — Charles Oliver Nutter <charles.nutter@...> 2007/10/03

Chad Perrin wrote:

[#272394] Re: Recent Criticism about Ruby (Scalability, etc.) — "M. Edward (Ed) Borasky" <znmeb@...> 2007/10/03

Charles Oliver Nutter wrote:

[#272398] Re: Recent Criticism about Ruby (Scalability, etc.) — benjohn@... 2007/10/03

[#272405] Re: Recent Criticism about Ruby (Scalability, etc.) — MenTaLguY <mental@...> 2007/10/03

On Thu, 4 Oct 2007 00:19:40 +0900, benjohn@fysh.org wrote:

[#272412] Re: Recent Criticism about Ruby (Scalability, etc.) — Chad Perrin <perrin@...> 2007/10/03

On Thu, Oct 04, 2007 at 12:38:25AM +0900, MenTaLguY wrote:

[#272426] Re: Recent Criticism about Ruby (Scalability, etc.) — MenTaLguY <mental@...> 2007/10/03

On Thu, 4 Oct 2007 01:42:22 +0900, Chad Perrin <perrin@apotheon.com> wrote:

[#272439] Re: Recent Criticism about Ruby (Scalability, etc.) — Chad Perrin <perrin@...> 2007/10/03

On Thu, Oct 04, 2007 at 02:39:28AM +0900, MenTaLguY wrote:

[#270924] Re: Recent Criticism about Ruby (Scalability, etc.) — "M. Edward (Ed) Borasky" <znmeb@...> 2007/09/26

Chad Perrin wrote:

[#270482] how to use Ruby / Tk to display a text message status box — SpringFlowers AutumnMoon <summercoolness@...>

how can we pop up a Tk window to display the temporary results of a

17 messages 2007/09/23
[#270980] Re: how to use Ruby / Tk to display a text message status box — Summercool <Summercoolness@...> 2007/09/26

[#270508] This is why Ruby 1.8.6 can never be made to run anywhere near as fast as Python 2.5.1 — Ruby Maniac <raychorn@...>

I welcome any corrections anyone might be able to make since I am new

60 messages 2007/09/24
[#270524] Re: This is why Ruby 1.8.6 can never be made to run anywhere near as fast as Python 2.5.1 — Phrogz <phrogz@...> 2007/09/24

On Sep 23, 8:50 pm, Ruby Maniac <raych...@hotmail.com> wrote:

[#270531] Re: This is why Ruby 1.8.6 can never be made to run anywhere near as fast as Python 2.5.1 — John Joyce <dangerwillrobinsondanger@...> 2007/09/24

Why do people troll?

[#270535] Re: This is why Ruby 1.8.6 can never be made to run anywhere near as fast as Python 2.5.1 — Mohit Sindhwani <mo_mail@...> 2007/09/24

John Joyce wrote:

[#270557] Re: This is why Ruby 1.8.6 can never be made to run anywhere near as fast as Python 2.5.1 — benjohn@... 2007/09/24

> John Joyce wrote:

[#270597] Re: This is why Ruby 1.8.6 can never be made to run anywhere near as fast as Python 2.5.1 — Chad Perrin <perrin@...> 2007/09/24

On Mon, Sep 24, 2007 at 06:34:57PM +0900, benjohn@fysh.org wrote:

[#270599] Re: This is why Ruby 1.8.6 can never be made to run anywhere near as fast as Python 2.5.1 — "M. Edward (Ed) Borasky" <znmeb@...> 2007/09/24

Chad Perrin wrote:

[#270727] Re: This is why Ruby 1.8.6 can never be made to run anywhere — 7stud -- <dolgun@...> 2007/09/25

Bill Kelly wrote:

[#270532] Re: This is why Ruby 1.8.6 can never be made to run anywhere near as fast as Python 2.5.1 — "Michael T. Richter" <ttmrichter@...> 2007/09/24

Can I ask why *ANYBODY* took a message by someone calling themselves

[#270536] Re: This is why Ruby 1.8.6 can never be made to run anywhere near as fast as Python 2.5.1 — "M. Edward (Ed) Borasky" <znmeb@...> 2007/09/24

Michael T. Richter wrote:

[#270542] "myscript.rb " - there's a blank in my name! — Todd Burch <promos@...>

On a Mac - Tiger 10.4.10.

13 messages 2007/09/24

[#270596] best way to 'hide' a method when method_missing is in town — "Kevin Barnes" <vinbarnes@...>

I am trying to hide a method in a subclass whose base class has

11 messages 2007/09/24

[#270663] Favorite idiom for "keep doing this until it returns nil/false" — Phrogz <phrogz@...>

I want to keep running gsub! on a string until it returns nil. How do

12 messages 2007/09/24

[#270708] object_id 1, 2, 3 — SpringFlowers AutumnMoon <summercoolness@...>

Fixnum object_id

15 messages 2007/09/25

[#270788] I love Ruby but what is the deal with... this ! — Ruby Maniac <rubymaniac@...>

I love Ruby but what is the deal with the lack of a VM ?

25 messages 2007/09/25
[#270791] Re: I love Ruby but what is the deal with... this ! — Gregory Seidman <gsslist+ruby@...> 2007/09/25

On Tue, Sep 25, 2007 at 10:35:06PM +0900, Ruby Maniac wrote:

[#270794] Re: I love Ruby but what is the deal with... this ! — Ruby Maniac <rubymaniac@...> 2007/09/25

On Sep 25, 6:52 am, Gregory Seidman <gsslist+r...@anthropohedron.net>

[#270815] Re: I love Ruby but what is the deal with... this ! — "Walter Purvis" <wpmailinglists@...> 2007/09/25

Troll.

[#270867] Re: I love Ruby but what is the deal with... this ! — Ruby Maniac <rubymaniac@...> 2007/09/25

On Sep 25, 8:23 am, "Walter Purvis" <wpmailingli...@gmail.com> wrote:

[#270872] Re: I love Ruby but what is the deal with... this ! — Phlip <phlip2005@...> 2007/09/25

> Do you classify all those who have an opposing viewpoint as being a

[#270792] Ruby Scales just fine ! — Ruby Maniac <rubymaniac@...>

Just buy a bunch of Quad Core Opterons and get over it !

24 messages 2007/09/25
[#270800] Re: Ruby Scales just fine ! — "M. Edward (Ed) Borasky" <znmeb@...> 2007/09/25

Ruby Maniac wrote:

[#270842] Re: Ruby Scales just fine ! — Eric Hodel <drbrain@...7.net> 2007/09/25

On Sep 25, 2007, at 07:22 , M. Edward (Ed) Borasky wrote:

[#270813] Why dynamic languages for ActiveRecord..? — ypomonh <ypomonh@...>

I having problems understanding why people prefer to implement the

14 messages 2007/09/25

[#270888] The guy who wrote RubyScript2Exe needs to seriously reconsider how this little "gem" works... — Ruby Maniac <rubymaniac@...>

I have a very simple Ruby script that does nothing more than compute

13 messages 2007/09/25

[#270916] ruby regex on html file — eggie5 <eggie5@...>

I'm trying to write a rake task to extract all the script tags out of

12 messages 2007/09/25

[#270966] Feature request for RubyScript2Exe — Ruby Maniac <rubymaniac@...>

It would be nice if RubyScript2Exe was able to handle a passworded ZIP

11 messages 2007/09/26

[#270989] Detecting number ranges — Jay Levitt <jay+news@...>

I had to write a script this evening to take an unsorted input file of the

17 messages 2007/09/26

[#271046] Finding the last Sunday of a month — Peter Bailey <pbailey@...>

Hello,

31 messages 2007/09/26
[#271050] Re: Finding the last Sunday of a month — Yossef Mendelssohn <ymendel@...> 2007/09/26

On Sep 26, 8:44 am, Peter Bailey <pbai...@bna.com> wrote:

[#271078] Recursing through directories — Gabriel Dragffy <gabe@...>

Hi there

14 messages 2007/09/26

[#271089] OneClickInstaller/RubyGems problems — Trans <transfire@...>

Is there anything you have to do after installing the Windows

16 messages 2007/09/26

[#271143] Confession: I never learned CS — Jay Levitt <jay+news@...>

I was thinking about my "Detecting number ranges" question and the various

24 messages 2007/09/26
[#271317] Re: Confession: I never learned CS — Jay Levitt <jay+news@...> 2007/09/27

On Thu, 27 Sep 2007 23:57:08 +0900, Ilmari Heikkinen wrote:

[#271147] Syntax for <stringVariable>.new ? — Larry Fast <lfast@...>

Hi Rubyists and ...istas,

14 messages 2007/09/26
[#271148] Re: Syntax for <stringVariable>.new ? — Sebastian Hungerecker <sepp2k@...> 2007/09/26

Larry Fast wrote:

[#271212] Confession: I never did ASM — julik <listbox@...>

I would love to join the recently started confession fest.

57 messages 2007/09/27
[#271220] Re: [OT] Confession: I never did ASM — "M. Edward (Ed) Borasky" <znmeb@...> 2007/09/27

julik wrote:

[#271279] Re: [OT] Confession: I never did ASM — John Joyce <dangerwillrobinsondanger@...> 2007/09/27

[#271393] Re: [OT] Confession: I never did ASM — "M. Edward (Ed) Borasky" <znmeb@...> 2007/09/28

John Joyce wrote:

[#271403] Re: [OT] Confession: I never did ASM — John Joyce <dangerwillrobinsondanger@...> 2007/09/28

[#271412] Re: [OT] Confession: I never did ASM — "M. Edward (Ed) Borasky" <znmeb@...> 2007/09/28

John Joyce wrote:

[#271672] Re: Confession: I never did ASM — Brian Adkins <lojicdotcom@...> 2007/09/29

On Sep 27, 1:21 am, julik <list...@julik.nl> wrote:

[#271695] Re: Confession: I never did ASM — John Joyce <dangerwillrobinsondanger@...> 2007/09/29

[#272303] Re: Confession: I never did ASM — Brian Adkins <lojicdotcom@...> 2007/10/03

On Sep 29, 3:27 pm, John Joyce <dangerwillrobinsondan...@gmail.com>

[#272307] Re: Confession: I never did ASM — John Joyce <dangerwillrobinsondanger@...> 2007/10/03

[#272309] Re: Confession: I never did ASM — "M. Edward (Ed) Borasky" <znmeb@...> 2007/10/03

John Joyce wrote:

[#272322] Re: Confession: I never did ASM — John Joyce <dangerwillrobinsondanger@...> 2007/10/03

[#272325] Re: Confession: I never did ASM — "M. Edward (Ed) Borasky" <znmeb@...> 2007/10/03

John Joyce wrote:

[#272423] Re: Confession: I never did ASM — Chad Perrin <perrin@...> 2007/10/03

On Wed, Oct 03, 2007 at 02:08:02PM +0900, M. Edward (Ed) Borasky wrote:

[#272508] Re: Confession: I never did ASM — "M. Edward (Ed) Borasky" <znmeb@...> 2007/10/04

Chad Perrin wrote:

[#271356] is there to invoke 'previous' in Find? (or refresh the current path?) — "dtown22@..." <dtown22@...>

I am writing a small script which recursively goes down a dir

10 messages 2007/09/27

[#271360] mac - hpricot problems — Sergio Ruiz <sergio@...>

i am trying to get hpricot running (so i can run mechanize) and am

24 messages 2007/09/27
[#271368] Re: mac - hpricot problems — Daniel Waite <rabbitblue@...> 2007/09/27

Sergio Ruiz wrote:

[#271370] Re: mac - hpricot problems — Sergio Ruiz <sergio@...> 2007/09/28

[#271376] Re: mac - hpricot problems — Ryan Davis <ryand-ruby@...> 2007/09/28

[#271364] Re: Anyone interested In IronRuby — Phrogz <phrogz@...>

On Sep 26, 11:47 pm, IronRuby <rubyguja...@gmail.com> wrote:

12 messages 2007/09/27

[#271394] dike-0.0.1 - a memory leak detector — "ara.t.howard" <ara.t.howard@...>

19 messages 2007/09/28
[#271522] Re: [ANN] dike-0.0.1 - a memory leak detector — Joel VanderWerf <vjoel@...> 2007/09/28

ara.t.howard wrote:

[#271526] Re: [ANN] dike-0.0.1 - a memory leak detector — "ara.t.howard" <ara.t.howard@...> 2007/09/28

[#271467] Probable Iterations (#141) — Ruby Quiz <james@...>

The three rules of Ruby Quiz:

15 messages 2007/09/28

[#271472] Windows - Get current logged user — Rodrigo Bermejo <rodrigo.bermejo@...>

14 messages 2007/09/28

[#271499] a different type of reference (shocked) — SpringFlowers AutumnMoon <summercoolness@...>

Before, when I say Ruby's reference to an object

14 messages 2007/09/28

[#271617] how can I start a shell process and return immediately? — Stephen Bannasch <stephen.bannasch@...>

I want to start a Java program from a Ruby program and have the Java

16 messages 2007/09/29
[#341070] Re: how can I start a shell process and return immediately? — Enling Li <enling.li@...> 2009/07/09

I have another quetion related to fire off a back ground shell process

[#271649] Is there a combination of a struct and an array? I wanna iterate over all created objects from a certain struct-class (I guess). — kazaam <kazaam@...>

I have a file with many entries and much of these I don't need. Let's imagine:

8 messages 2007/09/29

[#271673] a = Dog.new # a is not a pointer and not a reference? — SpringFlowers AutumnMoon <summercoolness@...>

when we say

57 messages 2007/09/29
[#271677] Re: a = Dog.new # a is not a pointer and not a reference? — Morton Goldberg <m_goldberg@...> 2007/09/29

On Sep 29, 2007, at 1:16 PM, SpringFlowers AutumnMoon wrote:

[#271698] Re: a = Dog.new # a is not a pointer and not a reference? — "Austin Ziegler" <halostatue@...> 2007/09/29

On 9/29/07, Morton Goldberg <m_goldberg@ameritech.net> wrote:

[#271718] Re: a = Dog.new # a is not a pointer and not a reference? — Joel VanderWerf <vjoel@...> 2007/09/29

Austin Ziegler wrote:

[#271804] Re: a = Dog.new # a is not a pointer and not a reference? — "Austin Ziegler" <halostatue@...> 2007/09/30

On 9/29/07, Joel VanderWerf <vjoel@path.berkeley.edu> wrote:

[#271732] Re: a = Dog.new # a is not a pointer and not a reference? — SpringFlowers AutumnMoon <summercoolness@...> 2007/09/30

Austin Ziegler wrote:

[#271734] Re: a = Dog.new # a is not a pointer and not a reference? — SpringFlowers AutumnMoon <summercoolness@...> 2007/09/30

SpringFlowers AutumnMoon wrote:

[#271740] Re: a = Dog.new # a is not a pointer and not a reference? — Morton Goldberg <m_goldberg@...> 2007/09/30

On Sep 29, 2007, at 8:18 PM, SpringFlowers AutumnMoon wrote:

[#271738] Newbie needs help getting user input — Peter Vanderhaden <bostonantifan@...>

I'm trying to learn Ruby and trying to convert a Perl program at the

14 messages 2007/09/30

[#271776] Can you please help to make decision? — Byung-Hee HWANG <bh@...>

Fist of all, sorry for poor English, I am not professional English

34 messages 2007/09/30
[#271808] Re: Can you please help to make decision? — 7stud -- <dolgun@...> 2007/09/30

I would choose python.

[#271784] which language allows you to change an argument's value? — Summercool <Summercoolness@...>

34 messages 2007/09/30

[SUMMARY] IP to Country (#139)

From: Ruby Quiz <james@...>
Date: 2007-09-20 12:18:03 UTC
List: ruby-talk #270015
Matthias W辰tcher made a classic mistake this week.  He sent in his first ever
quiz solution and told us not to expect anything special out of it.  We later
learned that it was a lot faster than all of the other solutions, thanks to more
effort from Matthias.  His code taught me some new tricks and I want to share
those with you.

But first, let's talk speed.

Most of the solutions are quite quick, relatively speaking.  What's the shared
secret of speed?  Binary search.  The records are in sorted order, so it's
possible to perform a simple cut-the-possible-matches-in-half-at-each-step
lookup.  That favored algorithm makes short work of what could otherwise be a
lengthy search.

Now you can do a binary search on the database file as is and several solutions
did.  This is a little trickier, because the records are not of a standard size.
You have to be super careful not to accidently skip records.  While the
solutions handled the challenge very well, you can make things quite a bit
easier if you are willing to preprocess the file.

You can also speed things up with some clever preprocessing.  That was the other
trick Matthias used to find answers so quickly.

Matthias realized that while the actual records contain quite a bit of data, we
only really care about the start of a range, the end of a range, and the country
code.  You can fit all of that in just ten bytes with four for each address and
two for the country.

The file also contains some consecutive ranges that can be collapsed for the
purposes of our search.  Such ranges may differ in some attributes, but as long
as their country codes are the same we can treat them as a single unit.

Now that you know the goal, let's take a look at the packing code Matthias sent
in:

	#!/usr/bin/ruby
	# comment
	
	last_start=nil
	last_end=nil
	last_country=nil
	File.open("packed-ip.dat","wb") do |wfile|
	  IO.foreach("geo-ip.csv") do |line|
	    next if !(line =~ /^"/ )
	      s,e,d1,d2,co=line.delete!("\"").split(",")
	      s,e = s.to_i,e.to_i
	      if !last_start
	# initialize with first entry
	        last_start,last_end,last_country = s,e,co
	      else
	        if s==last_end+1 and co==last_country
	# squeeze if successive ranges have zero gap
	          last_end=e
	        else
	# append last entry, remember new one
	          wfile << [last_start,last_end,last_country].pack("NNa2")
	          last_start,last_end,last_country = s,e,co
	        end
	      end
	  end
	# print last entry
	  if last_start
	    wfile << [last_start,last_end,last_country].pack("NNa2")
	  end
	end

The three variables declared up front are for tracking the ranges.  These will
be used to collapse consecutive ranges.

The next bit of code creates the binary database we will write into and parses
the CSV formated data.  Though the data is in the CSV format, the actual content
is trivial and you don't need a proper parser to get at it.  As you can see,
Matthias just checks for lines starting with a quote, pulls out all quote
characters, and split()s on commas.  This is faster than using a parser.

The if/else chain in the middle of the code does most of the work.  First, it
stores the initial range in the tracking variables.  For all other ranges it
tests to see if it is consecutive with the last one recorded and has the same
country code.  When it does, the endpoint of the last range is just bumped to
include them both.  When it doesn't, the last range is written to the file and
the code starts tracking the new range.  The final if statement ensures that we
write out the final range before exiting.

This really isn't too much work and it runs in under two seconds on my box. 
That's a small price to pay for a speed gain every time we look up an address.

Let's dive into the search code now.  Here's how it begins:

	#!/usr/bin/ruby
	
	# take command line or stdin -- the latter has performance advantage
	# for long lists
	if ARGV[0]
	  arr=ARGV
	else
	  arr=$stdin
	end
	
	# ...

As the comment tells us, Matthias added another way to feed the program
addresses.  Where I said we should take one from the command-line arguments,
this code actually handles any number of addresses from command-line arguments
or STDIN.

This next bit of code opens up our database:

	# ...
	
	# the binary table file is looked up with each request
	File.open("packed-ip.dat","rb") do |rfile|
	  rfile.seek(0,IO::SEEK_END)
	  record_max=rfile.pos/10-1
	  
	  # ...

The seek() and pos() calls here are used to find the end of the file.  You need
to know both ends of a data set to perform a binary search.  Note that dividing
by ten gives us the count of records since they are a fixed width and Matthias
subtracts one because we will never need to seek() to the end of the last record
again.

Now there's a touch more preparation for each address we want to find:

	  # ...
	  
	  arr.each { |argv|
	    # build a 4-char string representation of IP address
	    # in network byte order so it can be a string compare below
	    ipstr= argv.split(".").map {|x| x.to_i.chr}.join
	    
	    # ...

In order to avoid a bunch of to_i() calls on each range extracted from the
database, Matthias just encodes the address we are hunting for into the
character encoding used in the database.  This way simple String comparisons can
determine if the address it in the range.

We're now ready for the actual search code:

	    # ...
	    
	    # low/high water marks initialized
	    low,high=0,record_max
	    while true
	      mid=(low+high)/2       # binary search median
	      rfile.seek(10*mid)     # one record is 10 byte, seek to position
	      str=rfile.read(8)      # for range matching, we need only 8 bytes
	      # at comparison, values are big endian, i.e. packed("N")
	      if ipstr>=str[0,4]     # is this IP not below the current range?
	        if ipstr<=str[4,4]   # is this IP not above the current range?
	          puts rfile.read(2) # a perfect match, voila!
	          break
	        else
	          low=mid+1          # binary search: raise lower limit
	        end
	      else
	        high=mid-1           # binary search: reduce upper limit
	      end
	      if low>high            # no entries left? nothing found
	        puts "no country"
	        break
	      end
	    end
	  }
	end

This is a pretty textbook binary search.  You always begin by going to the
middle of the current low and high.  In this case that's a seek() call and we
have to remember to multiply the midpoint by our record size of ten.

Once we are at the right record, the code read()s the first eight bytes and
compares the address against the low and high for the range.  When it is in the
range, the final two bytes are read and printed.  If the address is below the
current range, we drop the high to below the current range.  If it's above, we
raise the low to above the current range.  A final check is added to catch the
cases where no match was found, in which case our low will bypass the high.

Remember that a second goal of the quiz described search was to be memory
friendly.  This code does terrific on that front since only one record needs to
be in memory at a time.  Once the checks are done, it can be replaced by the
next record.

My thanks to all who showed so many great examples of this classic algorithm.

Tomorrow we will write programs that can help me to better understand my
wardrobe...

In This Thread

Prev Next