<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: name code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sat, 26 Jul 2008 11:57:22 GMT</pubDate>
    <description>DZone Snippets: name code</description>
    <item>
      <title>Get the name of the script that is running</title>
      <link>http://snippets.dzone.com/posts/show/3771</link>
      <description>&lt;code&gt;&lt;br /&gt;script-name: does [system/options/script]&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 05 Apr 2007 18:14:10 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3771</guid>
      <author>gregg.irwin (Gregg Irwin)</author>
    </item>
    <item>
      <title>Get the currently running method name in Ruby</title>
      <link>http://snippets.dzone.com/posts/show/2785</link>
      <description>from: http://www.ruby-forum.com/topic/75258&lt;br /&gt;&lt;br /&gt;Author:  Robert Klemme&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;br /&gt;module Kernel&lt;br /&gt; private&lt;br /&gt;    def this_method_name&lt;br /&gt;      caller[0] =~ /`([^']*)'/ and $1&lt;br /&gt;    end&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;class Foo&lt;br /&gt; def test_method&lt;br /&gt;   this_method_name&lt;br /&gt; end&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;puts Foo.new.test_method    # =&gt; test_method&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 05 Oct 2006 19:00:47 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2785</guid>
      <author>ntk ()</author>
    </item>
    <item>
      <title>Convert string to underscore_name</title>
      <link>http://snippets.dzone.com/posts/show/2681</link>
      <description>Converts "My House" to "my_house".&lt;br /&gt;Converts " Peter's nice car " to "peters_nice_car".&lt;br /&gt;Converts "_88" to "88"&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;function string_to_underscore_name($string)&lt;br /&gt;{&lt;br /&gt;    $string = preg_replace('/[\'"]/', '', $string);&lt;br /&gt;    $string = preg_replace('/[^a-zA-Z0-9]+/', '_', $string);&lt;br /&gt;    $string = trim($string, '_');&lt;br /&gt;    $string = strtolower($string);&lt;br /&gt;    &lt;br /&gt;    return $string;&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sat, 23 Sep 2006 17:52:55 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2681</guid>
      <author>stancell (Algimantas Stancelis)</author>
    </item>
    <item>
      <title>helper to determine if radio/checkbox needs to be checked</title>
      <link>http://snippets.dzone.com/posts/show/2559</link>
      <description>I frequently have to use methods such as 'radio_button' and 'check_box_tag' when I don't have an object with a method that will automatically determine the value of the input field.  Therefore, I have to check to see if a certain parameter has been passed, and if so, if the parameter's value matches that of the input's value.  This method does that.&lt;br /&gt;&lt;br /&gt;It's designed to be used in a Rails helper.  You can either pass it the object, method, and value (the same parameters as, for example, &lt;a href="http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#M000395"&gt;radio_button&lt;/a&gt;) or name and value (the same parameters as &lt;a href="http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#M000501"&gt;radio_button_tag&lt;/a&gt;).&lt;br /&gt;&lt;br /&gt;&lt;code&gt;def checked?( *args )&lt;br /&gt;  if args.length == 3&lt;br /&gt;    object, method, value = args&lt;br /&gt;    if params[object] &amp;&amp; params[object][method] &amp;&amp; params[object][method] == value&lt;br /&gt;      'checked'&lt;br /&gt;    end&lt;br /&gt;  elsif args.length == 2&lt;br /&gt;    name, value = args&lt;br /&gt;    if params[name] &amp;&amp; params[name] == value&lt;br /&gt;      true&lt;br /&gt;    end&lt;br /&gt;  end&lt;br /&gt;end&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Here's an example usage:&lt;br /&gt;&lt;code&gt;&lt;%= radio_button 'person', 'age', '12', :checked =&gt; checked?( 'person', 'age', '12' ) %&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;If params[:person][:age] exists and it equals '12', then 'checked?' returns 'checked'; otherwise, it returns nil.</description>
      <pubDate>Thu, 07 Sep 2006 16:25:27 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2559</guid>
      <author>moneypenny ()</author>
    </item>
    <item>
      <title>HTML 4.0 color names</title>
      <link>http://snippets.dzone.com/posts/show/1608</link>
      <description>There are 16 of them&lt;br /&gt;&lt;code&gt;&lt;br /&gt;Black  	#000000&lt;br /&gt;Silver 	#C0C0C0&lt;br /&gt;Gray 	#808080&lt;br /&gt;White 	#FFFFFF&lt;br /&gt;Maroon 	#800000&lt;br /&gt;Red 	#FF0000&lt;br /&gt;Purple 	#800080&lt;br /&gt;Fuchsia #FF00FF&lt;br /&gt;Green 	#008000&lt;br /&gt;Lime 	#00FF00&lt;br /&gt;Olive 	#808000&lt;br /&gt;Yellow 	#FFFF00&lt;br /&gt;Navy 	#000080&lt;br /&gt;Blue 	#0000FF&lt;br /&gt;Teal 	#008080&lt;br /&gt;Aqua 	#00FFFF&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;From &lt;a href=http://www.htmlhelp.com/reference/html40/values.html&gt;this page&lt;/a&gt;.</description>
      <pubDate>Wed, 01 Mar 2006 20:02:09 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1608</guid>
      <author>korakot (Korakot Chaovavanich)</author>
    </item>
    <item>
      <title>Converting Between Different Naming Convetions</title>
      <link>http://snippets.dzone.com/posts/show/739</link>
      <description>From Sami Hangaslammi's &lt;a href=http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66009&gt;recipe&lt;/a&gt;.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;import re&lt;br /&gt;&lt;br /&gt;def cw2us(x): # capwords to underscore notation&lt;br /&gt;    return re.sub(r'(?&lt;=[a-z])[A-Z]|(?&lt;!^)[A-Z](?=[a-z])', r"_\g&lt;0&gt;", x).lower()&lt;br /&gt;&lt;br /&gt;def mc2us(x): # mixed case to underscore notation&lt;br /&gt;    return cw2us(x)&lt;br /&gt;&lt;br /&gt;def us2mc(x): # underscore to mixed case notation&lt;br /&gt;    return re.sub(r'_([a-z])', lambda m: (m.group(1).upper()), x)&lt;br /&gt;&lt;br /&gt;def us2cw(x): # underscore to capwords notation&lt;br /&gt;    s = us2mc(x)&lt;br /&gt;    return s[0].upper()+s[1:]&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Result&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&gt;&gt;&gt; cw2us("PrintHTML")&lt;br /&gt;'print_html'&lt;br /&gt;&gt;&gt;&gt; cw2us("IOError")&lt;br /&gt;'io_error'&lt;br /&gt;&gt;&gt;&gt; cw2us("SetXYPosition")&lt;br /&gt;'set_xy_position'&lt;br /&gt;&gt;&gt;&gt; cw2us("GetX")&lt;br /&gt;'get_x'&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 18 Sep 2005 14:12:35 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/739</guid>
      <author>korakot (Korakot Chaovavanich)</author>
    </item>
  </channel>
</rss>
