Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
P2P application in 15 lines of Python posted on slashdot
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  19 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
slonik AZ  
View profile  
 More options Dec 15 2004, 6:41 pm
Newsgroups: comp.lang.ruby
From: slonik AZ <slonik...@gmail.com>
Date: Thu, 16 Dec 2004 08:41:13 +0900
Local: Wed, Dec 15 2004 6:41 pm
Subject: P2P application in 15 lines of Python posted on slashdot
Hi Everybody,
slashdot published an article on someone's
15 lines long Peer-2-Peer application
http://developers.slashdot.org/article.pl?sid=04/12/15/1953227

Another person followed up with a 9 line equivalent Perl code.

I wonder what an equivalent Ruby program would look like?

I do not care whether it 15 or 25 lines. Python program is not very readable.
Can Ruby variant be concise, yet more clear?

--Leo--


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Giovanni Intini  
View profile  
 More options Dec 15 2004, 6:53 pm
Newsgroups: comp.lang.ruby
From: Giovanni Intini <inti...@gmail.com>
Date: Thu, 16 Dec 2004 08:53:49 +0900
Local: Wed, Dec 15 2004 6:53 pm
Subject: Re: P2P application in 15 lines of Python posted on slashdot
I was going to post the same message :)
Good rubyists unite! (I'm not good :( ). Let's write a short more
understandable program!

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Purple Meteor  
View profile  
 More options Dec 15 2004, 8:11 pm
Newsgroups: comp.lang.ruby
From: Purple Meteor <purple.met...@gmail.com>
Date: Thu, 16 Dec 2004 10:11:15 +0900
Local: Wed, Dec 15 2004 8:11 pm
Subject: Re: P2P application in 15 lines of Python posted on slashdot
On Thu, 16 Dec 2004 08:53:49 +0900, Giovanni Intini <inti...@gmail.com> wrote:
> Let's write a short more understandable program!

Actually, someone answered with a web server written in only 3 lines of codes.
More info here: http://tinyurl.com/6lxpa

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michael DeHaan  
View profile  
 More options Dec 15 2004, 8:19 pm
Newsgroups: comp.lang.ruby
From: Michael DeHaan <michael.deh...@gmail.com>
Date: Thu, 16 Dec 2004 10:19:59 +0900
Local: Wed, Dec 15 2004 8:19 pm
Subject: Re: P2P application in 15 lines of Python posted on slashdot
LOL.   The Python example used quite a few core libraries, so I think
a one-line instantiation of WebBRICK would suffice for a web server
example :)

Seriously, these golf competitions don't do much for me.   Show me
formatted code that applies some interesting algorithms instead.  
That's how you spar with other languages!

On Thu, 16 Dec 2004 10:11:15 +0900, Purple Meteor


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
gabriele renzi  
View profile  
 More options Dec 16 2004, 2:08 am
Newsgroups: comp.lang.ruby
From: gabriele renzi <rff_...@remove-yahoo.it>
Date: Thu, 16 Dec 2004 07:08:59 GMT
Local: Thurs, Dec 16 2004 2:08 am
Subject: Re: P2P application in 15 lines of Python posted on slashdot
Michael DeHaan ha scritto:

> LOL.   The Python example used quite a few core libraries, so I think
> a one-line instantiation of WebBRICK would suffice for a web server
> example :)

ruby -rwebrick -e 'WEBrick::HTTPServer.new(:DocumentRoot=>".").start'
but it is a oneliner in python too ;)

> Seriously, these golf competitions don't do much for me.   Show me
> formatted code that applies some interesting algorithms instead.  
> That's how you spar with other languages!

def qs(l)
  return [] if (x,*xs=*l).empty?
  less, more = xs.partition{|y| y < x}
  qs(less) + [x] + qs(more)
end

algoritm suggestions are welcome :)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Nikolai Weibull  
View profile  
 More options Dec 16 2004, 4:51 am
Newsgroups: comp.lang.ruby
From: Nikolai Weibull <mailing-lists.ruby-t...@rawuncut.elitemail.org>
Date: Thu, 16 Dec 2004 18:51:38 +0900
Local: Thurs, Dec 16 2004 4:51 am
Subject: Re: P2P application in 15 lines of Python posted on slashdot
* gabriele renzi <rff_...@remove-yahoo.it> [Dec 16, 2004 10:30]:

> def qs(l)
>  return [] if (x,*xs=*l).empty?
>  less, more = xs.partition{|y| y < x}
>  qs(less) + [x] + qs(more)
> end
> algoritm suggestions are welcome :)

How about

def qs(l)
  l.sort!
end

;-),
        nikolai

--
::: name: Nikolai Weibull    :: aliases: pcp / lone-star / aka :::
::: born: Chicago, IL USA    :: loc atm: Gothenburg, Sweden    :::
::: page: www.pcppopper.org  :: fun atm: gf,lps,ruby,lisp,war3 :::
main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Florian Gross  
View profile  
 More options Dec 16 2004, 6:39 am
Newsgroups: comp.lang.ruby
From: Florian Gross <f...@ccan.de>
Date: Thu, 16 Dec 2004 12:39:14 +0100
Local: Thurs, Dec 16 2004 6:39 am
Subject: Re: P2P application in 15 lines of Python posted on slashdot

slonik AZ wrote:
> slashdot published an article on someone's
> 15 lines long Peer-2-Peer application
> http://developers.slashdot.org/article.pl?sid=04/12/15/1953227

> Another person followed up with a 9 line equivalent Perl code.

> I wonder what an equivalent Ruby program would look like?

I did this 9.5 hours ago. Compared to the python one it is not
vulnerable to File stealing attacks (a client can request a file
../foobar and ~/foobar from the python server and will get it back
AFAIK) and 6 lines long. It is however vulnerable to the DRb style
.instance_eval exploits. I will fix this shortly, but I might have to
use 7 lines then.

[ p2p.rb < 1K ]
# 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)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Brian Schröder  
View profile  
 More options Dec 16 2004, 7:08 am
Newsgroups: comp.lang.ruby
From: Brian Schröder <r...@brian-schroeder.de>
Date: Thu, 16 Dec 2004 21:08:20 +0900
Local: Thurs, Dec 16 2004 7:08 am
Subject: Re: P2P application in 15 lines of Python posted on slashdot
On Thu, 16 Dec 2004 18:51:38 +0900

I hope sort is not implemented as quicksort ;)

Regards,

Brian

--
Brian Schröder
http://www.brian-schroeder.de/


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Nikolai Weibull  
View profile  
 More options Dec 16 2004, 8:16 am
Newsgroups: comp.lang.ruby
From: Nikolai Weibull <mailing-lists.ruby-t...@rawuncut.elitemail.org>
Date: Thu, 16 Dec 2004 22:16:48 +0900
Local: Thurs, Dec 16 2004 8:16 am
Subject: Re: P2P application in 15 lines of Python posted on slashdot
* Brian Schröder <r...@brian-schroeder.de> [Dec 16, 2004 13:10]:

> > How about
> > def qs(l)
> >   l.sort!
> > end
> I hope sort is not implemented as quicksort ;)

array.c:

static VALUE
sort_internal(ary)
    VALUE ary;
{
    qsort(RARRAY(ary)->ptr, RARRAY(ary)->len, sizeof(VALUE),
          rb_block_given_p()?sort_1:sort_2);
    return ary;

}

rb_ary_sort_bang(ary)
    VALUE ary;
{
    rb_ary_modify(ary);
    if (RARRAY(ary)->len > 1) {
        FL_SET(ary, ARY_TMPLOCK);       /* prohibit modification during sort */
        rb_ensure(sort_internal, ary, sort_unlock, ary);
    }
    return ary;

}

Just hope your systems qsort() is any good,
        nikolai

--
::: name: Nikolai Weibull    :: aliases: pcp / lone-star / aka :::
::: born: Chicago, IL USA    :: loc atm: Gothenburg, Sweden    :::
::: page: www.pcppopper.org  :: fun atm: gf,lps,ruby,lisp,war3 :::
main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
ts  
View profile  
 More options Dec 16 2004, 8:29 am
Newsgroups: comp.lang.ruby
From: ts <dec...@moulon.inra.fr>
Date: Thu, 16 Dec 2004 22:29:07 +0900
Local: Thurs, Dec 16 2004 8:29 am
Subject: Re: P2P application in 15 lines of Python posted on slashdot

>>>>> "N" == Nikolai Weibull <mailing-lists.ruby-t...@rawuncut.elitemail.org> writes:

N> Just hope your systems qsort() is any good,

uln% grep qsort util.h
void ruby_qsort _((void*, const int, const int, int (*)(), void*));
#define qsort(b,n,s,c,d) ruby_qsort(b,n,s,c,d)
uln%

Guy Decoux


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Florian Gross  
View profile  
 More options Dec 16 2004, 8:32 am
Newsgroups: comp.lang.ruby
From: Florian Gross <f...@ccan.de>
Date: Thu, 16 Dec 2004 14:32:32 +0100
Local: Thurs, Dec 16 2004 8:32 am
Subject: Re: P2P application in 15 lines of Python posted on slashdot

Here we go. Thanks to Mauricio Fernández for helping out with cutting
off a few important characters!

[ p2p.rb < 1K ]
#!/usr/bin/ruby
# 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,P,M,U,*O=File,Dir,*ARGV;def s(p)F.basename p[/\w.*/]end;def c u
DRbObject.new((),u)end;def x(u);[P,u].hash;end;M["c"]?c(U).f(x(U)).map{|n|p=x(n)
c=c(n);(c.f(p,O[0],0).map{|f|s f}-D["*"]).map{|f|open(f,"w")<<c.f(p,f,1)}}:(DRb.
start_service U,Class.new{def p(z=O)O.push(*z).uniq!;O;end;new.methods.map{|m|m[
/_[_t]/]||private(m)};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).map{|u|c(u).f(x(u),p(U))rescue()};self;end}.new.y;sleep)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Nikolai Weibull  
View profile  
 More options Dec 16 2004, 9:09 am
Newsgroups: comp.lang.ruby
From: Nikolai Weibull <mailing-lists.ruby-t...@rawuncut.elitemail.org>
Date: Thu, 16 Dec 2004 23:09:43 +0900
Local: Thurs, Dec 16 2004 9:09 am
Subject: Re: P2P application in 15 lines of Python posted on slashdot
* ts <dec...@moulon.inra.fr> [Dec 16, 2004 14:30]:

> > Just hope your systems qsort() is any good,
> uln% grep qsort util.h void ruby_qsort _((void*, const int, const int,
> int (*)(), void*)); #define qsort(b,n,s,c,d) ruby_qsort(b,n,s,c,d)

Then hope Ruby's implementation of qsort is any good ;-),
        nikolai

--
::: name: Nikolai Weibull    :: aliases: pcp / lone-star / aka :::
::: born: Chicago, IL USA    :: loc atm: Gothenburg, Sweden    :::
::: page: www.pcppopper.org  :: fun atm: gf,lps,ruby,lisp,war3 :::
main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Brian Schröder  
View profile  
 More options Dec 16 2004, 10:28 am
Newsgroups: comp.lang.ruby
From: Brian Schröder <r...@brian-schroeder.de>
Date: Fri, 17 Dec 2004 00:28:48 +0900
Local: Thurs, Dec 16 2004 10:28 am
Subject: Re: P2P application in 15 lines of Python posted on slashdot
On Thu, 16 Dec 2004 23:09:43 +0900

Nikolai Weibull <mailing-lists.ruby-t...@rawuncut.elitemail.org> wrote:
> * ts <dec...@moulon.inra.fr> [Dec 16, 2004 14:30]:
> > > Just hope your systems qsort() is any good,

> > uln% grep qsort util.h void ruby_qsort _((void*, const int, const int,
> > int (*)(), void*)); #define qsort(b,n,s,c,d) ruby_qsort(b,n,s,c,d)

> Then hope Ruby's implementation of qsort is any good ;-),
>    nikolai

So just out of interest, what kind of sort is ruby using?
(I could dig the sources, but I hope it will be an easy question for someone to
answer without spending too much time.)

Regards,

Brian

--
Brian Schröder
http://www.brian-schroeder.de/


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
why the lucky stiff  
View profile  
 More options Dec 16 2004, 11:26 am
Newsgroups: comp.lang.ruby
From: why the lucky stiff <ruby-t...@whytheluckystiff.net>
Date: Fri, 17 Dec 2004 01:26:14 +0900
Local: Thurs, Dec 16 2004 11:26 am
Subject: Re: P2P application in 15 lines of Python posted on slashdot

slonik AZ wrote:
>Hi Everybody,
>slashdot published an article on someone's
>15 lines long Peer-2-Peer application
>http://developers.slashdot.org/article.pl?sid=04/12/15/1953227

I am saddened that they failed to mention ducks.  Ducks, or, more
particularly, images of ducks, are the only legitimate payload in
peer-to-peer networks these days.  And, notice how I summarized this
point in less than 15 lines of text.  Christmas miracles abound, folks.

_why


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Nikolai Weibull  
View profile  
 More options Dec 16 2004, 11:35 am
Newsgroups: comp.lang.ruby
From: Nikolai Weibull <mailing-lists.ruby-t...@rawuncut.elitemail.org>
Date: Fri, 17 Dec 2004 01:35:31 +0900
Local: Thurs, Dec 16 2004 11:35 am
Subject: Re: P2P application in 15 lines of Python posted on slashdot
* Brian Schröder <r...@brian-schroeder.de> [Dec 16, 2004 16:30]:

> So just out of interest, what kind of sort is ruby using?  (I could
> dig the sources, but I hope it will be an easy question for someone to
> answer without spending too much time.)

