spread your best code-snippets

M

M. Edward (Ed) Borasky

Christian said:
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 :).
 
M

Matt Todd

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.
 
A

ara.t.howard

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
 
D

Daniel Baird

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
 
L

Logan Capaldo

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




 
E

Eric Armstrong

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!
 
J

John Gabriele

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/Cookbook/

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
 
L

Leslie Viljoen

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

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
 
R

Rob Sanheim

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?

The increasing amount of snippet sites is pretty annoying. There is
now programmingishard, the big bold site, and the rails tips site from
techno weenie, and a couple others I'm sure I'm missing.

I also find that all of these sites lack any sort of good search. How
can I easily find all snippets matching "ruby" and "metaprogramming"
at the big bold site? How about everything "rails" and "activerecord"
but not "rhtml" or "view"? Just having a bulk listing of the 500 ruby
snippets or whatever is not very helpful...

- Rob
 
D

Daniel Higginbotham

I'd add 5. dont be textsnippets.com - has anyone noticed that it looks just
like programmingishard.com, only with a worse design because of the google
ads? :)

One thing I'd like to see is a "snippet a day" or "tip a day" site to help
with my morning procrastination ritual.

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/Cookbook/

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
 
E

Ezra Zygmuntowicz

Actually the bigbold snippets site was written by Peter Cooper is an
open source rails app. Both textsnippets and programmingishard both
are using the same open code from bigbold.

-Ezra
 
E

Eric Armstrong

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

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

1. Keep the snippets categorized for easy browsing.
That right there is the really hard part! Everything
after that is a piece of cake.

The problem is compounded by the fact that a good
snippet library nests. One snippet will show basic
file reading, another will show a regular expression
pattern, and a third will integrate both of them into
a snippet that does some useful task.

Then there is the synonym issue. Snippets are a great
way to answer the "how do I do that?" question, and
a snippet library is easily searched when you know the
keywords you're looking for.

But when you don't know the keywords in advance, the
library needs a synonym generation mechanism (so they
get included in snippet comments) or a translation
mechanism, so people coming from different languages
will find the different ways Ruby uses to carry out
familiar tasks.

It's one /terrific/ AI project. I would think that a
paper on "how to do it right" would make a great thesis.
 
E

Eric Armstrong

Daniel said:
One thing I'd like to see is a "snippet a day" or "tip a day" site to help
with my morning procrastination ritual.
LOL. THAT would be a great way to get a painless education.
 
D

Daniel Baird

same, here.. for certain definitions of the word "help" :)

Absolutely . . . as long as the snippets came with concise, but
thorough, explanations.

Yes yes! That's the thing that turns a "curious looking" snippet into
a "teaching something" snippet.

;Daniel
 
C

Chad Perrin

same, here.. for certain definitions of the word "help" :)



Yes yes! That's the thing that turns a "curious looking" snippet into
a "teaching something" snippet.

I could, perhaps, contribute a mailing list and editing if I can get
others to contribute snippets and explanations.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top