aboutsummaryrefslogblamecommitdiffstats
path: root/toys/brhute-rb/pphidden.rb
blob: b6058db7d619a0a8ecabc8b9eadadd4513c05c12 (plain) (tree)


























































                                                                          
#require 'brhute'
#require 'derb'

# XXX how to make this a nice iterator ? change context of a Fiber is hard
class Pp_iter
    include Enumerable
    def initialize(image, sx=0, sy=0, mx=100, my=100)
        @domain = "www.pointerpointer.com"
        @baseurl = "images/"
        @image, @sx, @sy, @mx, @my = image, sx, sy, mx, my
        @x, @y = sx, sy
    end
    def next
        url = "%s/%s/N%0.4d_%d_%d.jpg" % \
            [@domain, @baseurl, @image, @x, @y]
        @y += 1
        if @y > @my
            @y = 0
            @x += 1
            if @x > @mx
                raise(StopIteration.new("iteration reached an end"))
            end
        end
        return url
    end
    def subset
        # XXX we are redoing 1 time the same url
        x, y = @x, @y
        @x = mx = x + [@mx - x, 10].min
        @y = my = y + [@my - y, 10].min
        puts "XXX subset %d %d %d %d" % [x, y, mx, my]
        Pp_iter.new(@image, x, y, mx, my)
    end
end

def test_iter
    Pp_iter.new(73, 0, 0).next do |url|
        puts url
    end
end
def test_iter_subset
    i = Pp_iter.new(73, 0, 0)
    puts i.next
    puts i.next
    puts "SUB"
    s = i.subset
    puts s.next
    puts s.next
    puts "MAIN"
    puts i.next
    puts i.next
end

#urls = Pp_iter(73, 0, 0)
#brhute::Brhute_ip(urls)

# Distributed Execution for Ruby:
# de = derb.run_on_hosts(['_g', '_sd'])
# de.execute(Pphidden, urls.subset)