Seems to be your standard memory-swap optimized quicksort, using its own
stack (i.e. no recursion), much like the one in glibc,
        nikolai

--
::: name: Nikolai Weibull    :: aliases: pcp / lone-star / aka :::
::: born: Chicago, IL USA    :: loc atm: Gothenburg, Sweden    :::
::: page: www.pcppopper.org  :: fun atm: gf,lps,ruby,lisp,war3 :::
main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
David G. Andersen  
View profile  
 More options Dec 16 2004, 2:57 pm
Newsgroups: comp.lang.ruby
From: "David G. Andersen" <d...@lcs.mit.edu>
Date: Fri, 17 Dec 2004 04:57:22 +0900
Local: Thurs, Dec 16 2004 2:57 pm
Subject: Re: P2P application in 15 lines of Python posted on slashdot
On Thu, Dec 16, 2004 at 10:37:13PM +0900, Florian Gross scribed:

> >I did this 9.5 hours ago. Compared to the python one it is not
> >vulnerable to File stealing attacks (a client can request a file
> >../foobar and ~/foobar from the python server and will get it back
> >AFAIK) and 6 lines long. It is however vulnerable to the DRb style
> >.instance_eval exploits. I will fix this shortly, but I might have to
> >use 7 lines then.

> Here we go. Thanks to Mauricio Fern?ndez for helping out with cutting
> off a few important characters!

Nice use of drb.

I wonder how long the same program would be in ruby if it implemented
the "tinyp2p" protocol instead of using drb. ;)

  -dave

--
work: d...@lcs.mit.edu                          me:  d...@pobox.com
      MIT Laboratory for Computer Science           http://www.angio.net/


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kaspar Schiess  
View profile  
 More options Dec 17 2004, 7:27 am
Newsgroups: comp.lang.ruby
From: Kaspar Schiess <e...@space.ch>
Date: Fri, 17 Dec 2004 21:27:40 +0900
Local: Fri, Dec 17 2004 7:27 am
Subject: Re: P2P application in 15 lines of Python posted on slashdot

> _why

No matter how much you might be off topic, I always enjoy reading your
posts. Another miracle lurking in the dark, there.

yours,  
kaspar


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Florian Gross  
View profile  
 More options Dec 17 2004, 4:53 pm
Newsgroups: comp.lang.ruby
From: Florian Gross <f...@ccan.de>
Date: Fri, 17 Dec 2004 22:53:19 +0100
Local: Fri, Dec 17 2004 4:53 pm
Subject: Re: P2P application in 15 lines of Python posted on slashdot

Florian Gross wrote:
> Here we go. Thanks to Mauricio Fernández for helping out with cutting
> off a few important characters!

Another new version, binary files can be transfered to and from Win32,
you can run servers from behind Routers and you can list all the files
on the specified network sorted by node and file name before downloading
them. Still six lines.

[ p2p.rb < 1K ]
#!/usr/bin/ruby
# Server: ruby p2p.rb password server public-uri private-uri merge-servers
# Sample: ruby p2p.rb foobar server druby://123.123.123.123:1337
#         druby://:1337 druby://foo.bar:1337
# Client: ruby p2p.rb password client server-uri download-pattern [list-only]
# Sample: ruby p2p.rb foobar client druby://localhost:1337 *.rb
########################################################################### #####
require'drb';F=File;P,M,U,V,*O=ARGV;def c(u)DRbObject.new((),u)end;def x(u);[P,u
].hash;end;def s(p);F.basename p[/[^|]+/];end;M["s"]?(DRb.start_service V,Class.
new{def p(z=O)O.push(*z).uniq;end;new.methods.map{|m|m[/_[_t]/]||private(m)};def
y;(p(U)+p).map{|u|u!=U&&c(u).f(x(u),p(U))};self;end;def f(c,a=[],t=2)x(U)==c&&t<
1?Dir[s(a)]:t<2?[*open(s(a),"rb")]:p(a)end}.new.y;sleep):c(U).f(x(U)).map{| n|c(n
).f(x(n),V,0).map{|f|s f}.sort.map{|f|O[0]?p(f):open(f,"wb")<<c(n).f(x(n),f,1)}}


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
thanhvn.i...@gmail.com  
View profile  
 More options Sep 10 2012, 4:19 am
Newsgroups: comp.lang.ruby
From: thanhvn.i...@gmail.com
Date: Mon, 10 Sep 2012 01:19:23 -0700 (PDT)
Local: Mon, Sep 10 2012 4:19 am
Subject: Re: P2P application in 15 lines of Python posted on slashdot
 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »