Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS 

Simple output of date in perl

// Simple output of current date in perl

  my @day_name = ("Sun.","Mon.","Tue.","Wed.","Thu.","Fri.","Sat.");
  my ($sec,$min,$hour,$mday,$mon,$year,$wday); 
  ($sec,$min,$hour,$mday,$mon,$year,$wday,undef,undef)=localtime(time()); $year+=1900;$mon++;
  $report_date=sprintf("%s %04d.%02d.%02d %02d:%02d",$day_name[$wday],$year,$mon,$mday,$hour,$min);

Get the currently running method name in Ruby

from: http://www.ruby-forum.com/topic/75258

Author: Robert Klemme



module Kernel
 private
    def this_method_name
      caller[0] =~ /`([^']*)'/ and $1
    end
end


class Foo
 def test_method
   this_method_name
 end
end

puts Foo.new.test_method    # => test_method

link_to_remote_unless_current

// Full discussion about this available at:
// http://6brand.com/articles/2006/06/07/link_to_remote_unless_current

# throw this in one of your controller helpers.
# it works just like a combination of link_to_unless_current and link_to_remote
def link_to_remote_unless_current(name, options = {}, html_options = {}, *parameters_for_method_reference, &block)
  if current_page?(options[:url])
    if block_given?
      block.arity <= 1 ? yield(name) : yield(name, remote_function(options), html_options, *parameters_for_method_reference)
    else
      name
    end
  else
    link_to_function(name, remote_function(options), html_options)
  end
end
« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS