From steve.holder at gmail.com Thu Jun 7 14:56:05 2007 From: steve.holder at gmail.com (Steve Holder) Date: Thu, 7 Jun 2007 11:56:05 -0700 Subject: [Pasadenarb-general] Next meeting Message-ID: <7d2225580706071156h146feaect6ad58c5934902ab4@mail.gmail.com> Hey everybody- Just a reminder, our next meeting is coming up, Tues. 6/12, 6:30 pm. Hope to see everybody. -Steve -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/pasadenarb-general/attachments/20070607/63ed9798/attachment.html From dorkus at gmail.com Fri Jun 8 11:10:51 2007 From: dorkus at gmail.com (Josh Kleinpeter) Date: Fri, 8 Jun 2007 08:10:51 -0700 Subject: [Pasadenarb-general] Meeting on 6/12 Message-ID: <78c8cd130706080810q4972711avaeca93dbaced137@mail.gmail.com> Not sure if I'm too late to get an invite to your 6/12 meeting, but I'd love to start attending. I'm a software developer at EarthLink in Pasadena, and I'm a big fan of Ruby and Rails. I've developed a few applications in Rails, mostly prototypes, and I'm working on more production worthy applications as I can. Glad to have discovered this (another EarthLinker turned me on to you guys), and hope to be able to meet with you all soon. -- Josh Kleinpeter -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/pasadenarb-general/attachments/20070608/1a8c3d7c/attachment.html From nate at natemurray.com Fri Jun 8 11:17:21 2007 From: nate at natemurray.com (Nathan Murray) Date: Fri, 8 Jun 2007 08:17:21 -0700 Subject: [Pasadenarb-general] Meeting on 6/12 In-Reply-To: <78c8cd130706080810q4972711avaeca93dbaced137@mail.gmail.com> References: <78c8cd130706080810q4972711avaeca93dbaced137@mail.gmail.com> Message-ID: Hey Josh! It's never too late and we would love to see you come. Check the archives or email Steve or I for directions. Hope to see you there! -Nate On Jun 8, 2007, at 8:10 AM, Josh Kleinpeter wrote: > Not sure if I'm too late to get an invite to your 6/12 meeting, but > I'd love to start attending. > > I'm a software developer at EarthLink in Pasadena, and I'm a big > fan of Ruby and Rails. I've developed a few applications in Rails, > mostly prototypes, and I'm working on more production worthy > applications as I can. Glad to have discovered this (another > EarthLinker turned me on to you guys), and hope to be able to meet > with you all soon. > > > -- > Josh Kleinpeter > _______________________________________________ > Pasadenarb-general mailing list > Pasadenarb-general at rubyforge.org > http://rubyforge.org/mailman/listinfo/pasadenarb-general From nate at heydsg.com Wed Jun 13 01:54:38 2007 From: nate at heydsg.com (Nate Daiger) Date: Tue, 12 Jun 2007 22:54:38 -0700 Subject: [Pasadenarb-general] great meeting tonight! Message-ID: <2e29f79d0706122254l459b77c4x35cf29327cddb9b8@mail.gmail.com> it was tons of fun. here's some of that proc vs. lambda crapola we were talking about: http://samdanielson.com/2007/3/19/proc-new-vs-lambda-in-ruby nate From steve.holder at gmail.com Wed Jun 13 15:52:45 2007 From: steve.holder at gmail.com (Steve Holder) Date: Wed, 13 Jun 2007 12:52:45 -0700 Subject: [Pasadenarb-general] great meeting tonight! In-Reply-To: <2e29f79d0706122254l459b77c4x35cf29327cddb9b8@mail.gmail.com> References: <2e29f79d0706122254l459b77c4x35cf29327cddb9b8@mail.gmail.com> Message-ID: <7d2225580706131252i6d681cf7ye8f5766cd6e0dd2f@mail.gmail.com> Thanks for the link, Nate - until our discussion last night, I hadn't realized there actually was a practical difference between Proc.new & lambda. The video turned out better than I expected - some of it is a bit blurry, but the audio is good. I'll hopefully be able to post them in the next few days, for folks who couldn't make it last night. I also realized we never discussed what to do at the next meeting. Any volunteers for talks? Jruby hit 1.0 a couple days ago, I could do a short presentation on that if anyone beside me is interested. -Steve On 6/12/07, Nate Daiger wrote: > > it was tons of fun. > > here's some of that proc vs. lambda crapola we were talking about: > > http://samdanielson.com/2007/3/19/proc-new-vs-lambda-in-ruby > > > nate > _______________________________________________ > Pasadenarb-general mailing list > Pasadenarb-general at rubyforge.org > http://rubyforge.org/mailman/listinfo/pasadenarb-general > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/pasadenarb-general/attachments/20070613/9dee8e73/attachment.html From nate at natemurray.com Wed Jun 13 16:04:46 2007 From: nate at natemurray.com (Nathan Murray) Date: Wed, 13 Jun 2007 13:04:46 -0700 Subject: [Pasadenarb-general] great meeting tonight! In-Reply-To: <7d2225580706131252i6d681cf7ye8f5766cd6e0dd2f@mail.gmail.com> References: <2e29f79d0706122254l459b77c4x35cf29327cddb9b8@mail.gmail.com> <7d2225580706131252i6d681cf7ye8f5766cd6e0dd2f@mail.gmail.com> Message-ID: Steve, I'd be interested in hearing about Jruby, I don't know much about it. I have a ruby question for you guys. I'm working on workers and managers like we were talking about last night. My workers create "Releases" (each time the site needs to be pushed live a Release is created). I want to loop over and check if the release is done. However, I don't want to infinite loop, I only want to check it, say, maybe 100 times. So I have the code like the following more than once: i = 0 until release.successful? || i >= 100 puts "doing something #{i}" i += 1 end It works okay, but I see this repetition and want to abstract it out. "Fill in the slots" you might say. What I want is a rubyish way to do this like 100.times do ... or 0.upto(100) etc. So my first attempt was something like 100.max_times_until release.successful? do |i| puts "doing something #{i}" end and max_time_until takes care of the iterator and yields i each time. The problem is that "release.successful?" is evaluated at the time its called and never again. So you never know if the status of the release changed. The best I've come up with is to wrap "release.successful?" in a lambda block. But this is a bit ugly. Can anyone think of a way to give this a clean syntax and still achieve the desired effect? I've attached my Integer extension and a rails-runnable test. ====================== class Integer def max_times_until(predicate) i = 0 until predicate.call || i >= to_i yield i i +=1 end end end ========================= require File.dirname(__FILE__) + '/../../test_helper' class Incrementer attr_accessor :incrementer def initialize @incrementer = 0 end def successful? return true if @incrementer >= 5 @incrementer += 1 false end end class IntegerExtensionTest < Test::Unit::TestCase def test_max_times inc = Incrementer.new 10.max_times_until lambda { inc.successful? } do |i| puts "try #{i} (#{inc.incrementer})" end i = 0 until release.successful? || i >= 100 puts "doing something #{i}" i += 1 end end end On Jun 13, 2007, at 12:52 PM, Steve Holder wrote: > Thanks for the link, Nate - until our discussion last night, I > hadn't realized there actually was a practical difference between > Proc.new & lambda. The video turned out better than I expected - > some of it is a bit blurry, but the audio is good. I'll hopefully > be able to post them in the next few days, for folks who couldn't > make it last night. > > I also realized we never discussed what to do at the next meeting. > Any volunteers for talks? Jruby hit 1.0 a couple days ago, I could > do a short presentation on that if anyone beside me is interested. > > -Steve > > On 6/12/07, Nate Daiger wrote: > it was tons of fun. > > here's some of that proc vs. lambda crapola we were talking about: > > http://samdanielson.com/2007/3/19/proc-new-vs-lambda-in-ruby > > > nate > _______________________________________________ > Pasadenarb-general mailing list > Pasadenarb-general at rubyforge.org > http://rubyforge.org/mailman/listinfo/pasadenarb-general -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/pasadenarb-general/attachments/20070613/b19a81a4/attachment-0001.html From adam at cpocommerce.com Wed Jun 13 18:28:11 2007 From: adam at cpocommerce.com (adam at cpocommerce.com) Date: Wed, 13 Jun 2007 15:28:11 -0700 (PDT) Subject: [Pasadenarb-general] great meeting tonight! In-Reply-To: Message-ID: <474022.30192.qm@web814.biz.mail.mud.yahoo.com> I would be interested in Jruby also. Adam Nathan Murray wrote: Steve, I'd be interested in hearing about Jruby, I don't know much about it. I have a ruby question for you guys. I'm working on workers and managers like we were talking about last night. My workers create "Releases" (each time the site needs to be pushed live a Release is created). I want to loop over and check if the release is done. However, I don't want to infinite loop, I only want to check it, say, maybe 100 times. So I have the code like the following more than once: i = 0 until release.successful? || i >= 100 puts "doing something #{i}" i += 1 end It works okay, but I see this repetition and want to abstract it out. "Fill in the slots" you might say. What I want is a rubyish way to do this like 100.times do ... or 0.upto(100) etc. So my first attempt was something like 100.max_times_until release.successful? do |i| puts "doing something #{i}" end and max_time_until takes care of the iterator and yields i each time. The problem is that "release.successful?" is evaluated at the time its called and never again. So you never know if the status of the release changed. The best I've come up with is to wrap "release.successful?" in a lambda block. But this is a bit ugly. Can anyone think of a way to give this a clean syntax and still achieve the desired effect? I've attached my Integer extension and a rails-runnable test. ====================== class Integer def max_times_until(predicate) i = 0 until predicate.call || i >= to_i yield i i +=1 end end end ========================= require File.dirname(__FILE__) + '/../../test_helper' class Incrementer attr_accessor :incrementer def initialize @incrementer = 0 end def successful? return true if @incrementer >= 5 @incrementer += 1 false end end class IntegerExtensionTest < Test::Unit::TestCase def test_max_times inc = Incrementer.new 10.max_times_until lambda { inc.successful? } do |i| puts "try #{i} (#{inc.incrementer})" end i = 0 until release.successful? || i >= 100 puts "doing something #{i}" i += 1 end end end On Jun 13, 2007, at 12:52 PM, Steve Holder wrote: Thanks for the link, Nate - until our discussion last night, I hadn't realized there actually was a practical difference between Proc.new & lambda. The video turned out better than I expected - some of it is a bit blurry, but the audio is good. I'll hopefully be able to post them in the next few days, for folks who couldn't make it last night. I also realized we never discussed what to do at the next meeting. Any volunteers for talks? Jruby hit 1.0 a couple days ago, I could do a short presentation on that if anyone beside me is interested. -Steve On 6/12/07, Nate Daiger wrote:it was tons of fun. here's some of that proc vs. lambda crapola we were talking about: http://samdanielson.com/2007/3/19/proc-new-vs-lambda-in-ruby nate _______________________________________________ Pasadenarb-general mailing list Pasadenarb-general at rubyforge.org http://rubyforge.org/mailman/listinfo/pasadenarb-general _______________________________________________ Pasadenarb-general mailing list Pasadenarb-general at rubyforge.org http://rubyforge.org/mailman/listinfo/pasadenarb-general -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/pasadenarb-general/attachments/20070613/b196115c/attachment.html From matt+pasadenarb at quantumlab.net Wed Jun 13 21:51:22 2007 From: matt+pasadenarb at quantumlab.net (Matt Pulver) Date: Wed, 13 Jun 2007 18:51:22 -0700 Subject: [Pasadenarb-general] great meeting tonight! In-Reply-To: <20070614014418.GA10439@xork.dyndns.org> References: <2e29f79d0706122254l459b77c4x35cf29327cddb9b8@mail.gmail.com> <7d2225580706131252i6d681cf7ye8f5766cd6e0dd2f@mail.gmail.com> <20070614014418.GA10439@xork.dyndns.org> Message-ID: <20070614015122.GB10439@xork.dyndns.org> As you can see I didn't read your entire email :) - adding a single lambda with 2 {}'s seems pretty clean to me... doesn't even add any extra lines. Matt On Wed, Jun 13, 2007 at 06:44:18PM -0700, Matt Pulver wrote: > Hi Nate, > > Nice exercise in higher-order procedures. Well thanks to your > talk last night, I think simply wrapping a lambda around the > release.successful? call should do the trick: > > 100.max_times_until lambda { release.successful? } do |i| > puts "doing something #{i}" > sleep 1 > end > > where max_times_until is defined as: > > class Fixnum > def max_times_until( procedure ) > 1.upto(self) do |i| > break if procedure.call > yield i > end > end > end > > Attached is a script that tests this, by simply checking to see if 3 > seconds have passed. > > Matt > > > On Wed, Jun 13, 2007 at 01:04:46PM -0700, Nathan Murray wrote: > > > > Steve, I'd be interested in hearing about Jruby, I don't know much > > about it. > > > > I have a ruby question for you guys. I'm working on workers and > > managers like we were talking about last night. My workers create > > "Releases" (each time the site needs to be pushed live a Release is > > created). > > > > I want to loop over and check if the release is done. However, I don't > > want to infinite loop, I only want to check it, say, maybe 100 times. > > So I have the code like the following more than once: > > > > i = 0 > > until release.successful? || i >= 100 > > puts "doing something #{i}" > > i += 1 > > end > > It works okay, but I see this repetition and want to abstract it out. > > "Fill in the slots" you might say. What I want is a rubyish way to do > > this like > > 100.times do ... or 0.upto(100) etc. > > So my first attempt was something like > > > > 100.max_times_until release.successful? do |i| > > puts "doing something #{i}" > > end > > and max_time_until takes care of the iterator and yields i each time. > > The problem is that "release.successful?" is evaluated at the time its > > called and never again. So you never know if the status of the release > > changed. The best I've come up with is to wrap "release.successful?" > > in a lambda block. But this is a bit ugly. Can anyone think of a way > > to give this a clean syntax and still achieve the desired effect? > > I've attached my Integer extension and a rails-runnable test. > > ====================== > > class Integer > > def max_times_until(predicate) > > i = 0 > > until predicate.call || i >= to_i > > yield i > > i +=1 > > end > > end > > end > > ========================= > > require File.dirname(__FILE__) + '/../../test_helper' > > class Incrementer > > attr_accessor :incrementer > > def initialize > > @incrementer = 0 > > end > > def successful? > > return true if @incrementer >= 5 > > @incrementer += 1 > > false > > end > > end > > class IntegerExtensionTest < Test::Unit::TestCase > > def test_max_times > > inc = Incrementer.new > > 10.max_times_until lambda { inc.successful? } do |i| > > puts "try #{i} (#{inc.incrementer})" > > end > > i = 0 > > until release.successful? || i >= 100 > > puts "doing something #{i}" > > i += 1 > > end > > end > > end > > > > On Jun 13, 2007, at 12:52 PM, Steve Holder wrote: > > > > Thanks for the link, Nate - until our discussion last night, I > > hadn't realized there actually was a practical difference between > > Proc.new & lambda. The video turned out better than I expected - > > some of it is a bit blurry, but the audio is good. I'll hopefully > > be able to post them in the next few days, for folks who couldn't > > make it last night. > > I also realized we never discussed what to do at the next meeting. > > Any volunteers for talks? Jruby hit 1.0 a couple days ago, I could > > do a short presentation on that if anyone beside me is interested. > > -Steve > > > > On 6/12/07, Nate Daiger <[1]nate at heydsg.com> wrote: > > > > it was tons of fun. > > here's some of that proc vs. lambda crapola we were talking about: > > [2]http://samdanielson.com/2007/3/19/proc-new-vs-lambda-in-ruby > > nate > #!/usr/bin/env ruby > > class Fixnum > def max_times_until( procedure ) > 1.upto(self) do |i| > break if procedure.call > yield i > end > end > end > > class Time > def seconds_later?(seconds) > self + seconds < Time.now > end > end > > release = Time.new > > 100.max_times_until lambda { release.seconds_later?(3) } do |i| > puts "doing something #{i}" > sleep 1 > end From matt+pasadenarb at quantumlab.net Wed Jun 13 22:16:06 2007 From: matt+pasadenarb at quantumlab.net (Matt Pulver) Date: Wed, 13 Jun 2007 19:16:06 -0700 Subject: [Pasadenarb-general] great meeting tonight! In-Reply-To: <20070614015122.GB10439@xork.dyndns.org> References: <2e29f79d0706122254l459b77c4x35cf29327cddb9b8@mail.gmail.com> <7d2225580706131252i6d681cf7ye8f5766cd6e0dd2f@mail.gmail.com> <20070614014418.GA10439@xork.dyndns.org> <20070614015122.GB10439@xork.dyndns.org> Message-ID: <20070614021606.GA10522@xork.dyndns.org> Ok so I don't read emails and now I spam the list :) Maybe this is what you're looking for? 100.max_times_until do |i| puts "doing something #{i}" sleep 1 release.seconds_later?(3) end Put the boolean-valued method call last that determines when to exit, which then becomes the return value of yield: class Fixnum def max_times_until 1.upto(self) do |i| break if yield i end end end Attached is a runnable demo. Matt On Wed, Jun 13, 2007 at 06:51:22PM -0700, Matt Pulver wrote: > As you can see I didn't read your entire email :) - adding a single > lambda with 2 {}'s seems pretty clean to me... doesn't even add any > extra lines. > > Matt > > > On Wed, Jun 13, 2007 at 06:44:18PM -0700, Matt Pulver wrote: > > Hi Nate, > > > > Nice exercise in higher-order procedures. Well thanks to your > > talk last night, I think simply wrapping a lambda around the > > release.successful? call should do the trick: > > > > 100.max_times_until lambda { release.successful? } do |i| > > puts "doing something #{i}" > > sleep 1 > > end > > > > where max_times_until is defined as: > > > > class Fixnum > > def max_times_until( procedure ) > > 1.upto(self) do |i| > > break if procedure.call > > yield i > > end > > end > > end > > > > Attached is a script that tests this, by simply checking to see if 3 > > seconds have passed. > > > > Matt > > > > > > On Wed, Jun 13, 2007 at 01:04:46PM -0700, Nathan Murray wrote: > > > > > > Steve, I'd be interested in hearing about Jruby, I don't know much > > > about it. > > > > > > I have a ruby question for you guys. I'm working on workers and > > > managers like we were talking about last night. My workers create > > > "Releases" (each time the site needs to be pushed live a Release is > > > created). > > > > > > I want to loop over and check if the release is done. However, I don't > > > want to infinite loop, I only want to check it, say, maybe 100 times. > > > So I have the code like the following more than once: > > > > > > i = 0 > > > until release.successful? || i >= 100 > > > puts "doing something #{i}" > > > i += 1 > > > end > > > It works okay, but I see this repetition and want to abstract it out. > > > "Fill in the slots" you might say. What I want is a rubyish way to do > > > this like > > > 100.times do ... or 0.upto(100) etc. > > > So my first attempt was something like > > > > > > 100.max_times_until release.successful? do |i| > > > puts "doing something #{i}" > > > end > > > and max_time_until takes care of the iterator and yields i each time. > > > The problem is that "release.successful?" is evaluated at the time its > > > called and never again. So you never know if the status of the release > > > changed. The best I've come up with is to wrap "release.successful?" > > > in a lambda block. But this is a bit ugly. Can anyone think of a way > > > to give this a clean syntax and still achieve the desired effect? > > > I've attached my Integer extension and a rails-runnable test. > > > ====================== > > > class Integer > > > def max_times_until(predicate) > > > i = 0 > > > until predicate.call || i >= to_i > > > yield i > > > i +=1 > > > end > > > end > > > end > > > ========================= > > > require File.dirname(__FILE__) + '/../../test_helper' > > > class Incrementer > > > attr_accessor :incrementer > > > def initialize > > > @incrementer = 0 > > > end > > > def successful? > > > return true if @incrementer >= 5 > > > @incrementer += 1 > > > false > > > end > > > end > > > class IntegerExtensionTest < Test::Unit::TestCase > > > def test_max_times > > > inc = Incrementer.new > > > 10.max_times_until lambda { inc.successful? } do |i| > > > puts "try #{i} (#{inc.incrementer})" > > > end > > > i = 0 > > > until release.successful? || i >= 100 > > > puts "doing something #{i}" > > > i += 1 > > > end > > > end > > > end > > > > > > On Jun 13, 2007, at 12:52 PM, Steve Holder wrote: > > > > > > Thanks for the link, Nate - until our discussion last night, I > > > hadn't realized there actually was a practical difference between > > > Proc.new & lambda. The video turned out better than I expected - > > > some of it is a bit blurry, but the audio is good. I'll hopefully > > > be able to post them in the next few days, for folks who couldn't > > > make it last night. > > > I also realized we never discussed what to do at the next meeting. > > > Any volunteers for talks? Jruby hit 1.0 a couple days ago, I could > > > do a short presentation on that if anyone beside me is interested. > > > -Steve > > > > > > On 6/12/07, Nate Daiger <[1]nate at heydsg.com> wrote: > > > > > > it was tons of fun. > > > here's some of that proc vs. lambda crapola we were talking about: > > > [2]http://samdanielson.com/2007/3/19/proc-new-vs-lambda-in-ruby > > > nate > > > #!/usr/bin/env ruby > > > > class Fixnum > > def max_times_until( procedure ) > > 1.upto(self) do |i| > > break if procedure.call > > yield i > > end > > end > > end > > > > class Time > > def seconds_later?(seconds) > > self + seconds < Time.now > > end > > end > > > > release = Time.new > > > > 100.max_times_until lambda { release.seconds_later?(3) } do |i| > > puts "doing something #{i}" > > sleep 1 > > end > > _______________________________________________ > Pasadenarb-general mailing list > Pasadenarb-general at rubyforge.org > http://rubyforge.org/mailman/listinfo/pasadenarb-general -------------- next part -------------- #!/usr/bin/env ruby class Fixnum def max_times_until 1.upto(self) do |i| break if yield i end end end class Time def seconds_later?(seconds) self + seconds < Time.now end end release = Time.new 100.max_times_until do |i| puts "doing something #{i}" sleep 1 release.seconds_later?(3) end From matt+pasadenarb at quantumlab.net Wed Jun 13 21:44:18 2007 From: matt+pasadenarb at quantumlab.net (Matt Pulver) Date: Wed, 13 Jun 2007 18:44:18 -0700 Subject: [Pasadenarb-general] great meeting tonight! In-Reply-To: References: <2e29f79d0706122254l459b77c4x35cf29327cddb9b8@mail.gmail.com> <7d2225580706131252i6d681cf7ye8f5766cd6e0dd2f@mail.gmail.com> Message-ID: <20070614014418.GA10439@xork.dyndns.org> Hi Nate, Nice exercise in higher-order procedures. Well thanks to your talk last night, I think simply wrapping a lambda around the release.successful? call should do the trick: 100.max_times_until lambda { release.successful? } do |i| puts "doing something #{i}" sleep 1 end where max_times_until is defined as: class Fixnum def max_times_until( procedure ) 1.upto(self) do |i| break if procedure.call yield i end end end Attached is a script that tests this, by simply checking to see if 3 seconds have passed. Matt On Wed, Jun 13, 2007 at 01:04:46PM -0700, Nathan Murray wrote: > > Steve, I'd be interested in hearing about Jruby, I don't know much > about it. > > I have a ruby question for you guys. I'm working on workers and > managers like we were talking about last night. My workers create > "Releases" (each time the site needs to be pushed live a Release is > created). > > I want to loop over and check if the release is done. However, I don't > want to infinite loop, I only want to check it, say, maybe 100 times. > So I have the code like the following more than once: > > i = 0 > until release.successful? || i >= 100 > puts "doing something #{i}" > i += 1 > end > It works okay, but I see this repetition and want to abstract it out. > "Fill in the slots" you might say. What I want is a rubyish way to do > this like > 100.times do ... or 0.upto(100) etc. > So my first attempt was something like > > 100.max_times_until release.successful? do |i| > puts "doing something #{i}" > end > and max_time_until takes care of the iterator and yields i each time. > The problem is that "release.successful?" is evaluated at the time its > called and never again. So you never know if the status of the release > changed. The best I've come up with is to wrap "release.successful?" > in a lambda block. But this is a bit ugly. Can anyone think of a way > to give this a clean syntax and still achieve the desired effect? > I've attached my Integer extension and a rails-runnable test. > ====================== > class Integer > def max_times_until(predicate) > i = 0 > until predicate.call || i >= to_i > yield i > i +=1 > end > end > end > ========================= > require File.dirname(__FILE__) + '/../../test_helper' > class Incrementer > attr_accessor :incrementer > def initialize > @incrementer = 0 > end > def successful? > return true if @incrementer >= 5 > @incrementer += 1 > false > end > end > class IntegerExtensionTest < Test::Unit::TestCase > def test_max_times > inc = Incrementer.new > 10.max_times_until lambda { inc.successful? } do |i| > puts "try #{i} (#{inc.incrementer})" > end > i = 0 > until release.successful? || i >= 100 > puts "doing something #{i}" > i += 1 > end > end > end > > On Jun 13, 2007, at 12:52 PM, Steve Holder wrote: > > Thanks for the link, Nate - until our discussion last night, I > hadn't realized there actually was a practical difference between > Proc.new & lambda. The video turned out better than I expected - > some of it is a bit blurry, but the audio is good. I'll hopefully > be able to post them in the next few days, for folks who couldn't > make it last night. > I also realized we never discussed what to do at the next meeting. > Any volunteers for talks? Jruby hit 1.0 a couple days ago, I could > do a short presentation on that if anyone beside me is interested. > -Steve > > On 6/12/07, Nate Daiger <[1]nate at heydsg.com> wrote: > > it was tons of fun. > here's some of that proc vs. lambda crapola we were talking about: > [2]http://samdanielson.com/2007/3/19/proc-new-vs-lambda-in-ruby > nate -------------- next part -------------- #!/usr/bin/env ruby class Fixnum def max_times_until( procedure ) 1.upto(self) do |i| break if procedure.call yield i end end end class Time def seconds_later?(seconds) self + seconds < Time.now end end release = Time.new 100.max_times_until lambda { release.seconds_later?(3) } do |i| puts "doing something #{i}" sleep 1 end From steve.holder at gmail.com Thu Jun 14 11:01:45 2007 From: steve.holder at gmail.com (Steve Holder) Date: Thu, 14 Jun 2007 08:01:45 -0700 Subject: [Pasadenarb-general] great meeting tonight! In-Reply-To: <20070614021606.GA10522@xork.dyndns.org> References: <2e29f79d0706122254l459b77c4x35cf29327cddb9b8@mail.gmail.com> <7d2225580706131252i6d681cf7ye8f5766cd6e0dd2f@mail.gmail.com> <20070614014418.GA10439@xork.dyndns.org> <20070614015122.GB10439@xork.dyndns.org> <20070614021606.GA10522@xork.dyndns.org> Message-ID: <7d2225580706140801q2858ab54mb1146c764beedb5a@mail.gmail.com> Is this the kind of thing that would be better handled with a thread and timeout? Something along the lines of: t = Thread.new { ...do work here... } unless t.join(timeout) #thread didn't finish w/ in the timeout period, so do whatever you've got to do end It partly depends on what the work you're doing is - with ruby's threading model, if you're stuck in a system call control won't return to the ruby interpreter, in which case the timeout value won't be honored until the system call actually returns. But you avoid the overhead of constantly polling to see if you're done. Actually, I suppose you could even use Matt's approach and roll it into Fixnum: 100.seconds_max { ...do some stuff...} class Fixnum def seconds_max t = Thread.new { yield } unless t.join(self) #kill the thread, maybe, and raise an exception? end end end -Steve On 6/13/07, Matt Pulver wrote: > > Ok so I don't read emails and now I spam the list :) > > Maybe this is what you're looking for? > > 100.max_times_until do |i| > puts "doing something #{i}" > sleep 1 > release.seconds_later?(3) > end > > Put the boolean-valued method call last that determines when to exit, > which then becomes the return value of yield: > > class Fixnum > def max_times_until > 1.upto(self) do |i| > break if yield i > end > end > end > > Attached is a runnable demo. > > Matt > > > On Wed, Jun 13, 2007 at 06:51:22PM -0700, Matt Pulver wrote: > > As you can see I didn't read your entire email :) - adding a single > > lambda with 2 {}'s seems pretty clean to me... doesn't even add any > > extra lines. > > > > Matt > > > > > > On Wed, Jun 13, 2007 at 06:44:18PM -0700, Matt Pulver wrote: > > > Hi Nate, > > > > > > Nice exercise in higher-order procedures. Well thanks to your > > > talk last night, I think simply wrapping a lambda around the > > > release.successful? call should do the trick: > > > > > > 100.max_times_until lambda { release.successful? } do |i| > > > puts "doing something #{i}" > > > sleep 1 > > > end > > > > > > where max_times_until is defined as: > > > > > > class Fixnum > > > def max_times_until( procedure ) > > > 1.upto(self) do |i| > > > break if procedure.call > > > yield i > > > end > > > end > > > end > > > > > > Attached is a script that tests this, by simply checking to see if 3 > > > seconds have passed. > > > > > > Matt > > > > > > > > > On Wed, Jun 13, 2007 at 01:04:46PM -0700, Nathan Murray wrote: > > > > > > > > Steve, I'd be interested in hearing about Jruby, I don't know > much > > > > about it. > > > > > > > > I have a ruby question for you guys. I'm working on > workers and > > > > managers like we were talking about last night. My workers > create > > > > "Releases" (each time the site needs to be pushed live a > Release is > > > > created). > > > > > > > > I want to loop over and check if the release is done. However, I > don't > > > > want to infinite loop, I only want to check it, say, maybe 100 > times. > > > > So I have the code like the following more than once: > > > > > > > > i = 0 > > > > until release.successful? || i >= 100 > > > > puts "doing something #{i}" > > > > i += 1 > > > > end > > > > It works okay, but I see this repetition and want to abstract it > out. > > > > "Fill in the slots" you might say. What I want is a rubyish way > to do > > > > this like > > > > 100.times do ... or 0.upto(100) etc. > > > > So my first attempt was something like > > > > > > > > 100.max_times_until release.successful? do |i| > > > > puts "doing something #{i}" > > > > end > > > > and max_time_until takes care of the iterator and yields i each > time. > > > > The problem is that "release.successful?" is evaluated at the > time its > > > > called and never again. So you never know if the status of the > release > > > > changed. The best I've come up with is to wrap " > release.successful?" > > > > in a lambda block. But this is a bit ugly. Can anyone think of > a way > > > > to give this a clean syntax and still achieve the desired effect? > > > > I've attached my Integer extension and a rails-runnable test. > > > > ====================== > > > > class Integer > > > > def max_times_until(predicate) > > > > i = 0 > > > > until predicate.call || i >= to_i > > > > yield i > > > > i +=1 > > > > end > > > > end > > > > end > > > > ========================= > > > > require File.dirname(__FILE__) + '/../../test_helper' > > > > class Incrementer > > > > attr_accessor :incrementer > > > > def initialize > > > > @incrementer = 0 > > > > end > > > > def successful? > > > > return true if @incrementer >= 5 > > > > @incrementer += 1 > > > > false > > > > end > > > > end > > > > class IntegerExtensionTest < Test::Unit::TestCase > > > > def test_max_times > > > > inc = Incrementer.new > > > > 10.max_times_until lambda { inc.successful? } do |i| > > > > puts "try #{i} (#{inc.incrementer})" > > > > end > > > > i = 0 > > > > until release.successful? || i >= 100 > > > > puts "doing something #{i}" > > > > i += 1 > > > > end > > > > end > > > > end > > > > > > > > On Jun 13, 2007, at 12:52 PM, Steve Holder wrote: > > > > > > > > Thanks for the link, Nate - until our discussion last > night, I > > > > hadn't realized there actually was a practical difference > between > > > > Proc.new & lambda. The video turned out better than I > expected - > > > > some of it is a bit blurry, but the audio is good. I'll > hopefully > > > > be able to post them in the next few days, for folks who > couldn't > > > > make it last night. > > > > I also realized we never discussed what to do at the next > meeting. > > > > Any volunteers for talks? Jruby hit 1.0 a couple days ago, I > could > > > > do a short presentation on that if anyone beside me is > interested. > > > > -Steve > > > > > > > > On 6/12/07, Nate Daiger <[1]nate at heydsg.com> wrote: > > > > > > > > it was tons of fun. > > > > here's some of that proc vs. lambda crapola we were talking > about: > > > > [2]http://samdanielson.com/2007/3/19/proc-new-vs-lambda-in-ruby > > > > nate > > > > > #!/usr/bin/env ruby > > > > > > class Fixnum > > > def max_times_until( procedure ) > > > 1.upto(self) do |i| > > > break if procedure.call > > > yield i > > > end > > > end > > > end > > > > > > class Time > > > def seconds_later?(seconds) > > > self + seconds < Time.now > > > end > > > end > > > > > > release = Time.new > > > > > > 100.max_times_until lambda { release.seconds_later?(3) } do |i| > > > puts "doing something #{i}" > > > sleep 1 > > > end > > > > _______________________________________________ > > Pasadenarb-general mailing list > > Pasadenarb-general at rubyforge.org > > http://rubyforge.org/mailman/listinfo/pasadenarb-general > > _______________________________________________ > Pasadenarb-general mailing list > Pasadenarb-general at rubyforge.org > http://rubyforge.org/mailman/listinfo/pasadenarb-general > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/pasadenarb-general/attachments/20070614/03581262/attachment.html From steve.holder at gmail.com Tue Jun 19 00:47:32 2007 From: steve.holder at gmail.com (Steve Holder) Date: Mon, 18 Jun 2007 21:47:32 -0700 Subject: [Pasadenarb-general] Videos from last week Message-ID: <7d2225580706182147y60c4a674m8f5af6f6f0b3ced5@mail.gmail.com> Hey everyone- I've just posted the first of the videos from last week, Nate Murray's talk on higher order procedures. Its on http://www.pasadenarb.com, you can also grab it directly from Google Video at http://video.google.com/videoplay?docid=7579034415589180412. The talk from Nate and Jason is a bit longer, I should have it up later this week. -Steve -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/pasadenarb-general/attachments/20070618/6ff896e1/attachment-0001.html From nate at natemurray.com Tue Jun 19 11:33:31 2007 From: nate at natemurray.com (Nathan Murray) Date: Tue, 19 Jun 2007 08:33:31 -0700 Subject: [Pasadenarb-general] Videos from last week In-Reply-To: <7d2225580706182147y60c4a674m8f5af6f6f0b3ced5@mail.gmail.com> References: <7d2225580706182147y60c4a674m8f5af6f6f0b3ced5@mail.gmail.com> Message-ID: Awesome! Steve, thanks so much for taking the time to do this. -Nate On Jun 18, 2007, at 9:47 PM, Steve Holder wrote: > Hey everyone- > I've just posted the first of the videos from last week, Nate > Murray's talk on higher order procedures. Its on http:// > www.pasadenarb.com, you can also grab it directly from Google Video > at http://video.google.com/videoplay?docid=7579034415589180412. > > The talk from Nate and Jason is a bit longer, I should have it up > later this week. > > -Steve -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/pasadenarb-general/attachments/20070619/4751bb25/attachment.html From nate at natemurray.com Mon Jun 25 19:19:15 2007 From: nate at natemurray.com (Nathan Murray) Date: Mon, 25 Jun 2007 16:19:15 -0700 Subject: [Pasadenarb-general] great meeting tonight! In-Reply-To: <7d2225580706140801q2858ab54mb1146c764beedb5a@mail.gmail.com> References: <2e29f79d0706122254l459b77c4x35cf29327cddb9b8@mail.gmail.com> <7d2225580706131252i6d681cf7ye8f5766cd6e0dd2f@mail.gmail.com> <20070614014418.GA10439@xork.dyndns.org> <20070614015122.GB10439@xork.dyndns.org> <20070614021606.GA10522@xork.dyndns.org> <7d2225580706140801q2858ab54mb1146c764beedb5a@mail.gmail.com> Message-ID: <309F7195-6777-4067-A6D5-0DB8D9BF7EF5@natemurray.com> Guys, thanks for the creative solutions to the timeout problem earlier. I just discovered that there is a standard "timeout" library that was right up my alley. I decided I would share my solution with you guys: #!/usr/bin/env ruby require 'timeout' class FinishedWithNoProblem < StandardError #:nodoc: end max_time = 5 # seconds [6, 3].each do |running_time| before = Time.now begin puts "Will finish in #{running_time}" status = Timeout.timeout(max_time) do loop do raise FinishedWithNoProblem if Time.now-before >= running_time $stdout.print "." $stdout.flush sleep(0.3) end end rescue Timeout::Error puts "Timed out (#{Time.now-before})" rescue FinishedWithNoProblem puts "We're done! (#{Time.now-before})" end end On Jun 14, 2007, at 8:01 AM, Steve Holder wrote: > Is this the kind of thing that would be better handled with a > thread and timeout? Something along the lines of: > > t = Thread.new { ...do work here... } > unless t.join(timeout) > #thread didn't finish w/ in the timeout period, so do whatever > you've got to do > end > > It partly depends on what the work you're doing is - with ruby's > threading model, if you're stuck in a system call control won't > return to the ruby interpreter, in which case the timeout value > won't be honored until the system call actually returns. But you > avoid the overhead of constantly polling to see if you're done. > > Actually, I suppose you could even use Matt's approach and roll it > into Fixnum: > > 100.seconds_max { ...do some stuff...} > > class Fixnum > def seconds_max > t = Thread.new { yield } > unless t.join(self) > #kill the thread, maybe, and raise an exception? > end > end > end > > -Steve > > On 6/13/07, Matt Pulver < matt+pasadenarb at quantumlab.net> wrote: > Ok so I don't read emails and now I spam the list :) > > Maybe this is what you're looking for? > > 100.max_times_until do |i| > puts "doing something #{i}" > sleep 1 > release.seconds_later?(3) > end > > Put the boolean-valued method call last that determines when to exit, > which then becomes the return value of yield: > > class Fixnum > def max_times_until > 1.upto(self) do |i| > break if yield i > end > end > end > > Attached is a runnable demo. > > Matt > > > On Wed, Jun 13, 2007 at 06:51:22PM -0700, Matt Pulver wrote: > > As you can see I didn't read your entire email :) - adding a single > > lambda with 2 {}'s seems pretty clean to me... doesn't even add any > > extra lines. > > > > Matt > > > > > > On Wed, Jun 13, 2007 at 06:44:18PM -0700, Matt Pulver wrote: > > > Hi Nate, > > > > > > Nice exercise in higher-order procedures. Well thanks to your > > > talk last night, I think simply wrapping a lambda around the > > > release.successful? call should do the trick: > > > > > > 100.max_times_until lambda { release.successful? } do |i| > > > puts "doing something #{i}" > > > sleep 1 > > > end > > > > > > where max_times_until is defined as: > > > > > > class Fixnum > > > def max_times_until( procedure ) > > > 1.upto(self) do |i| > > > break if procedure.call > > > yield i > > > end > > > end > > > end > > > > > > Attached is a script that tests this, by simply checking to see > if 3 > > > seconds have passed. > > > > > > Matt > > > > > > > > > On Wed, Jun 13, 2007 at 01:04:46PM -0700, Nathan Murray wrote: > > > > > > > > Steve, I'd be interested in hearing about Jruby, I > don't know much > > > > about it. > > > > > > > > I have a ruby question for you guys. I'm working on > workers and > > > > managers like we were talking about last night. My > workers create > > > > "Releases" (each time the site needs to be pushed live > a Release is > > > > created). > > > > > > > > I want to loop over and check if the release is done. > However, I don't > > > > want to infinite loop, I only want to check it, say, > maybe 100 times. > > > > So I have the code like the following more than once: > > > > > > > > i = 0 > > > > until release.successful? || i >= 100 > > > > puts "doing something #{i}" > > > > i += 1 > > > > end > > > > It works okay, but I see this repetition and want to > abstract it out. > > > > "Fill in the slots" you might say. What I want is a > rubyish way to do > > > > this like > > > > 100.times do ... or 0.upto(100) etc. > > > > So my first attempt was something like > > > > > > > > 100.max_times_until release.successful? do |i| > > > > puts "doing something #{i}" > > > > end > > > > and max_time_until takes care of the iterator and yields i > each time. > > > > The problem is that "release.successful?" is evaluated at > the time its > > > > called and never again. So you never know if the status of > the release > > > > changed. The best I've come up with is to wrap " > release.successful?" > > > > in a lambda block. But this is a bit ugly. Can anyone > think of a way > > > > to give this a clean syntax and still achieve the desired > effect? > > > > I've attached my Integer extension and a rails-runnable test. > > > > ====================== > > > > class Integer > > > > def max_times_until(predicate) > > > > i = 0 > > > > until predicate.call || i >= to_i > > > > yield i > > > > i +=1 > > > > end > > > > end > > > > end > > > > ========================= > > > > require File.dirname(__FILE__) + '/../../test_helper' > > > > class Incrementer > > > > attr_accessor :incrementer > > > > def initialize > > > > @incrementer = 0 > > > > end > > > > def successful? > > > > return true if @incrementer >= 5 > > > > @incrementer += 1 > > > > false > > > > end > > > > end > > > > class IntegerExtensionTest < Test::Unit::TestCase > > > > def test_max_times > > > > inc = Incrementer.new > > > > 10.max_times_until lambda { inc.successful? } do |i| > > > > puts "try #{i} (#{inc.incrementer})" > > > > end > > > > i = 0 > > > > until release.successful? || i >= 100 > > > > puts "doing something #{i}" > > > > i += 1 > > > > end > > > > end > > > > end > > > > > > > > On Jun 13, 2007, at 12:52 PM, Steve Holder wrote: > > > > > > > > Thanks for the link, Nate - until our discussion > last night, I > > > > hadn't realized there actually was a practical > difference between > > > > Proc.new & lambda. The video turned out better than > I expected - > > > > some of it is a bit blurry, but the audio is good. > I'll hopefully > > > > be able to post them in the next few days, for folks > who couldn't > > > > make it last night. > > > > I also realized we never discussed what to do at the > next meeting. > > > > Any volunteers for talks? Jruby hit 1.0 a couple days > ago, I could > > > > do a short presentation on that if anyone beside me is > interested. > > > > -Steve > > > > > > > > On 6/12/07, Nate Daiger <[1]nate@ heydsg.com> wrote: > > > > > > > > it was tons of fun. > > > > here's some of that proc vs. lambda crapola we were > talking about: > > > > [2]http://samdanielson.com/2007/3/19/proc-new-vs-lambda- > in-ruby > > > > nate > > > > > #!/usr/bin/env ruby > > > > > > class Fixnum > > > def max_times_until( procedure ) > > > 1.upto(self) do |i| > > > break if procedure.call > > > yield i > > > end > > > end > > > end > > > > > > class Time > > > def seconds_later?(seconds) > > > self + seconds < Time.now > > > end > > > end > > > > > > release = Time.new > > > > > > 100.max_times_until lambda { release.seconds_later?(3) } do |i| > > > puts "doing something #{i}" > > > sleep 1 > > > end > > > > _______________________________________________ > > Pasadenarb-general mailing list > > Pasadenarb-general at rubyforge.org > > http://rubyforge.org/mailman/listinfo/pasadenarb-general > > _______________________________________________ > Pasadenarb-general mailing list > Pasadenarb-general at rubyforge.org > http://rubyforge.org/mailman/listinfo/pasadenarb-general > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/pasadenarb-general/attachments/20070625/16ebd73d/attachment-0001.html From steve.holder at gmail.com Wed Jun 27 23:12:26 2007 From: steve.holder at gmail.com (Steve Holder) Date: Wed, 27 Jun 2007 20:12:26 -0700 Subject: [Pasadenarb-general] Foreman Video Message-ID: <7d2225580706272012l872df0dk8c70757d1348612d@mail.gmail.com> Hey everyone- I finally was able to get the video of Nate and Jason discussing Foreman posted. Its on the blog - http://www.pasadenarb.com, and here's the direct link: http://video.google.com/videoplay?docid=-377149344549775862&hl=en -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/pasadenarb-general/attachments/20070627/40468699/attachment.html