Oldest Ruby hacker?

C

Chris McMahon

My father-in-law is a mostly retired mining engineer. He keeps a lot
of data about mines in an Excel spreadsheet.

I'm a QA tester. I've been working on a data-driven Fit-like harness
that holds test data in Excel spreadsheets.

He had to do some math on the values in the table. I hacked up my test
data framework to parse his spreadsheet (took about 15 minutes), and
now he's learning Ruby (and the very nice ScriptingExcel page at Ruby
Garden) because he just couldn't do his work with VBA.

He is 71 years old.
 
C

Charles Roper

Chris said:
He had to do some math on the values in the table. I hacked up my test
data framework to parse his spreadsheet (took about 15 minutes), and
now he's learning Ruby (and the very nice ScriptingExcel page at Ruby
Garden) because he just couldn't do his work with VBA.

I too am learning Ruby (I am a mere 30 though) and have started with
hacking at Excel spreadsheets as a) I have to do a lot of this in my
work, thus making rather dry work quite fun (ah, the magic of Ruby);
and b) VBA makes my skin crawl. The Scripting Excel page on the Garden
has been invaluable for this, but I'm finding reading in values from
cells and writing them back again to be extremely slow. Once in a Ruby
array they process like lightening. Has anyone got any tips for
speeding up the parsing of ranges, and writing them back again?

Here's an example of how I'm iterating over a range (simplified for
clarity):

my_range = "$A$2:$A$3000"
my_array = []
sheet.range(my_range).each { |cell| my_array << cell.value }

On large ranges, where I slot arrays within arrays, doing this kind of
thing seems to take an age, even on my Athlon64 3200. To give you some
idea, reading in an 8000 row x 20 column worksheet takes over 1 minute
and 45 seconds, while writing takes about 80 seconds. The actual
processing Ruby does on the arrays is about 1 second from what I can
tell.

Chris - I'd love to take a look at your Excel parsing framework.
Perhaps it'll help me get my head around Ruby a little more.

Many thanks,

Charles Roper
 
P

pat eyler

How about youngest Ruby hacker?

Well, my 11 yo son is working on it. I'm looking forward to helping
him post some of his work here in the not too distant future.
 
J

Jacob Quinn Shenker

T24gMTAvMjcvMDUsIHBhdCBleWxlciA8cGF0LmV5bGVyQGdtYWlsLmNvbT4gd3JvdGU6Cj4gT24g
MTAvMjcvMDUsIEphY29iIFF1aW5uIFNoZW5rZXIgPGpxc2hlbmtlckBnbWFpbC5jb20+IHdyb3Rl
Ogo+ID4gSG93IGFib3V0IHlvdW5nZXN0IFJ1YnkgaGFja2VyPwo+ID4KPgo+IFdlbGwsIG15IDEx
IHlvIHNvbiBpcyB3b3JraW5nIG9uIGl0LiAgSSdtIGxvb2tpbmcgZm9yd2FyZCB0byBoZWxwaW5n
Cj4gaGltIHBvc3Qgc29tZSBvZiBoaXMgd29yayBoZXJlIGluIHRoZSBub3QgdG9vIGRpc3RhbnQg
ZnV0dXJlLgoKLi4ud2VsbCwgaGUgaGFzIG1lIGJlYXQuIEknbSAxNC4gOikKCj4KPiAtLQo+IHRo
YW5rcywKPiAtcGF0ZQo+IC0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0KPgo+Cg==
 
T

Terje Tjervaag

The Scripting Excel page on the Garden
has been invaluable for this, but I'm finding reading in values from
cells and writing them back again to be extremely slow. Once in a Ruby
array they process like lightening. Has anyone got any tips for
speeding up the parsing of ranges, and writing them back again?

Charles,

It's a simple trick but in case you don't know about it, turn off
screen updating while you're doing your routine using:
excel.screenupdating =3D false
..where excel is your reference to the application (e.g.
WIN32OLE::new('excel/application'))

Remember to turn it back on with '=3D true' when you're done or excel
won't show your changes.
 
P

pat eyler

...well, he has me beat. I'm 14. :)

He may beat you ... let's wait 'till he actually writes something more than=
the
'how many seconds old are you?' exercises.

Hacking Ruby at 14 is pretty cool though. :)
 
C

Christophe Grandsire

Selon pat eyler said:
Hacking Ruby at 14 is pretty cool though. :)

