Spread your best code-snippets

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.

“naPOLeon” [email protected] writes:

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.

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 N. 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 :).

On Thu, 3 Aug 2006, Matt T. wrote:

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

On 8/3/06, Matt T. [email protected] 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

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

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.

On 8/3/06, Matt T. [email protected] wrote:

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

Strange I had exactly the same feeling, but lacked the courage to say so.
But I have the courage to omit the smiley :slight_smile:

Robert


Deux choses sont infinies : l’univers et la bêtise humaine ; en ce qui
concerne l’univers, je n’en ai pas acquis la certitude absolue.

  • Albert Einstein

On Aug 3, 2006, at 12:01 AM, [email protected] wrote:

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

-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

On 8/2/06, Christian N. [email protected] wrote:

“naPOLeon” [email protected] writes:

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.

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

On 8/2/06, naPOLeon [email protected] wrote:

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

[email protected] wrote:

On Thu, 3 Aug 2006, Matt T. 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!

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? :slight_smile:

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

On 8/2/06, Christian N. [email protected] wrote:


Christian N. [email protected] http://chneukirchen.org

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
Actually the bigbold snippets site was written by Peter C. is an

open source rails app. Both textsnippets and programmingishard both
are using the same open code from bigbold.

-Ezra

Daniel H. wrote:

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.

John G. wrote:

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.

On Sun, Aug 13, 2006 at 12:16:29PM +0900, Eric A. wrote:

Daniel H. wrote:

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.

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

On Sun, Aug 13, 2006 at 09:20:44PM +0900, Daniel B. wrote:

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.

Daniel H. wrote:

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

same, here… for certain definitions of the word “help” :slight_smile:

On 8/13/06, Chad P. [email protected] wrote:

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs