Categories
technology

p2(very small)p

This is getting ridiculous. Following my recent post about Ed Shelton’s P2P program in 15 lines of Perl there’s been a P2P app done in 9 lines of Perl and now (wait for it) a full peer-2-peer application in 6 lines of Ruby with a 3 lines of comments.
Just to show everybody how nuts this has become the code is reproduced below…
# Server: ruby p2p.rb password server server-uri merge-servers
# Sample: ruby p2p.rb foobar server druby://localhost:1337 druby://foo.bar:1337
# Client: ruby p2p.rb password client server-uri download-pattern
# Sample: ruby p2p.rb foobar client druby://localhost:1337 *.rb
require'drb';F,D,C,P,M,U,*O=File,Class,Dir,*ARGV;def s(p)F.split(p[/[^|].*/])[-1
]end;def c(u);DRbObject.new((),u)end;def x(u)[P,u].hash;end;M=="client"&&c(U).f(
x(U)).each{|n|p,c=x(n),c(n);(c.f(p,O[0],0).map{|f|s f}-D["*"]).each{|f|F.open(f,
"w"){|o|o<<c.f(p,f,1)}}}||(DRb.start_service U,C.new{def f(c,a=[],t=2)c==x(U)&&(
t==0&&D[s(a)]||t==1&&F.read(s(a))||p(a))end;def y()(p(U)+p).each{|u|c(u).f(x(u),
p(U))rescue()};self;end;private;def p(x=[]);O.push(*x).uniq!;O;end}.new.y;sleep)

I think I’ve had more than enough of this. Pick a suitably high-level language, use single character variable names and some whacky formatting to exchange a file over a socket and call it P2P. Next someone is gonna write a java programme using SUN’s JXTA that just inits a class or two, format it all on about 4 lines and say, wow it’s the shortest P2P app ever… More interesting would be a P2P application written in a declarative language like Prolog or a functional language like Haskell or Hope. Haven’t done much Haskell programming in a while (damn rusty and for some reason don’t feel like breaking out the books) but prolog looks tempting. Expect a post. I may have to use some file IO/socket programming but it sounds like an interesting project. I’ll let readers know how I get on 😉