That ain't nothing! ( ;) ) I was already programming when I was 6, and it=
wasn't
in Ruby only because Ruby didn't exist yet. Hey, I had already written a =
fully
fledged text editor when I was 14, all in BASIC (Amstrad CPC BASIC). I re=
member
having to deal with the cursor issue and the editor buffer and the text d=
isplay
all by myself. Can't remember how I did it though (and I don't have the p=
rogram
anymore :( ).

And then one wonders why I didn't take a CS education. Must be all that
brain-washing from my parents and my teachers that programming "wouldn't =
put
bread on the table." Now I have to content myself with a M.Sc in Physics =
:( ...

Seriously though, it's indeed pretty cool to see people of the age of 14 =
already
hacking away :) .
--
Christophe Grandsire.

http://rainbow.conlang.free.fr

It takes a straight mind to create a twisted conlang.
 
Z

Zach Dennis

Christophe said:
That ain't nothing! ( ;) ) I was already programming when I was 6, and it wasn't
in Ruby only because Ruby didn't exist yet. Hey, I had already written a fully
fledged text editor when I was 14, all in BASIC (Amstrad CPC BASIC).

Not to be snide, but "Do you want a cookie?"

Zach
 
C

Christophe Grandsire

Selon Zach Dennis :
Not to be snide, but "Do you want a cookie?"

I am not a native English speaker, so I don't know what you mean.

As for what I wrote, it was meant as a semi-joke (note the winkey!),
just to point out in (hopefully) a humorous way that some have begun
programming quite early in their life. I realise now it kind of made me
look like a grumpy old man who didn't feel he was recognised enough.
That wasn't my purpose (hey, I'm only 29, with the social skills of
closed oyster, so I may sound quite differently from what I mean).

Anyway, if my remarks were in any way out of place, I apologise. I
wasn't meaning to sound pretentious. Apparently I failed :( .
--
Christophe Grandsire.

http://rainbow.conlang.free.fr

You need a straight mind to invent a twisted conlang.
 
Z

Zach Dennis

Christophe said:
Selon Zach Dennis :


I am not a native English speaker, so I don't know what you mean.

Growing up as a minister's son I would often go to bible camps in the
summer. All of us pk's (pastor's kids) would always feel we had a one up
on all of the other campers for some reason. We felt we were "special"
just for being a pk! One year a speaker at a conference asked the
pastor's kids if they wanted a cookie because they were special, then he
told us to sit down and he went on with the rest of his message.

So the cookie comment could be rephrased by saying, "Did you tell us
this just so we would all know how special you are? Would you like a
prize (a cookie) for your accomplishments as a kid?)
As for what I wrote, it was meant as a semi-joke (note the winkey!),
just to point out in (hopefully) a humorous way that some have begun
programming quite early in their life. I realise now it kind of made me
look like a grumpy old man who didn't feel he was recognised enough.
That wasn't my purpose (hey, I'm only 29, with the social skills of
closed oyster, so I may sound quite differently from what I mean).

Anyway, if my remarks were in any way out of place, I apologise. I
wasn't meaning to sound pretentious. Apparently I failed :( .

I see what you mean, I was being way to picky. I apologize for
insensitive comment on my behalf. Have a good weekend,

Zach
 
C

Charles Roper

It's a simple trick but in case you don't know about it, turn off
screen updating while you're doing your routine using:
excel.screenupdating =3D false
..where excel is your reference to the application (e.g.
WIN32OLE::new('excel/application'))

Remember to turn it back on with '=3D true' when you're done or excel
won't show your changes.

Terje,

Many thanks for the suggestion. I'm actually doing something similar
and hiding the whole Excel app:

excel.Visible =3D false

I also tried your suggestion, but reading and writing to cells was still sl=
ow.

However, I found a solution. Iterating over a range of cells and
reading or writing to them individually is what was causing the
bottleneck, so I experimented with reading whole ranges into an array
like so:

my_range =3D "$A$2:$A$8000"
my_array =3D sheet.range(my_range).Value

Not only is this more terse, it's also much, much faster. Using my
8000 row sheet, it reads the range into an array in about a 1.5
seconds, as opposed to the iterator taking over 1 minute and 45
seconds.

I was also delighted to discover that this works for writing back to a
range of cells too:

sheet.range(my_range) =3D my_array

Beautiful.
 

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
473,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top