[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

spread your best code-snippets

naPOLeon

8/2/2006 2:53:00 PM

I just ran over a nice code-snippet online-database: 'Programming is
Hard' at http://programmingi...

So let's spread our best Ruby-Code to help the others out there to
improve their code.

18 Answers

Christian Neukirchen

8/2/2006 6:47:00 PM

0

"naPOLeon" <naPOLeon.Polzer@gmx.de> writes:

> I just ran over a nice code-snippet online-database: 'Programming is
> Hard' at http://programmingi...
>
> So let's spread our best Ruby-Code to help the others out there to
> improve their code.

This is the third kind of snippet site I see today---they all look the
same. Wouldn't it be more effective to unify them?

--
Christian Neukirchen <chneukirchen@gmail.com> http://chneuk...

M. Edward (Ed) Borasky

8/3/2006 1:45:00 AM

0

Christian Neukirchen wrote:
> This is the third kind of snippet site I see today---they all look the
> same. Wouldn't it be more effective to unify them?
>
Hmpf ... I spend whole *days* writing code snippets and never get a
chance to assemble and refactor them into real software :).




Matt Todd

8/3/2006 3:49:00 AM

0

Yes, but that means those people would need to become unified, but I
somehow think that, at the genesis of these competing sites, they've
become, themselves, competitors, and possibly unable to unify in that
regard.

So, you are faced with an awkward decision: use none or make your own
that will become the defacto.

Hmmm, and neither of those really work, do they? (Despite your clout.)

But, you're right, I'd like them to be unified as well.

M.T.

Ara.T.Howard

8/3/2006 4:02:00 AM

0

Daniel Baird

8/3/2006 4:03:00 AM

0

On 8/3/06, Matt Todd <chiology@gmail.com> wrote:
>
> So, you are faced with an awkward decision: use none or make your own
> that will become the defacto.

Or, kludge up something that uses those other sites as backends, so
you can search all the clip sites from a single interface.

This is the Ruby list after all, right?

;D

--
Daniel Baird
http://tidd... (free, effortless TiddlyWiki hosting)
http://danie... (TiddlyW;nks! :: Whiteboard Koala :: Blog ::
Things That Suck)

Matt Todd

8/3/2006 4:08:00 AM

0

A mashup of snippets. Makes me drool in fright! :)

Logan Capaldo

8/3/2006 1:15:00 PM

0


On Aug 3, 2006, at 12:01 AM, ara.t.howard@noaa.gov wrote:

> On Thu, 3 Aug 2006, Matt Todd wrote:
>
>> Yes, but that means those people would need to become unified, but I
>> somehow think that, at the genesis of these competing sites, they've
>> become, themselves, competitors, and possibly unable to unify in that
>> regard.
>>
>> So, you are faced with an awkward decision: use none or make your own
>> that will become the defacto.
>>
>> Hmmm, and neither of those really work, do they? (Despite your
>> clout.)
>>
>> But, you're right, I'd like them to be unified as well.
>>
>> M.T.
>
> long ago i suggested the subject line [SNIPPET] for postings to
> comp.lang.ruby
> - google already indexes it - it would at least be a single unified
> space.
>
> -a

This is an idea I like. So in honor of the fact that I stole the
format for this script from you ara, I'd like to present my favorite
little script / snippet, rbmlexample:

Usage: ruby rblmlexample.rb <somefile.rb> [ arguments for somefile.rb ]
It copies the results of running somefile.rb and also somefile.rb to
the clipboard on Mac OS X (In ara's style of cat blah.rb ruby
blah.rb), where you can then paste it into a ruby talk email.

It's dependent on pbcopy, but I imagine a little search and replace
could adapt it for xclip. In retrospect this is probably a bit too
long to be a snippet. Ah well.



% cat rbmlexample.rb
#!/usr/bin/env ruby
$VERBOSE = true
begin
file_name = ARGV.shift or raise 'You need to supply a file name'
IO.popen('pbcopy', 'r+') do |clipboard|
clipboard.puts "% cat #{file_name}"

file_src = nil
File.open(file_name) do |source_code|
file_src = source_code.read
end
clipboard.puts file_src

clipboard.puts ''

ruby_res = nil
IO.popen('ruby 2>&1', 'r+') do |ruby|
ruby.puts 'STDOUT.sync = true'
ruby.puts %Q{
begin
old_verbose = $VERBOSE
$VERBOSE = nil
ARGV = #{ARGV.inspect}
ensure
$VERBOSE = old_verbose
end
}
ruby.puts file_src
ruby.close_write
ruby_res = ruby.read
end
clipboard.puts "% ruby #{file_name}"
clipboard.puts ruby_res
end
rescue => ex
STDERR.puts "#{File.basename($0)}: error: #{ex.message}"
end





> --
> we can never obtain peace in the outer world until we make peace with
> ourselves.
> - h.h. the 14th dali lama
>


Eric Armstrong

8/3/2006 11:19:00 PM

0

ara.t.howard@noaa.gov wrote:
> On Thu, 3 Aug 2006, Matt Todd wrote:
>
> long ago i suggested the subject line [SNIPPET] for postings to
> comp.lang.ruby
> - google already indexes it - it would at least be a single unified space.
>
Terrific suggestion!


jmg3000

8/4/2006 6:15:00 AM

0

On 8/2/06, Christian Neukirchen <chneukirchen@gmail.com> wrote:
> "naPOLeon" <naPOLeon.Polzer@gmx.de> writes:
>
> > I just ran over a nice code-snippet online-database: 'Programming is
> > Hard' at http://programmingi...
> >
> > So let's spread our best Ruby-Code to help the others out there to
> > improve their code.
>
> This is the third kind of snippet site I see today---they all look the
> same. Wouldn't it be more effective to unify them?

ActiveState does this for a number of languages:
http://aspn.activestate.com/ASPN...

The keys to making this work really well, I would think, would be:

1. Keep the snippets categorized for easy browsing.

2. Provide a means for users to comment on the snippets (since they
may want to provide corrections or alternatives).

3. Explicitly specify the terms by which all the snippets will be made
available (public domain might make the most sense here).

4. Provide a link to download all snippets in a tar.gz file. (Oooh --
maybe even including the user comments as separate text files... [muah
ha ha ha!])

Might make a great but simple RoR project for some scrappy Rubyist pup!

---John

Leslie Viljoen

8/4/2006 1:08:00 PM

0

On 8/2/06, naPOLeon <naPOLeon.Polzer@gmx.de> wrote:
> I just ran over a nice code-snippet online-database: 'Programming is
> Hard' at http://programmingi...
>
> So let's spread our best Ruby-Code to help the others out there to
> improve their code.

I have snippets on my wiki, but programmingishard.com is much cooler.
In fact it's very cool, and I say COOL WINS! I'm going to put all my
snippets there!

L