<?xml version="1.0" encoding="UTF-8"?>
<rss version='2.0' xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule">
    <channel>
        <!-- This XML Feed shows details for the page Code Snippets: ruby -->
        <creativeCommons:license>http://creativecommons.org/licenses/by-sa/2.5/</creativeCommons:license>
        <title>Code Snippets: ruby</title>
        <link>http://swik.net/Ruby%2FCode+Snippets%3A+ruby</link>
        <description></description>
        
        <pubDate>Mon, 06 Jun 2005 23:12:32 -0700</pubDate>
        <lastBuildDate>Mon, 06 Jun 2005 23:13:29 -0700</lastBuildDate>
            
        <item>
            <title>Search and replace keywords within many files</title>
            <link>http://swik.net/Ruby/Code+Snippets%3A+ruby/Search+and+replace+keywords+within+many+files/cheag</link>
            <description># search and replace all text files in the temp directory replacing the word &#039;five&#039; with &#039;six&#039;
&lt;br/&gt;
&lt;br/&gt;&lt;code&gt;glob_path, exp_search, exp_replace = &#039;temp/*.txt&#039;,&#039;five&#039;, &#039;six&#039;
&lt;br/&gt;Dir.glob(glob_path).each do |file| 
&lt;br/&gt;  buffer = File.new(file,&#039;r&#039;).read.gsub(/#{exp_search}/,exp_replace)
&lt;br/&gt;  File.open(file,&#039;w&#039;) {|fw| fw.write(buffer)}
&lt;br/&gt;end&lt;/code&gt;
&lt;br/&gt;
&lt;br/&gt;output before:
&lt;br/&gt;
&lt;br/&gt;more t*.txt
&lt;br/&gt;::::::::::::::
&lt;br/&gt;t1.txt
&lt;br/&gt;::::::::::::::
&lt;br/&gt;123 five 789
&lt;br/&gt;::::::::::::::
&lt;br/&gt;t2.txt
&lt;br/&gt;::::::::::::::
&lt;br/&gt;123 four 6789
&lt;br/&gt;::::::::::::::
&lt;br/&gt;t3.txt
&lt;br/&gt;::::::::::::::
&lt;br/&gt;123 ... five five four three
&lt;br/&gt;
&lt;br/&gt;output after:
&lt;br/&gt;
&lt;br/&gt; more t*.txt
&lt;br/&gt;::::::::::::::
&lt;br/&gt;t1.txt
&lt;br/&gt;::::::::::::::
&lt;br/&gt;123 six 789
&lt;br/&gt;::::::::::::::
&lt;br/&gt;t2.txt
&lt;br/&gt;::::::::::::::
&lt;br/&gt;123 four 6789
&lt;br/&gt;::::::::::::::
&lt;br/&gt;t3.txt
&lt;br/&gt;::::::::::::::
&lt;br/&gt;123 ... six six four three
&lt;br/&gt;</description>
            
            <pubDate>Sat, 11 Oct 2008 15:43:52 -0700</pubDate>
        </item>
            
        <item>
            <title>Fun with grep in Ruby</title>
            <link>http://swik.net/Ruby/Code+Snippets%3A+ruby/Fun+with+grep+in+Ruby/chd65</link>
            <description># a basic string search
&lt;br/&gt;&lt;code&gt;&gt;&gt; f = &quot;fun sun dog&quot;
&lt;br/&gt;
&lt;br/&gt;&gt;&gt; puts f.grep(&#039;sun&#039;)
&lt;br/&gt;=&gt; nil
&lt;br/&gt;
&lt;br/&gt;&gt;&gt; puts f.grep(/sun/)
&lt;br/&gt;=&gt; fun sun dog
&lt;br/&gt;
&lt;br/&gt;&gt;&gt; f = &quot;fun Sun dog&quot;
&lt;br/&gt;
&lt;br/&gt;&gt;&gt; puts f.grep(/sun/i)  # case-insensistive
&lt;br/&gt;=&gt; fun Sun dog&lt;/code&gt;
&lt;br/&gt;
&lt;br/&gt;
&lt;br/&gt;# search a range of numbers in an array
&lt;br/&gt;&lt;code&gt;&gt;&gt; numbers = [1, 2, 3, 4, 5, 6, 8, 9]
&lt;br/&gt;&gt;&gt; numbers.grep(3..6)
&lt;br/&gt;=&gt; [3, 4, 5, 6]&lt;/code&gt;
&lt;br/&gt;
&lt;br/&gt;
&lt;br/&gt;# search a range of dates
&lt;br/&gt;&lt;code&gt;&gt;&gt; dates = [Date.new(2000, 1, 1), Date.new(2002, 2, 2), Date.new(2004, 3, 3), Date.new(2006, 4, 4)]
&lt;br/&gt;
&lt;br/&gt;=&gt; [&quot;2002-02-02&quot;, &quot;2004-03-03&quot;]&lt;/code&gt;
&lt;br/&gt;
&lt;br/&gt;
&lt;br/&gt;# searching for a base class
&lt;br/&gt;&lt;code&gt;&gt;&gt; class Base;end
&lt;br/&gt;=&gt; nil
&lt;br/&gt;&gt;&gt; class Child1 =&gt; nil
&lt;br/&gt;&gt;&gt; class Child2 =&gt; nil
&lt;br/&gt;&gt;&gt; class NotAChild;end
&lt;br/&gt;&gt;&gt; =&gt; nil
&lt;br/&gt;&gt;&gt; objects = [Child1.new, NotAChild.new, Child2.new]
&lt;br/&gt;=&gt; [#, #, #]
&lt;br/&gt;
&lt;br/&gt;&gt;&gt; objects.grep(Base)
&lt;br/&gt;=&gt; [#, #]&lt;/code&gt;
&lt;br/&gt;
&lt;br/&gt;
&lt;br/&gt;# search all Ruby files in the temp directory containing the word &#039;ruby&#039;
&lt;br/&gt;&lt;code&gt;exp_search =&#039;ruby&#039;
&lt;br/&gt;&gt;&gt; Dir.glob(&#039;temp/*.rb&#039;).each {|file| File.readlines(file).each {|l| l.grep(/#{exp_search}/).each {|r| puts file + &#039; : &#039; + r}} }
&lt;br/&gt;
&lt;br/&gt;temp/hello.rb : #!/usr/bin/ruby
&lt;br/&gt;temp/jabber_bot.rb : require &#039;rubygems&#039;
&lt;br/&gt;temp/jabber_bot.rb : require &#039;ruby-debug&#039;
&lt;br/&gt;=&gt; [&quot;temp/hello.rb&quot;, &quot;temp/jabber_bot.rb&quot;]&lt;/code&gt;
&lt;br/&gt;
&lt;br/&gt;Resource:
&lt;br/&gt; - &lt;a href=&quot;http://www.oreillynet.com/ruby/blog/2007/03/getting_to_know_the_ruby_core.html&quot;&gt;Getting to Know the Ruby Core Classes: Enumerable#grep - O&#039;Reilly Ruby&lt;/a&gt; [oreillynet.com]</description>
            
            <pubDate>Sat, 11 Oct 2008 14:44:09 -0700</pubDate>
        </item>
            
        <item>
            <title>HANDY ONE-LINERS FOR RUBY</title>
            <link>http://swik.net/Ruby/Code+Snippets%3A+ruby/HANDY+ONE-LINERS+FOR+RUBY/chd17</link>
            <description>Source: &lt;a href=&quot;http://www.fepus.net/ruby1line.txt&quot;&gt;http://www.fepus.net/ruby1line.txt&lt;/a&gt; [fepus.net]
&lt;br/&gt;
&lt;br/&gt;HANDY ONE-LINERS FOR RUBY                             November 16, 2005
&lt;br/&gt;compiled by David P Thomas          version 1.0
&lt;br/&gt;
&lt;br/&gt;Latest version of this file can be found at:
&lt;br/&gt;    http://www.fepus.net/ruby1line.txt
&lt;br/&gt;
&lt;br/&gt;Last Updated: Wed Nov 16 08:35:02 CST 2005
&lt;br/&gt;
&lt;br/&gt;FILE SPACING:
&lt;br/&gt;
&lt;br/&gt;# double space a file
&lt;br/&gt;&lt;code&gt;    $  ruby -pe &#039;puts&#039; 
&lt;br/&gt;# triple space a file
&lt;br/&gt;&lt;code&gt;    $  ruby -pe &#039;2.times {puts}&#039; 
&lt;br/&gt;# undo double-spacing (w/ and w/o whitespace in lines)
&lt;br/&gt;&lt;code&gt;    $  ruby -lne &#039;BEGIN{$/=&quot;\n\n&quot;}; puts $_&#039;     $  ruby -ne &#039;BEGIN{$/=&quot;\n\n&quot;}; puts $_.chomp&#039;     $  ruby -e &#039;puts STDIN.readlines.to_s.gsub(/\n\n/, &quot;\n&quot;)&#039; 
&lt;br/&gt;
&lt;br/&gt;NUMBERING:
&lt;br/&gt;
&lt;br/&gt;# number each line of a file (left justified).
&lt;br/&gt;&lt;code&gt;    $  ruby -ne &#039;printf(&quot;%-6s%s&quot;, $., $_)&#039; 
&lt;br/&gt;# number each line of a file (right justified).
&lt;br/&gt;&lt;code&gt;    $  ruby -ne &#039;printf(&quot;%6s%s&quot;, $., $_)&#039; 
&lt;br/&gt;# number each line of a file, only print non-blank lines
&lt;br/&gt;&lt;code&gt;    $  ruby -e &#039;while gets; end; puts $.&#039; 
&lt;br/&gt;# count lines (emulates &#039;wc -l&#039;)
&lt;br/&gt;&lt;code&gt;    $  ruby -ne &#039;END {puts $.}&#039;     $  ruby -e &#039;while gets; end; puts $.&#039; 
&lt;br/&gt;
&lt;br/&gt;TEXT CONVERSION AND SUBSTITUTION:
&lt;br/&gt;
&lt;br/&gt;# convert DOS newlines (CR/LF) to Unix format (LF)
&lt;br/&gt;# - strip newline regardless; re-print with unix EOL
&lt;br/&gt;&lt;code&gt;    $  ruby -ne &#039;BEGIN{$\=&quot;\n&quot;}; print $_.chomp&#039; 
&lt;br/&gt;
&lt;br/&gt;# convert Unix newlines (LF) to DOS format (CR/LF)
&lt;br/&gt;# - strip newline regardless; re-print with dos EOL
&lt;br/&gt;&lt;code&gt;    $  ruby -ne &#039;BEGIN{$\=&quot;\r\n&quot;}; print $_.chomp&#039; 
&lt;br/&gt;
&lt;br/&gt;# delete leading whitespace (spaces/tabs/etc) from beginning of each line
&lt;br/&gt;&lt;code&gt;    $  ruby -pe &#039;gsub(/^\s+/, &quot;&quot;)&#039; 
&lt;br/&gt;
&lt;br/&gt;# delete trailing whitespace (spaces/tabs/etc) from end of each line
&lt;br/&gt;# - strip newline regardless; replace with default platform record separator
&lt;br/&gt;&lt;code&gt;    $  ruby -pe &#039;gsub(/\s+$/, $/)&#039; 
&lt;br/&gt;
&lt;br/&gt;# delete BOTH leading and trailing whitespace from each line
&lt;br/&gt;&lt;code&gt;    $  ruby -pe &#039;gsub(/^\s+/, &quot;&quot;).gsub(/\s+$/, $/)&#039; 
&lt;br/&gt;
&lt;br/&gt;# insert 5 blank spaces at the beginning of each line (ie. page offset)
&lt;br/&gt;&lt;code&gt;    $  ruby -pe &#039;gsub(/%/, &quot;   &quot;)&#039;     FAILS! $  ruby -pe &#039;gsub(/%/, 5.times{putc &quot; &quot;})&#039; 
&lt;br/&gt;
&lt;br/&gt;# align all text flush right on a 79-column width
&lt;br/&gt;&lt;code&gt;    $  ruby -ne &#039;printf(&quot;%79s&quot;, $_)&#039; 
&lt;br/&gt;
&lt;br/&gt;# center all text in middle of 79-column width
&lt;br/&gt;&lt;code&gt;    $  ruby -ne &#039;puts $_.chomp.center(79)&#039;     $  ruby -lne &#039;puts $_.center(79)&#039; 
&lt;br/&gt;
&lt;br/&gt;# substitute (find and replace) &quot;foo&quot; with &quot;bar&quot; on each line
&lt;br/&gt;&lt;code&gt;    $  ruby -pe &#039;gsub(/foo/, &quot;bar&quot;)&#039; 
&lt;br/&gt;
&lt;br/&gt;# substitute &quot;foo&quot; with &quot;bar&quot; ONLY for lines which contain &quot;baz&quot;
&lt;br/&gt;&lt;code&gt;    $  ruby -pe &#039;gsub(/foo/, &quot;bar&quot;) if $_ =~ /baz/&#039; 
&lt;br/&gt;
&lt;br/&gt;# substitute &quot;foo&quot; with &quot;bar&quot; EXCEPT for lines which contain &quot;baz&quot;
&lt;br/&gt;&lt;code&gt;    $  ruby -pe &#039;gsub(/foo/, &quot;bar&quot;) unless $_ =~ /baz/&#039; 
&lt;br/&gt;
&lt;br/&gt;# substitute &quot;foo&quot; or &quot;bar&quot; or &quot;baz&quot;.... with &quot;baq&quot;
&lt;br/&gt;&lt;code&gt;    $  ruby -pe &#039;gsub(/(foo|bar|baz)/, &quot;baq&quot;)&#039; 
&lt;br/&gt;
&lt;br/&gt;# reverse order of lines (emulates &#039;tac&#039;) IMPROVE
&lt;br/&gt;&lt;code&gt;    $  ruby -ne &#039;BEGIN{@arr=Array.new}; @arr.push $_; END{puts @arr.reverse}&#039; 
&lt;br/&gt;
&lt;br/&gt;# reverse each character on the line (emulates &#039;rev&#039;)
&lt;br/&gt;&lt;code&gt;    $  ruby -ne &#039;puts $_.chomp.reverse&#039;     $  ruby -lne &#039;puts $_.reverse&#039; 
&lt;br/&gt;
&lt;br/&gt;# join pairs of lines side-by-side (like &#039;paste&#039;)
&lt;br/&gt;&lt;code&gt;    $  ruby -pe &#039;$_ = $_.chomp + &quot; &quot; + gets if $. % 2&#039; 
&lt;br/&gt;
&lt;br/&gt;# if a line ends with a backslash, append the next line to it
&lt;br/&gt;&lt;code&gt;    $  ruby -pe &#039;while $_.match(/\\$/); $_ = $_.chomp.chop + gets; end&#039;     $  ruby -e &#039;puts STDIN.readlines.to_s.gsub(/\\\n/, &quot;&quot;)&#039; 
&lt;br/&gt;
&lt;br/&gt;# if a line begins with an equal sign, append it to the previous line (Unix)
&lt;br/&gt;&lt;code&gt;    $  ruby -e &#039;puts STDIN.readlines.to_s.gsub(/\n=/, &quot;&quot;)&#039; 
&lt;br/&gt;
&lt;br/&gt;# add a blank line every 5 lines (after lines 5, 10, 15, etc)
&lt;br/&gt;&lt;code&gt;    $  ruby -pe &#039;puts if $. % 6 == 0&#039; 
&lt;br/&gt;
&lt;br/&gt;SELECTIVE PRINTING OF CERTAIN LINES
&lt;br/&gt;
&lt;br/&gt;# print first 10 lines of a file (emulate &#039;head&#039;)
&lt;br/&gt;&lt;code&gt;    $  ruby -pe &#039;exit if $. &gt; 10&#039; 
&lt;br/&gt;
&lt;br/&gt;# print first line of a file (emulate &#039;head -1&#039;)
&lt;br/&gt;&lt;code&gt;    $  ruby -pe &#039;puts $_; exit&#039; 
&lt;br/&gt;
&lt;br/&gt;# print the last 10 lines of a file (emulate &#039;tail&#039;); NOTE reads entire file!
&lt;br/&gt;&lt;code&gt;    $  ruby -e &#039;puts STDIN.readlines.reverse!.slice(0,10).reverse!&#039; 
&lt;br/&gt;
&lt;br/&gt;# print the last 2 lines of a file (emulate &#039;tail -2&#039;); NOTE reads entire file!
&lt;br/&gt;&lt;code&gt;    $  ruby -e &#039;puts STDIN.readlines.reverse!.slice(0,2).reverse!&#039; 
&lt;br/&gt;
&lt;br/&gt;# print the last line of a file (emulates &#039;tail -1&#039;)
&lt;br/&gt;&lt;code&gt;    $  ruby -ne &#039;line = $_; END {puts line}&#039; 
&lt;br/&gt;
&lt;br/&gt;# print only lines that match a regular expression (emulates &#039;grep&#039;)
&lt;br/&gt;&lt;code&gt;    $  ruby -pe &#039;next unless $_ =~ /regexp/&#039; 
&lt;br/&gt;
&lt;br/&gt;# print only lines that DO NOT match a regular expression (emulates &#039;grep&#039;)
&lt;br/&gt;&lt;code&gt;    $  ruby -pe &#039;next if $_ =~ /regexp/&#039; 
&lt;br/&gt;
&lt;br/&gt;# print the line immediately before a regexp, but not the regex matching line
&lt;br/&gt;&lt;code&gt;    $  ruby -ne &#039;puts @prev if $_ =~ /regex/; @prev = $_;&#039; 
&lt;br/&gt;
&lt;br/&gt;# print the line immediately after a regexp, but not the regex matching line
&lt;br/&gt;&lt;code&gt;    $  ruby -ne &#039;puts $_ if @prev =~ /regex/; @prev = $_;&#039; 
&lt;br/&gt;
&lt;br/&gt;# grep for foo AND bar AND baz (in any order)
&lt;br/&gt;&lt;code&gt;    $  ruby -pe &#039;next unless $_ =~ /foo/ &amp;&amp; $_ =~ /bar/ &amp;&amp; $_ =~ /baz/&#039; 
&lt;br/&gt;
&lt;br/&gt;# grep for foo AND bar AND baz (in order)
&lt;br/&gt;&lt;code&gt;    $  ruby -pe &#039;next unless $_ =~ /foo.*bar.*baz/&#039; 
&lt;br/&gt;
&lt;br/&gt;# grep for foo OR bar OR baz
&lt;br/&gt;&lt;code&gt;    $  ruby -pe &#039;next unless $_ =~ /(foo|bar|baz)/&#039; 
&lt;br/&gt;
&lt;br/&gt;# print paragraph if it contains regexp; blank lines separate paragraphs
&lt;br/&gt;&lt;code&gt;    $  ruby -ne &#039;BEGIN{$/=&quot;\n\n&quot;}; print $_ if $_ =~ /regexp/&#039; 
&lt;br/&gt;
&lt;br/&gt;# print paragraph if it contains foo AND bar AND baz (in any order); blank lines separate paragraphs
&lt;br/&gt;&lt;code&gt;    $  ruby -ne &#039;BEGIN{$/=&quot;\n\n&quot;}; print $_ if $_ =~ /foo/ &amp;&amp; $_ =~ /bar/ &amp;&amp; $_ =~ /baz/&#039; 
&lt;br/&gt;
&lt;br/&gt;# print paragraph if it contains foo AND bar AND baz (in order); blank lines separate paragraphs
&lt;br/&gt;&lt;code&gt;    $  ruby -ne &#039;BEGIN{$/=&quot;\n\n&quot;}; print $_ if $_ =~ /(foo.*bar.*baz)/&#039; 
&lt;br/&gt;
&lt;br/&gt;# print paragraph if it contains foo OR bar OR baz; blank lines separate paragraphs
&lt;br/&gt;&lt;code&gt;    $  ruby -ne &#039;BEGIN{$/=&quot;\n\n&quot;}; print $_ if $_ =~ /(foo|bar|baz)/&#039; 
&lt;br/&gt;
&lt;br/&gt;# print only lines of 65 characters or greater
&lt;br/&gt;&lt;code&gt;    $  ruby -pe &#039;next unless $_.chomp.length &gt;= 65&#039;     $  ruby -lpe &#039;next unless $_.length &gt;= 65&#039; 
&lt;br/&gt;
&lt;br/&gt;# print only lines of 65 characters or less
&lt;br/&gt;&lt;code&gt;    $  ruby -pe &#039;next unless $_.chomp.length     $  ruby -lpe &#039;next unless $_.length 
&lt;br/&gt;
&lt;br/&gt;# print section of file from regex to end of file
&lt;br/&gt;&lt;code&gt;    $  ruby -pe &#039;@found=true if $_ =~ /regex/; next unless @found&#039; 
&lt;br/&gt;
&lt;br/&gt;# print section of file based on line numbers (eg. lines 2-7 inclusive)
&lt;br/&gt;&lt;code&gt;    $  ruby -pe &#039;next unless $. &gt;= 2 &amp;&amp; $. = 4 &amp;&amp; $. % 3 == 0&#039; 
&lt;br/&gt;
&lt;br/&gt;# print section of file between two regular expressions, /foo/ and /bar/
&lt;br/&gt;&lt;code&gt;    $  ruby -ne &#039;@found=true if $_ =~ /foo/; next unless @found; puts $_; exit if $_ =~ /bar/&#039; 
&lt;br/&gt;
&lt;br/&gt;SELECTIVE DELETION OF CERTAIN LINES
&lt;br/&gt;
&lt;br/&gt;# print all of file except between two regular expressions, /foo/ and /bar/
&lt;br/&gt;&lt;code&gt;    $  ruby -ne &#039;@found = true if $_ =~ /foo/; puts $_ unless @found; @found = false if $_ =~ /bar/&#039; 
&lt;br/&gt;
&lt;br/&gt;# print file and remove duplicate, consecutive lines from a file (emulates &#039;uniq&#039;)
&lt;br/&gt;&lt;code&gt;    $  ruby -ne &#039;puts $_ unless $_ == @prev; @prev = $_&#039; 
&lt;br/&gt;
&lt;br/&gt;# print file and remove duplicate, non-consecutive lines from a file (careful of memory!)
&lt;br/&gt;&lt;code&gt;    $  ruby -e &#039;puts STDIN.readlines.sort.uniq!.to_s&#039; 
&lt;br/&gt;
&lt;br/&gt;# print file except for first 10 lines
&lt;br/&gt;&lt;code&gt;    $  ruby -pe &#039;next if $. </description>
            
            <pubDate>Sat, 11 Oct 2008 13:44:04 -0700</pubDate>
        </item>
            
        <item>
            <title>Search and replace filenames using Ruby</title>
            <link>http://swik.net/Ruby/Code+Snippets%3A+ruby/Search+and+replace+filenames+using+Ruby/chdcb</link>
            <description>This script searches and replaces file names within a file directory.
&lt;br/&gt;
&lt;br/&gt;&lt;code&gt;
&lt;br/&gt;#!/usr/bin/ruby
&lt;br/&gt;#file: bulkrenamefiles.rb
&lt;br/&gt;
&lt;br/&gt;class BulkRenameFiles
&lt;br/&gt;  def initialize(h)
&lt;br/&gt;    h[:dir] = &#039;.&#039; if [:dir].empty?
&lt;br/&gt;
&lt;br/&gt;    files = Dir.entries(h[:dir])
&lt;br/&gt;
&lt;br/&gt;    files.each do |f|
&lt;br/&gt;      next if f == &quot;.&quot; or f == &quot;..&quot;
&lt;br/&gt;      oldFile = h[:dir] + &quot;/&quot; + f
&lt;br/&gt;      newFile = h[:dir] + &quot;/&quot; + f.gsub(/#{h[:exp_search]}/,h[:exp_replace])
&lt;br/&gt;      File.rename(oldFile, newFile)
&lt;br/&gt;    end
&lt;br/&gt;  end
&lt;br/&gt;end
&lt;br/&gt;
&lt;br/&gt;if __FILE__ == $0 then
&lt;br/&gt;  brf = BulkRenameFiles.new(:dir =&gt; &#039;.&#039;, :exp_search =&gt; &#039;^_&#039;, :exp_replace =&gt; &#039;&#039;)
&lt;br/&gt;end
&lt;br/&gt;&lt;/code&gt;
&lt;br/&gt;
&lt;br/&gt;output before:
&lt;br/&gt;&lt;code&gt;-rwxr-xr-x 1 apache apache  178 Aug  2 16:29 class_template.xml
&lt;br/&gt;-rwxr-xr-x 1 apache apache  106 Aug  2 16:29 _tasks_data_template.xml
&lt;br/&gt;-rwxr-xr-x 1 apache apache  100 Aug  2 19:31 _tasks_today.xml
&lt;br/&gt;-rwxr-xr-x 1 apache apache  909 Aug  2 19:31 _tasks.xsl
&lt;br/&gt;-rwxr-xr-x 1 apache apache  106 Aug  2 19:56 _tasks2_data.xml
&lt;br/&gt;-rw-r--r-- 1 apache apache  267 Aug  2 22:43 _tasks.xml
&lt;br/&gt;-rwxr-xr-x 1 apache apache   56 Aug  5 02:10 _tasks_template.xml
&lt;br/&gt;-rwxr-xr-x 1 apache apache 2686 Aug  8 19:53 index.xml
&lt;br/&gt;-rwxr-xr-x 1 apache apache 2685 Aug  8 19:53 _tasks_data.xml&lt;/code&gt;
&lt;br/&gt;
&lt;br/&gt;output after:
&lt;br/&gt;
&lt;br/&gt;&lt;code&gt;-rwxr-xr-x 1 apache apache  106 Aug  2 16:29 tasks_data_template.xml
&lt;br/&gt;-rwxr-xr-x 1 apache apache  178 Aug  2 16:29 class_template.xml
&lt;br/&gt;-rwxr-xr-x 1 apache apache  100 Aug  2 19:31 tasks_today.xml
&lt;br/&gt;-rwxr-xr-x 1 apache apache  909 Aug  2 19:31 tasks.xsl
&lt;br/&gt;-rwxr-xr-x 1 apache apache  106 Aug  2 19:56 tasks2_data.xml
&lt;br/&gt;-rw-r--r-- 1 apache apache  267 Aug  2 22:43 tasks.xml
&lt;br/&gt;-rwxr-xr-x 1 apache apache   56 Aug  5 02:10 tasks_template.xml
&lt;br/&gt;-rwxr-xr-x 1 apache apache 2685 Aug  8 19:53 tasks_data.xml
&lt;br/&gt;-rwxr-xr-x 1 apache apache 2686 Aug  8 19:53 index.xml&lt;/code&gt;
&lt;br/&gt;
&lt;br/&gt;Source: &lt;a href=&quot;http://www.rubyonrailsexamples.com/ruby-files/ruby-files-renaming/&quot;&gt;Renaming files using ruby! - by Ruby on Rails&lt;/a&gt; [rubyonrailsexamples.com]</description>
            
            <pubDate>Sat, 11 Oct 2008 07:28:31 -0700</pubDate>
        </item>
            
        <item>
            <title>Running netstat in a Ruby system command</title>
            <link>http://swik.net/Ruby/Code+Snippets%3A+ruby/Running+netstat+in+a+Ruby+system+command/cg9h4</link>
            <description>Source: &lt;a href=&quot;http://www.wellho.net/resources/ex.php4?item=r106/ndo&quot;&gt;Running another process - netstat example - Ruby example&lt;/a&gt; [wellho.net]
&lt;br/&gt;
&lt;br/&gt;&lt;code&gt;
&lt;br/&gt;fhi = IO.popen(&quot;netstat 3&quot;)
&lt;br/&gt;while (line = fhi.gets)
&lt;br/&gt;      print line
&lt;br/&gt;        print &quot;and&quot;
&lt;br/&gt;end
&lt;br/&gt;&lt;/code&gt;
&lt;br/&gt;
&lt;br/&gt;extract from the output :
&lt;br/&gt;&lt;code&gt;
&lt;br/&gt;Active Internet connections (w/o servers)
&lt;br/&gt;andProto Recv-Q Send-Q Local Address           Foreign Address         State    
&lt;br/&gt;   
&lt;br/&gt;andtcp        0      0 kataia.local:41981      92-236-96-2:xmpp-client ESTABLISH
&lt;br/&gt;ED 
&lt;br/&gt;andtcp        0      0 kataia.local:46000      ec2-75-101-229-77.c:www TIME_WAIT
&lt;br/&gt;   
&lt;br/&gt;andtcp        0      0 kataia.local:36042      192.168.1.107:6600      ESTABLISH
&lt;br/&gt;ED 
&lt;br/&gt;andtcp        0      0 kataia.local:60859      ec2-67-202-19-236.c:www TIME_WAIT
&lt;br/&gt;...
&lt;br/&gt;andunix  3      [ ]         STREAM     CONNECTED     11570    /var/run/dbus/system_bus_socket
&lt;br/&gt;andunix  3      [ ]         STREAM     CONNECTED     11569
&lt;br/&gt;andunix  3      [ ]         STREAM     CONNECTED     11540    /var/run/dbus/system_bus_socket
&lt;br/&gt;andunix  3      [ ]         STREAM     CONNECTED     11539
&lt;br/&gt;andunix  2      [ ]         DGRAM                    11535
&lt;br/&gt;andunix  3      [ ]         STREAM     CONNECTED     11518
&lt;br/&gt;andunix  3      [ ]         STREAM     CONNECTED     11517
&lt;br/&gt;andunix  2      [ ]         DGRAM                    11494
&lt;br/&gt;&lt;/code&gt;</description>
            
            <pubDate>Fri, 10 Oct 2008 02:10:28 -0700</pubDate>
        </item>
            
        <item>
            <title>Ping all nodes on the LAN subnet</title>
            <link>http://swik.net/Ruby/Code+Snippets%3A+ruby/Ping+all+nodes+on+the+LAN+subnet/cg731</link>
            <description>This Ruby script attempts to ping all machines on the network 192.168.1.x and then save  the results in an XML file.
&lt;br/&gt;
&lt;br/&gt;&lt;code&gt;
&lt;br/&gt;#!/usr/bin/ruby
&lt;br/&gt;#file: pingall.rb
&lt;br/&gt;
&lt;br/&gt;require &#039;ping&#039;
&lt;br/&gt;require &#039;prettyxml&#039;
&lt;br/&gt;require &#039;rexml/document&#039;
&lt;br/&gt;include REXML
&lt;br/&gt;
&lt;br/&gt;ip_prefix = &#039;192.168.1.&#039;
&lt;br/&gt;file_template = File.new(&#039;network_nodes_template.xml&#039;,&#039;r&#039;)
&lt;br/&gt;buffer = file_template.read
&lt;br/&gt;doc = Document.new(buffer)
&lt;br/&gt;(1..254).each do |i| 
&lt;br/&gt;
&lt;br/&gt;  Thread.new do
&lt;br/&gt;    doc.root.elements[&quot;records/node[#{i}]/active&quot;].text = &#039;y&#039;  if Ping.pingecho(ip_prefix + i.to_s, 1)
&lt;br/&gt;  end
&lt;br/&gt;
&lt;br/&gt;end
&lt;br/&gt;
&lt;br/&gt;file = File.new(&#039;ping_results.xml&#039;,&#039;w&#039;)
&lt;br/&gt;file.puts doc.pretty
&lt;br/&gt;file.close
&lt;br/&gt;&lt;/code&gt;
&lt;br/&gt;
&lt;br/&gt;output extract from ping_results.xml:
&lt;br/&gt;&lt;code&gt;
&lt;br/&gt;
&lt;br/&gt;  
&lt;br/&gt;  
&lt;br/&gt;    
&lt;br/&gt;      &lt;address&gt;192.168.1.1&lt;/address&gt;
&lt;br/&gt;      n
&lt;br/&gt;    
&lt;br/&gt;    
&lt;br/&gt;      &lt;address&gt;192.168.1.2&lt;/address&gt;
&lt;br/&gt;      n
&lt;br/&gt;    
&lt;br/&gt;    
&lt;br/&gt;      &lt;address&gt;192.168.1.3&lt;/address&gt;
&lt;br/&gt;      n
&lt;br/&gt;    
&lt;br/&gt;...
&lt;br/&gt;    
&lt;br/&gt;      &lt;address&gt;192.168.1.101&lt;/address&gt;
&lt;br/&gt;      n
&lt;br/&gt;    
&lt;br/&gt;    
&lt;br/&gt;      &lt;address&gt;192.168.1.102&lt;/address&gt;
&lt;br/&gt;      y
&lt;br/&gt;    
&lt;br/&gt;    
&lt;br/&gt;      &lt;address&gt;192.168.1.103&lt;/address&gt;
&lt;br/&gt;      y
&lt;br/&gt;    
&lt;br/&gt;...
&lt;br/&gt;    
&lt;br/&gt;      &lt;address&gt;192.168.1.253&lt;/address&gt;
&lt;br/&gt;      n
&lt;br/&gt;    
&lt;br/&gt;    
&lt;br/&gt;      &lt;address&gt;192.168.1.254&lt;/address&gt;
&lt;br/&gt;      y
&lt;br/&gt;    
&lt;br/&gt;  
&lt;br/&gt;
&lt;br/&gt;&lt;/code&gt;
&lt;br/&gt;
&lt;br/&gt;References:
&lt;br/&gt; - &lt;a href=&quot;http://snippets.dzone.com/posts/show/5212&quot;&gt;Ruby Threading&lt;/a&gt; [dzone.com]
&lt;br/&gt; - &lt;a href=&quot;http://snippets.dzone.com/posts/show/4953&quot;&gt;Pretty Print XML using Ruby&lt;/a&gt; [dzone.com]</description>
            
            <pubDate>Thu, 09 Oct 2008 18:09:53 -0700</pubDate>
        </item>
            
        <item>
            <title>Capture matching Regex results into variables in 1 line of code</title>
            <link>http://swik.net/Ruby/Code+Snippets%3A+ruby/Capture+matching+Regex+results+into+variables+in+1+line+of+code/cg730</link>
            <description>
&lt;br/&gt;&lt;code&gt;&gt;&gt; firstname, lastname = line1.match(/(\w+),\s+(\w+)/).captures&lt;/code&gt;
&lt;br/&gt;=&gt; [&quot;David&quot;, &quot;Smith&quot;]
&lt;br/&gt;&lt;code&gt;&gt;&gt; firstname&lt;/code&gt;
&lt;br/&gt;=&gt; &quot;David&quot;
&lt;br/&gt;&lt;code&gt;&gt;&gt; lastname&lt;/code&gt;
&lt;br/&gt;=&gt; &quot;Smith&quot;
&lt;br/&gt;
&lt;br/&gt;</description>
            
            <pubDate>Thu, 09 Oct 2008 18:09:53 -0700</pubDate>
        </item>
            
        <item>
            <title>Log calls to require in ruby</title>
            <link>http://swik.net/Ruby/Code+Snippets%3A+ruby/Log+calls+to+require+in+ruby/cg73z</link>
            <description>// description of your code here
&lt;br/&gt;
&lt;br/&gt;&lt;code&gt;
&lt;br/&gt;require &#039;logger&#039;
&lt;br/&gt;  
&lt;br/&gt;class Object
&lt;br/&gt;  def require(file_name)        
&lt;br/&gt;    output = &quot;requiring #{file_name}&quot;    
&lt;br/&gt;    puts output   
&lt;br/&gt;    log = Logger.new(File.join(File.dirname(__FILE__), &#039;required.log&#039;))        
&lt;br/&gt;    log.debug(output)     
&lt;br/&gt;    super
&lt;br/&gt;  end  
&lt;br/&gt;end
&lt;br/&gt;&lt;/code&gt;</description>
            
            <pubDate>Thu, 09 Oct 2008 18:09:53 -0700</pubDate>
        </item>
            
        <item>
            <title>Determine the operating system in Ruby</title>
            <link>http://swik.net/Ruby/Code+Snippets%3A+ruby/Determine+the+operating+system+in+Ruby/cg73y</link>
            <description>This code runs on RUBY_PLATFORM which returns the platform the active copy of ruby was
&lt;br/&gt;compiled to run on.  I have not found a better method thus far.
&lt;br/&gt;
&lt;br/&gt;&lt;code&gt;
&lt;br/&gt;module OsFunctions
&lt;br/&gt;  
&lt;br/&gt;  # universal-darwin9.0 shows up for RUBY_PLATFORM on os X leopard with the bundled ruby. 
&lt;br/&gt;  # Installing ruby in different manners may give a different result, so beware.
&lt;br/&gt;  # Examine the ruby platform yourself. If you see other values please comment
&lt;br/&gt;  # in the snippet on dzone and I will add them.
&lt;br/&gt;
&lt;br/&gt;  def is_mac?
&lt;br/&gt;    RUBY_PLATFORM.downcase.include?(&quot;darwin&quot;)
&lt;br/&gt;  end
&lt;br/&gt;
&lt;br/&gt;  def is_windows?
&lt;br/&gt;     RUBY_PLATFORM.downcase.include?(&quot;mswin&quot;)
&lt;br/&gt;  end
&lt;br/&gt;
&lt;br/&gt;  def is_linux?
&lt;br/&gt;     RUBY_PLATFORM.downcase.include?(&quot;linux&quot;)
&lt;br/&gt;  end
&lt;br/&gt;end
&lt;br/&gt;&lt;/code&gt;</description>
            
            <pubDate>Thu, 09 Oct 2008 18:09:53 -0700</pubDate>
        </item>
            
        <item>
            <title>Call a function on all items in an array and collect responses</title>
            <link>http://swik.net/Ruby/Code+Snippets%3A+ruby/Call+a+function+on+all+items+in+an+array+and+collect+responses/cg73x</link>
            <description>&lt;code&gt;
&lt;br/&gt;# The invisible proxy allows seamless calling of a method on all objects of an array.
&lt;br/&gt;# When an array is wrapped (passed into) one of these objects, you can call a function
&lt;br/&gt;# on all objects in the array with one line.
&lt;br/&gt;
&lt;br/&gt;# This is not how this works exactly, but a good resource:
&lt;br/&gt;#   http://alisdair.mcdiarmid.org/2005/12/20/invisible-proxies-with-ruby
&lt;br/&gt;
&lt;br/&gt;class InvisibleProxyToArray
&lt;br/&gt;
&lt;br/&gt;  instance_methods.each do |m|
&lt;br/&gt;    undef_method(m) unless m =~ /(^__|^nil\\?|^send)/
&lt;br/&gt;  end
&lt;br/&gt;  
&lt;br/&gt;  def initialize(collection)
&lt;br/&gt;    @collection = collection
&lt;br/&gt;  end
&lt;br/&gt;
&lt;br/&gt;  def respond_to?(symbol)
&lt;br/&gt;    @collection.first.respond_to?(symbol)
&lt;br/&gt;  end
&lt;br/&gt;   
&lt;br/&gt;  # calls a method on every member of the proxied array
&lt;br/&gt;  # and totals the return values
&lt;br/&gt;  def total(total_symbol)
&lt;br/&gt;    total=0
&lt;br/&gt;    @collection.each{|obj|total= total + obj.send(total_symbol)}
&lt;br/&gt;    total
&lt;br/&gt;  end
&lt;br/&gt;  
&lt;br/&gt;  
&lt;br/&gt;  # gives a string indicating object responses to being sent a symbol (which calls a property or method)
&lt;br/&gt;  # summarize(:status) will produce:  running (2), stopping (13)
&lt;br/&gt;  def summarize(summarize_symbol)
&lt;br/&gt;    msgs=[]
&lt;br/&gt;    hsh=hash_by_result(summarize_symbol, @collection)
&lt;br/&gt;    hsh.each {|status, resources_arr| msgs     msgs.join(&#039;,&#039;)
&lt;br/&gt;  end
&lt;br/&gt;  
&lt;br/&gt;  # returns a hash like {&quot;running&quot;=&gt;[a , b], &quot;dead&quot;=&gt;[a]} for :status or other messages
&lt;br/&gt;  # where a and b would be resources whose response for :status was &quot;running&quot;
&lt;br/&gt;  def hash_by_result(property_symbol,object_array)
&lt;br/&gt;    hsh={} 
&lt;br/&gt;    object_array.each do |obj|
&lt;br/&gt;      hsh[obj.send(property_symbol)] ||= []
&lt;br/&gt;      hsh[obj.send(property_symbol)]     end
&lt;br/&gt;    hsh
&lt;br/&gt;  end
&lt;br/&gt;   
&lt;br/&gt;  
&lt;br/&gt;  private
&lt;br/&gt;
&lt;br/&gt;  def method_missing(method, *args, &amp;block)
&lt;br/&gt;    @collection.each {|item| item.send(method, *args, &amp;block)}
&lt;br/&gt;  end
&lt;br/&gt;  
&lt;br/&gt;end
&lt;br/&gt;&lt;/code&gt;</description>
            
            <pubDate>Thu, 09 Oct 2008 18:09:53 -0700</pubDate>
        </item>
            
        <item>
            <title>Convert the /etc/services file to XML</title>
            <link>http://swik.net/Ruby/Code+Snippets%3A+ruby/Convert+the+%2Fetc%2Fservices+file+to+XML/cg73w</link>
            <description>This Ruby script simply reads the port numbers from the Linux file /etc/services into a n XML file.
&lt;br/&gt;
&lt;br/&gt;&lt;code&gt;
&lt;br/&gt;#!/usr/bin/ruby
&lt;br/&gt;#file: readportservices.rb
&lt;br/&gt;
&lt;br/&gt;require &#039;rexml/document&#039;
&lt;br/&gt;require &#039;prettyxml&#039;
&lt;br/&gt;include REXML
&lt;br/&gt;
&lt;br/&gt;class ReadPortServices
&lt;br/&gt;
&lt;br/&gt;  def initialize(h)
&lt;br/&gt;    @services_filepath = h[:services]
&lt;br/&gt;    @xml_filepath = h[:xmlfile]
&lt;br/&gt;    main()
&lt;br/&gt;  end
&lt;br/&gt;
&lt;br/&gt;  def add_node(doc, port, name, description)
&lt;br/&gt;    node = Element.new(&#039;port&#039;)
&lt;br/&gt;
&lt;br/&gt;    add_child(node, &#039;number&#039;, port)
&lt;br/&gt;    add_child(node, &#039;name&#039;, name)
&lt;br/&gt;    add_child(node, &#039;description&#039;, description)
&lt;br/&gt;    doc.root.elements[&#039;records&#039;].add_element node
&lt;br/&gt;  end
&lt;br/&gt;
&lt;br/&gt;  def add_child(node,nodename, value)
&lt;br/&gt;    newnode = Element.new(nodename)
&lt;br/&gt;    newnode.text = value
&lt;br/&gt;    node.add_element(newnode)
&lt;br/&gt;  end
&lt;br/&gt;
&lt;br/&gt;  def main()
&lt;br/&gt;    doc = Document.new(&#039;&#039;)
&lt;br/&gt;    summary_description = &#039;&#039;
&lt;br/&gt;
&lt;br/&gt;    File.readlines(@services_filepath).each do |line|
&lt;br/&gt;        next if line[0] == ?# or line =~ /^$/
&lt;br/&gt;
&lt;br/&gt;        name, port, protocol, description = line.match(/(^[a-z][0-9A-Za-z_.+-]*)\s+(\d+)\/(\w+).[^#]+#?.?(.+)?$/).captures
&lt;br/&gt;        add_node(doc, port, name, description)
&lt;br/&gt;    end
&lt;br/&gt;
&lt;br/&gt;    #puts doc
&lt;br/&gt;    file= File.new(@xml_filepath, &#039;w&#039;)
&lt;br/&gt;    file.puts doc.pretty
&lt;br/&gt;    file.close
&lt;br/&gt;  end
&lt;br/&gt;end
&lt;br/&gt;
&lt;br/&gt;if __FILE__ == $0 then
&lt;br/&gt;  rps = ReadPortServices.new(:services =&gt; &#039;/etc/services&#039;, :xmlfile =&gt; &#039;service_ports.xml&#039;)
&lt;br/&gt;end
&lt;br/&gt;&lt;/code&gt;</description>
            
            <pubDate>Thu, 09 Oct 2008 18:09:53 -0700</pubDate>
        </item>
            
        <item>
            <title>Scan ports in Ruby</title>
            <link>http://swik.net/Ruby/Code+Snippets%3A+ruby/Scan+ports+in+Ruby/cg73v</link>
            <description>The following code originated from  &lt;a href=&quot;http://rubyforge.org/projects/pscan/&quot;&gt;RubyForge: Simple TCP/IP port scanner: Project Info&lt;/a&gt; [rubyforge.org], and then the XML feature for reading and outputting port number information was added.
&lt;br/&gt;
&lt;br/&gt;
&lt;br/&gt;&lt;code&gt;#!/usr/bin/ruby
&lt;br/&gt;#file: portscan.rb
&lt;br/&gt;
&lt;br/&gt;require &#039;open-uri&#039;
&lt;br/&gt;require &#039;socket&#039;
&lt;br/&gt;require &#039;rexml/document&#039;
&lt;br/&gt;include REXML
&lt;br/&gt;
&lt;br/&gt;class PortScanner
&lt;br/&gt;
&lt;br/&gt;  def initialize(host, xmlfileout=&#039;portscan_result.xml&#039;)
&lt;br/&gt;    high = 8192
&lt;br/&gt;    service_url = &quot;http://rorbuilder.info/r/service_ports.xml&quot;
&lt;br/&gt;    doc_result = main(service_url, host, high)
&lt;br/&gt;
&lt;br/&gt;    File.new(xmlfileout,&#039;w&#039;).puts(doc_result)
&lt;br/&gt;    
&lt;br/&gt;  end
&lt;br/&gt;
&lt;br/&gt;  def main(url, host, high)
&lt;br/&gt;
&lt;br/&gt;    buffer = open(url, &quot;UserAgent&quot; =&gt; &quot;Ruby-PortScanner1.0&quot;)
&lt;br/&gt;    doc = Document.new(buffer)
&lt;br/&gt;
&lt;br/&gt;    doc.root.elements.each(&#039;records/port&#039;) do |node|
&lt;br/&gt;      new_node = Element.new(&#039;open&#039;)
&lt;br/&gt;      new_node.text = &#039;n&#039;
&lt;br/&gt;      node.add_element new_node
&lt;br/&gt;    end
&lt;br/&gt;
&lt;br/&gt;    for port in 1 .. high
&lt;br/&gt;      begin
&lt;br/&gt;	      s = TCPsocket.open(host, port)
&lt;br/&gt;        puts &#039;port &#039; + port.to_s
&lt;br/&gt;        node_port = doc.root.elements[&quot;records/port[number=&#039;#{port.to_s}&#039;]&quot;]
&lt;br/&gt;        
&lt;br/&gt;        unless node_port.nil? 
&lt;br/&gt;          port_name = node_port.elements[&#039;name&#039;].text.to_s
&lt;br/&gt;          node_port.elements[&#039;open&#039;].text = &#039;y&#039;
&lt;br/&gt;        else 
&lt;br/&gt;          port_name = &#039;unknown&#039;
&lt;br/&gt;          add_port(:doc =&gt; doc , :port =&gt; port , :name =&gt; port_name, :description =&gt; &#039;&#039;) 
&lt;br/&gt;        end
&lt;br/&gt;
&lt;br/&gt;	      printf &quot;%s/%sopen\t%s\n&quot;, port, &#039;tcp&#039;.ljust(11 - port.to_s.length), port_name
&lt;br/&gt;
&lt;br/&gt;	      s.close
&lt;br/&gt;      rescue Errno::ECONNREFUSED
&lt;br/&gt;	      next
&lt;br/&gt;      end
&lt;br/&gt;    end
&lt;br/&gt;    return doc
&lt;br/&gt;  end
&lt;br/&gt;
&lt;br/&gt;  def add_port(h)
&lt;br/&gt;    node_port = Element.new(&#039;port&#039;)
&lt;br/&gt;
&lt;br/&gt;    add_child(node_port, &#039;number&#039;, h[:port])
&lt;br/&gt;    add_child(node_port, &#039;name&#039;, h[:name])
&lt;br/&gt;    add_child(node_port, &#039;description&#039;, h[:description])
&lt;br/&gt;    h[:doc].root.elements[&#039;records&#039;].add_element node_port
&lt;br/&gt;  end
&lt;br/&gt;
&lt;br/&gt;  def add_child(node,nodename, value)
&lt;br/&gt;    newnode = Element.new(nodename)
&lt;br/&gt;    newnode.text = value
&lt;br/&gt;    node.add_element(newnode)
&lt;br/&gt;  end
&lt;br/&gt;
&lt;br/&gt;end
&lt;br/&gt;
&lt;br/&gt;if __FILE__ == $0 then
&lt;br/&gt;  ps = PortScanner.new(&#039;192.168.1.106&#039;)  
&lt;br/&gt;end
&lt;br/&gt;&lt;/code&gt;
&lt;br/&gt;
&lt;br/&gt;screen output:
&lt;br/&gt;&lt;code&gt;
&lt;br/&gt;22/tcp      open        ssh
&lt;br/&gt;80/tcp      open        www
&lt;br/&gt;443/tcp     open        https
&lt;br/&gt;513/tcp     open        login
&lt;br/&gt;514/tcp     open        shell
&lt;br/&gt;4369/tcp    open        unknown
&lt;br/&gt;5222/tcp    open        xmpp-client
&lt;br/&gt;5269/tcp    open        xmpp-server
&lt;br/&gt;5280/tcp    open        unknown
&lt;br/&gt;8000/tcp    open        unknown
&lt;br/&gt;8001/tcp    open        unknown
&lt;br/&gt;&lt;/code&gt;
&lt;br/&gt;xml output:
&lt;br/&gt;
&lt;br/&gt;&lt;code&gt;
&lt;br/&gt;
&lt;br/&gt;  
&lt;br/&gt;  
&lt;br/&gt;    
&lt;br/&gt;      1
&lt;br/&gt;      tcpmux
&lt;br/&gt;      TCP port service multiplexer
&lt;br/&gt;    n
&lt;br/&gt;    
&lt;br/&gt;      7
&lt;br/&gt;      echo
&lt;br/&gt;      
&lt;br/&gt;    n
&lt;br/&gt;    
&lt;br/&gt;      7
&lt;br/&gt;      echo
&lt;br/&gt;      
&lt;br/&gt;    n
&lt;br/&gt;...
&lt;br/&gt;    
&lt;br/&gt;      5222
&lt;br/&gt;      xmpp-client
&lt;br/&gt;      Jabber Client Connection
&lt;br/&gt;    y
&lt;br/&gt;    
&lt;br/&gt;      5222
&lt;br/&gt;      xmpp-client
&lt;br/&gt;      
&lt;br/&gt;    n
&lt;br/&gt;    
&lt;br/&gt;      5269
&lt;br/&gt;      xmpp-server
&lt;br/&gt;      Jabber Server Connection
&lt;br/&gt;    y
&lt;br/&gt;    
&lt;br/&gt;      5269
&lt;br/&gt;      xmpp-server
&lt;br/&gt;      
&lt;br/&gt;    n
&lt;br/&gt;...
&lt;br/&gt;    
&lt;br/&gt;      60179
&lt;br/&gt;      fido
&lt;br/&gt;      fidonet EMSI over TCP
&lt;br/&gt;    n
&lt;br/&gt;  4369unknownrt&gt;5280unknown&lt;/p&gt;ort&gt;8000unknownport&gt;8001unknown/port&gt;
&lt;br/&gt;
&lt;br/&gt;&lt;/code&gt;</description>
            
            <pubDate>Thu, 09 Oct 2008 18:09:53 -0700</pubDate>
        </item>
            
        <item>
            <title>Creating a timestamp in Ruby</title>
            <link>http://swik.net/Ruby/Code+Snippets%3A+ruby/Creating+a+timestamp+in+Ruby/cg4zg</link>
            <description>&lt;code&gt;
&lt;br/&gt; # year + month + day + hour + minutes +seconds
&lt;br/&gt; Time.now.strftime(&quot;%y%m%d%H%M%S&quot;) # =&gt; &quot;081008115016&quot;
&lt;br/&gt;&lt;/code&gt;
&lt;br/&gt;
&lt;br/&gt;References:
&lt;br/&gt; - &lt;a href=&quot;http://almosteffortless.com//2007/07/29/the-perfect-timestamp/&quot;&gt;The Perfect Timestamp - almost effortless&lt;/a&gt; [almosteffortless.com]
&lt;br/&gt;
&lt;br/&gt;Additional code - Displaying a human friendly elapsed time
&lt;br/&gt;
&lt;br/&gt;&lt;code&gt;
&lt;br/&gt;def time_ago_or_time_stamp(from_time, to_time = Time.now, include_seconds = true, detail = false)
&lt;br/&gt;  from_time = from_time.to_time if from_time.respond_to?(:to_time)
&lt;br/&gt;  to_time = to_time.to_time if to_time.respond_to?(:to_time)
&lt;br/&gt;  distance_in_minutes = (((to_time - from_time).abs)/60).round
&lt;br/&gt;  distance_in_seconds = ((to_time - from_time).abs).round
&lt;br/&gt;  case distance_in_minutes
&lt;br/&gt;    when 0..1           then time = (distance_in_seconds     when 2..59          then time = &quot;#{distance_in_minutes} minutes ago&quot;
&lt;br/&gt;    when 60..90         then time = &quot;1 hour ago&quot;
&lt;br/&gt;    when 90..1440       then time = &quot;#{(distance_in_minutes.to_f / 60.0).round} hours ago&quot;
&lt;br/&gt;    when 1440..2160     then time = &#039;1 day ago&#039; # 1-1.5 days
&lt;br/&gt;    when 2160..2880     then time = &quot;#{(distance_in_minutes.to_f / 1440.0).round} days ago&quot; # 1.5-2 days
&lt;br/&gt;    else time = from_time.strftime(&quot;%a, %d %b %Y&quot;)
&lt;br/&gt;  end
&lt;br/&gt;  return time_stamp(from_time) if (detail &amp;&amp; distance_in_minutes &gt; 2880)
&lt;br/&gt;  return time
&lt;br/&gt;end
&lt;br/&gt;&lt;/code&gt;
&lt;br/&gt;
&lt;br/&gt;input:
&lt;br/&gt;a = Time.now
&lt;br/&gt;
&lt;br/&gt;output:
&lt;br/&gt;&gt;&gt; time_ago_or_time_stamp(a)
&lt;br/&gt;=&gt; &quot;45 seconds ago&quot;
&lt;br/&gt;&gt;&gt; time_ago_or_time_stamp(a)
&lt;br/&gt;=&gt; &quot;1 minute ago&quot;
&lt;br/&gt;&gt;&gt; time_ago_or_time_stamp(a)
&lt;br/&gt;=&gt; &quot;1 minute ago&quot;
&lt;br/&gt;&gt;&gt; time_ago_or_time_stamp(a)
&lt;br/&gt;=&gt; &quot;2 minutes ago&quot;
&lt;br/&gt;
&lt;br/&gt;
&lt;br/&gt;
&lt;br/&gt;</description>
            
            <pubDate>Wed, 08 Oct 2008 04:54:56 -0700</pubDate>
        </item>
            
        <item>
            <title>Drawing a line in the Maemo app</title>
            <link>http://swik.net/Ruby/Code+Snippets%3A+ruby/Drawing+a+line+in+the+Maemo+app/cg21x</link>
            <description>This script creates a Ruby Maemo application which displays a black diagonal line on a white background..
&lt;br/&gt;
&lt;br/&gt;&lt;code&gt;
&lt;br/&gt;#! /usr/bin/env ruby
&lt;br/&gt;#file: line.rb
&lt;br/&gt;require &#039;hildon&#039;
&lt;br/&gt;
&lt;br/&gt;area = Gtk::DrawingArea.new
&lt;br/&gt;
&lt;br/&gt;area.set_size_request(100,100)
&lt;br/&gt;area.signal_connect(&quot;expose_event&quot;) do
&lt;br/&gt;  alloc = area.allocation
&lt;br/&gt;  x1 = 100; y1 = 100; x2 = 400; y2 = 200
&lt;br/&gt;  area.window.draw_line(area.style.fg_gc(area.state), x1, y1, x2, y2)
&lt;br/&gt;
&lt;br/&gt;end
&lt;br/&gt;
&lt;br/&gt;Gtk::Window.new.add(area).show_all
&lt;br/&gt;
&lt;br/&gt;Gtk.main
&lt;br/&gt;
&lt;br/&gt;&lt;/code&gt;
&lt;br/&gt;
&lt;br/&gt;You can see the &lt;a href=&quot;http://twitxr.com/image/107274/&quot;&gt;output of the script on the N800&lt;/a&gt; [twitxr.com].
&lt;br/&gt;
&lt;br/&gt;Resources:
&lt;br/&gt; - &lt;a href=&quot;http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gdk%3A%3ADrawable#draw_line&quot;&gt;Gdk::Drawable - Ruby-GNOME2 Project Website&lt;/a&gt; [sourceforge.jp]
&lt;br/&gt; - &lt;a href=&quot;http://library.gnome.org/devel/gdk/stable/gdk-Drawing-Primitives.html&quot;&gt;Drawing Primitives&lt;/a&gt; [gnome.org]
&lt;br/&gt; - &lt;a href=&quot;http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk%3A%3ADrawingArea&quot;&gt;Gtk::DrawingArea - Ruby-GNOME2 Project Website&lt;/a&gt; [sourceforge.jp]</description>
            
            <pubDate>Tue, 07 Oct 2008 15:54:47 -0700</pubDate>
        </item>
            
        <item>
            <title>Display images in a Ruby Maemo application</title>
            <link>http://swik.net/Ruby/Code+Snippets%3A+ruby/Display+images+in+a+Ruby+Maemo+application/cg2wc</link>
            <description>This code was copied from the &lt;a href=&quot;http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk%3A%3ADrawingArea&quot;&gt;Gtk::DrawingArea - Ruby-GNOME2 Project Website&lt;/a&gt; [sourceforge.jp]
&lt;br/&gt;
&lt;br/&gt;&lt;code&gt;
&lt;br/&gt;#! /usr/bin/env ruby
&lt;br/&gt;#file: image2.rb
&lt;br/&gt;require &#039;hildon&#039;
&lt;br/&gt;
&lt;br/&gt;program = Hildon::Program.instance
&lt;br/&gt;window = program.add_window Hildon::Window.new
&lt;br/&gt;image = Gtk::Image.new(&quot;myfile.png&quot;)
&lt;br/&gt;event_box = Gtk::EventBox.new.add(image)
&lt;br/&gt;event_box.signal_connect(&quot;button_press_event&quot;) do
&lt;br/&gt;  puts &quot;Clicked.&quot;
&lt;br/&gt;end
&lt;br/&gt;window.add event_box
&lt;br/&gt;window.show_all
&lt;br/&gt;Gtk.main
&lt;br/&gt;&lt;/code&gt;
&lt;br/&gt;
&lt;br/&gt;You can see from the &lt;a href=&quot;http://twitxr.com/image/107228/&quot;&gt;output on the N800&lt;/a&gt; [twitxr.com] what the image looks like.
&lt;br/&gt;
&lt;br/&gt;Resources:
&lt;br/&gt; - &lt;a href=&quot;http://user-contributions.org/wikis/userwiki/index.php?title=Gtk_Image&quot;&gt;Gtk Image - UsercbWiki&lt;/a&gt; [user-contributions.org]
&lt;br/&gt; - &lt;a href=&quot;http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk%3A%3AImage&quot;&gt;Gtk::Image - Ruby-GNOME2 Project Website&lt;/a&gt; [sourceforge.jp]</description>
            
            <pubDate>Tue, 07 Oct 2008 14:54:18 -0700</pubDate>
        </item>
            
        <item>
            <title>Capturing mouse movement from a Ruby Maemo application</title>
            <link>http://swik.net/Ruby/Code+Snippets%3A+ruby/Capturing+mouse+movement+from+a+Ruby+Maemo+application/cg2wb</link>
            <description>This script simply displays an image and captures the movement of the stylus on the screen. 
&lt;br/&gt;
&lt;br/&gt;&lt;code&gt;
&lt;br/&gt;#! /usr/bin/env ruby
&lt;br/&gt;#file: mousemove2.rb
&lt;br/&gt;require &#039;hildon&#039;
&lt;br/&gt;
&lt;br/&gt;program = Hildon::Program.instance
&lt;br/&gt;window = program.add_window Hildon::Window.new
&lt;br/&gt;image = Gtk::Image.new(&quot;myfile.png&quot;)
&lt;br/&gt;event_box = Gtk::EventBox.new.add(image)
&lt;br/&gt;
&lt;br/&gt;event_box.signal_connect(&#039;motion_notify_event&#039;) do |item,  event|
&lt;br/&gt;  puts &#039;x: &#039;  + event.x.to_s + &#039;  y: &#039; + event.y.to_s
&lt;br/&gt;end
&lt;br/&gt;
&lt;br/&gt;event_box.signal_connect(&quot;button_press_event&quot;) do
&lt;br/&gt;  puts &quot;Clicked.&quot;
&lt;br/&gt;end
&lt;br/&gt;
&lt;br/&gt;window.add event_box
&lt;br/&gt;window.show_all
&lt;br/&gt;Gtk.main
&lt;br/&gt;
&lt;br/&gt;&lt;/code&gt;
&lt;br/&gt;
&lt;br/&gt;output (while moving the stylus along the path of a &lt;a href=&quot;http://twitxr.com/image/107228/&quot;&gt;black squiggle on the screen&lt;/a&gt; [twitxr.com]) :
&lt;br/&gt;
&lt;br/&gt;Clicked.
&lt;br/&gt;...
&lt;br/&gt;x: 479.0  y: 128.0
&lt;br/&gt;x: 479.0  y: 128.0
&lt;br/&gt;x: 479.0  y: 128.0
&lt;br/&gt;x: 480.0  y: 129.0
&lt;br/&gt;x: 480.0  y: 129.0
&lt;br/&gt;x: 480.0  y: 129.0
&lt;br/&gt;x: 482.0  y: 129.0
&lt;br/&gt;x: 486.0  y: 128.0
&lt;br/&gt;x: 488.0  y: 128.0
&lt;br/&gt;x: 488.0  y: 126.0
&lt;br/&gt;x: 488.0  y: 128.0
&lt;br/&gt;x: 488.0  y: 128.0
&lt;br/&gt;
&lt;br/&gt;Note: The stylus touch-screen behaves almost the same as the mouse except the stylus has to impact on to the device to make movement which triggers a &#039;clicked&#039; event to begin with.
&lt;br/&gt;
&lt;br/&gt;Resouces:
&lt;br/&gt; - &lt;a href=&quot;http://ruby-gnome2.sourceforge.jp/hiki.cgi?ruby-gtk-object-hierarchy&quot;&gt;Ruby/GTK Object Hierarchy - Ruby-GNOME2 Project Website&lt;/a&gt; [sourceforge.jp]
&lt;br/&gt; - &lt;a href=&quot;http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/22225&quot;&gt;[ruby-talk:22225] ruby-gtk: freq of mouse events: linux vs win nt&lt;/a&gt; [nagaokaut.ac.jp]
&lt;br/&gt; - &lt;a href=&quot;http://ruby-gnome.sourceforge.net/programming/signal.html&quot;&gt;Ruby/GTK Programming (signals)&lt;/a&gt; [sourceforge.net]
&lt;br/&gt; - &lt;a href=&quot;http://library.gnome.org/devel/gtk/2.14/ch01.html&quot;&gt;Object Hierarchy&lt;/a&gt; [gnome.org]
&lt;br/&gt; - &lt;a href=&quot;http://maemo.org/api_refs/3.0/hildon-docs/hildon-libs/index.html&quot;&gt;hildon-libs 0.14.11 Reference Manual&lt;/a&gt; [maemo.org]</description>
            
            <pubDate>Tue, 07 Oct 2008 14:54:18 -0700</pubDate>
        </item>
            
        <item>
            <title>Drawing an ellipsis in a Ruby Maemo application</title>
            <link>http://swik.net/Ruby/Code+Snippets%3A+ruby/Drawing+an+ellipsis+in+a+Ruby+Maemo+application/cg2pe</link>
            <description>This code was copied from the &lt;a href=&quot;http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk%3A%3ADrawingArea&quot;&gt;Gtk::DrawingArea - Ruby-GNOME2 Project Website&lt;/a&gt; [sourceforge.jp]
&lt;br/&gt;
&lt;br/&gt;&lt;code&gt;
&lt;br/&gt;#! /usr/bin/env ruby
&lt;br/&gt;#file: elipse.rb
&lt;br/&gt;require &#039;hildon&#039;
&lt;br/&gt;
&lt;br/&gt;area = Gtk::DrawingArea.new
&lt;br/&gt;
&lt;br/&gt;area.set_size_request(100,100)
&lt;br/&gt;area.signal_connect(&quot;expose_event&quot;) do
&lt;br/&gt;  alloc = area.allocation
&lt;br/&gt;  area.window.draw_arc(area.style.fg_gc(area.state), true, 
&lt;br/&gt;                       0, 0, alloc.width, alloc.height, 0, 64 * 360) 
&lt;br/&gt;end
&lt;br/&gt;
&lt;br/&gt;Gtk::Window.new.add(area).show_all
&lt;br/&gt;
&lt;br/&gt;Gtk.main
&lt;br/&gt;
&lt;br/&gt;&lt;/code&gt;
&lt;br/&gt;
&lt;br/&gt;You can see from the &lt;a href=&quot;http://twitxr.com/image/107217/&quot;&gt;output on the N800&lt;/a&gt; [twitxr.com] which shows a black ellipsis.</description>
            
            <pubDate>Tue, 07 Oct 2008 13:54:26 -0700</pubDate>
        </item>
            
        <item>
            <title>Adding a 2nd level menu to a Ruby Maemo application</title>
            <link>http://swik.net/Ruby/Code+Snippets%3A+ruby/Adding+a+2nd+level+menu+to+a+Ruby+Maemo+application/cg1vu</link>
            <description>Here is a script to run a Ruby Maemo application which has a scroll bar and a 2nd level menu box.  The first level menu box would be application&#039;s control menu box.
&lt;br/&gt;
&lt;br/&gt;&lt;code&gt;
&lt;br/&gt;#! /usr/bin/env ruby
&lt;br/&gt;#file: menu2.rb
&lt;br/&gt;
&lt;br/&gt;#require &#039;gtk&#039;
&lt;br/&gt;require &#039;hildon&#039;
&lt;br/&gt;
&lt;br/&gt;program = Hildon::Program.instance
&lt;br/&gt;
&lt;br/&gt;#window = Gtk::Window.new(Gtk::WINDOW_TOPLEVEL)
&lt;br/&gt;window = program.add_window Hildon::Window.new
&lt;br/&gt;
&lt;br/&gt;mbar = Gtk::MenuBar.new
&lt;br/&gt;filemitem = Gtk::MenuItem.new(&#039;File&#039;)
&lt;br/&gt;filemitem.show
&lt;br/&gt;filemenu = Gtk::Menu.new
&lt;br/&gt;item1 = Gtk::MenuItem.new(&#039;Open&#039;)
&lt;br/&gt;item1.show
&lt;br/&gt;filemenu.add item1
&lt;br/&gt;item2 = Gtk::MenuItem.new(&#039;Save&#039;)
&lt;br/&gt;item2.show
&lt;br/&gt;filemenu.add item2
&lt;br/&gt;item3 = Gtk::MenuItem.new(&#039;Quit&#039;)
&lt;br/&gt;item3.show
&lt;br/&gt;filemenu.add item3
&lt;br/&gt;filemitem.set_submenu filemenu
&lt;br/&gt;mbar.append filemitem
&lt;br/&gt;mbar.show
&lt;br/&gt;
&lt;br/&gt;vadj = Gtk::Adjustment.new(0,0,0,0,0,0)
&lt;br/&gt;
&lt;br/&gt;vs = Gtk::VScrollbar.new(vadj)
&lt;br/&gt;
&lt;br/&gt;
&lt;br/&gt;hbox = Gtk::HBox.new(false, 0)
&lt;br/&gt;
&lt;br/&gt;hbox.pack_start vs, false, false, 0
&lt;br/&gt;
&lt;br/&gt;vbox = Gtk::VBox.new(false, 0)
&lt;br/&gt;vbox.pack_start mbar, false, false, 0
&lt;br/&gt;vbox.pack_start hbox, true, true, 0
&lt;br/&gt;vbox.show
&lt;br/&gt;
&lt;br/&gt;window.add vbox
&lt;br/&gt;
&lt;br/&gt;vs.show
&lt;br/&gt;hbox.show
&lt;br/&gt;window.show
&lt;br/&gt;Gtk.main
&lt;br/&gt;
&lt;br/&gt;&lt;/code&gt;
&lt;br/&gt;
&lt;br/&gt;You can see from the &lt;a href=&quot;http://twitxr.com/image/107128/&quot;&gt;output on the N800&lt;/a&gt; [twitxr.com] as I selected an item from the menu box&#039;.
&lt;br/&gt;
&lt;br/&gt;Resources:
&lt;br/&gt; - &lt;a href=&quot;http://snippets.dzone.com/posts/show/6214&quot;&gt;Adding a text entry box in a Ruby Maemo application&lt;/a&gt; [dzone.com]
&lt;br/&gt; - &lt;a href=&quot;http://ruby-gnome.sourceforge.net/programming/menu.html&quot;&gt;Ruby/Gtk Programming&lt;/a&gt; [sourceforge.net]</description>
            
            <pubDate>Tue, 07 Oct 2008 09:56:31 -0700</pubDate>
        </item>
            
        <item>
            <title>Adding a file selection dialog window to a Ruby Maemo application</title>
            <link>http://swik.net/Ruby/Code+Snippets%3A+ruby/Adding+a+file+selection+dialog+window+to+a+Ruby+Maemo+application/cg1vt</link>
            <description>Run a Ruby Maemo application which displays the system&#039;s file selection dialog box.
&lt;br/&gt;
&lt;br/&gt;&lt;code&gt;
&lt;br/&gt;#! /usr/bin/env ruby
&lt;br/&gt;#file: fileselection.rb
&lt;br/&gt;
&lt;br/&gt;#require &#039;gtk&#039;
&lt;br/&gt;require &#039;hildon&#039;
&lt;br/&gt;
&lt;br/&gt;program = Hildon::Program.instance
&lt;br/&gt;
&lt;br/&gt;fs = Gtk::FileSelection.new(&#039;File Selection Example&#039;)
&lt;br/&gt;fs.show
&lt;br/&gt;
&lt;br/&gt;Gtk.main
&lt;br/&gt;
&lt;br/&gt;&lt;/code&gt;
&lt;br/&gt;You can see from the &lt;a href=&quot;http://twitxr.com/image/107133/&quot;&gt;output on the N800&lt;/a&gt; [twitxr.com] as I viewed the File Selection Example dialog box&#039;.
&lt;br/&gt;
&lt;br/&gt;Resources:
&lt;br/&gt; - &lt;a href=&quot;http://snippets.dzone.com/posts/show/6214&quot;&gt;Adding a text entry box in a Ruby Maemo application&lt;/a&gt; [dzone.com]
&lt;br/&gt; - &lt;a href=&quot;http://ruby-gnome.sourceforge.net/programming/menu.html&quot;&gt;Ruby/Gtk Programming&lt;/a&gt; [sourceforge.net]</description>
            
            <pubDate>Tue, 07 Oct 2008 09:56:31 -0700</pubDate>
        </item>
            
        <item>
            <title>Adding a text entry box in a Ruby Maemo application</title>
            <link>http://swik.net/Ruby/Code+Snippets%3A+ruby/Adding+a+text+entry+box+in+a+Ruby+Maemo+application/cg1m6</link>
            <description>Here is a script to run a Ruby Maemo application which has a text entry box.  There&#039;s nothing special about this code other than it uses &#039;hildon&#039; instead of Gtk. 
&lt;br/&gt;
&lt;br/&gt;The only code changes from the original Ruby GTK code was to comment out the gtk include file and the Gtk Window.new statement.
&lt;br/&gt;
&lt;br/&gt;&lt;code&gt;
&lt;br/&gt;#! /usr/bin/env ruby
&lt;br/&gt;#file: entry.rb
&lt;br/&gt;
&lt;br/&gt;#require &#039;gtk&#039;
&lt;br/&gt;require &#039;hildon&#039;
&lt;br/&gt;
&lt;br/&gt;program = Hildon::Program.instance
&lt;br/&gt;
&lt;br/&gt;#window = Gtk::Window.new(Gtk::WINDOW_TOPLEVEL)
&lt;br/&gt;window = program.add_window Hildon::Window.new
&lt;br/&gt;
&lt;br/&gt;label = Gtk::Label.new(&#039;Name:&#039;)
&lt;br/&gt;entry = Gtk::Entry.new
&lt;br/&gt;entry.set_text(&#039;John&#039;)
&lt;br/&gt;box = Gtk::HBox.new(false, 0)
&lt;br/&gt;box.pack_start label, true, true, 5
&lt;br/&gt;box.pack_start entry, true, true, 5
&lt;br/&gt;label.show
&lt;br/&gt;entry.show
&lt;br/&gt;
&lt;br/&gt;entry.signal_connect(&#039;activate&#039;) {|widget|
&lt;br/&gt;  print &quot;Your name is #{entry.get_text}\n&quot;
&lt;br/&gt;}
&lt;br/&gt;
&lt;br/&gt;window.add(box)
&lt;br/&gt;box.show
&lt;br/&gt;window.show
&lt;br/&gt;Gtk.main
&lt;br/&gt;&lt;/code&gt;
&lt;br/&gt;
&lt;br/&gt;You can see from the &lt;a href=&quot;http://twitxr.com/image/107118/&quot;&gt;output on the N800&lt;/a&gt; [twitxr.com] as I replaced the entry value &#039;John&#039; with &#039;Jim&#039;.
&lt;br/&gt;
&lt;br/&gt;Resources:
&lt;br/&gt; - &lt;a href=&quot;http://ruby-gnome.sourceforge.net/programming/entry.html&quot;&gt;エントリウィジェットとコンボウィジェット - Ruby/Gtk Programming&lt;/a&gt; [sourceforge.net]
&lt;br/&gt; - &lt;a href=&quot;http://ruby-gnome.sourceforge.net/programming/hello.html&quot;&gt;Hello World in Ruby/GTK&lt;/a&gt; [sourceforge.net]</description>
            
            <pubDate>Tue, 07 Oct 2008 08:54:12 -0700</pubDate>
        </item>
            
        <item>
            <title>Adding a combo box to a Ruby Maemo application</title>
            <link>http://swik.net/Ruby/Code+Snippets%3A+ruby/Adding+a+combo+box+to+a+Ruby+Maemo+application/cg1m5</link>
            <description>Here is a script to run a Ruby Maemo application which has a combo box.
&lt;br/&gt;
&lt;br/&gt;&lt;code&gt;
&lt;br/&gt;#! /usr/bin/env ruby
&lt;br/&gt;#file: combo.rb
&lt;br/&gt;
&lt;br/&gt;#require &#039;gtk&#039;
&lt;br/&gt;require &#039;hildon&#039;
&lt;br/&gt;
&lt;br/&gt;program = Hildon::Program.instance
&lt;br/&gt;
&lt;br/&gt;#window = Gtk::Window.new(Gtk::WINDOW_TOPLEVEL)
&lt;br/&gt;window = program.add_window Hildon::Window.new
&lt;br/&gt;
&lt;br/&gt;combo = Gtk::Combo.new
&lt;br/&gt;combo.set_popdown_strings([&#039;http://www.netlab.co.jp/ruby/&#039;,
&lt;br/&gt;			    &#039;http://ruby.freak.ne.jp/&#039;])
&lt;br/&gt;combo.entry.set_text &#039;&#039;
&lt;br/&gt;window.add(combo)
&lt;br/&gt;combo.show
&lt;br/&gt;window.show
&lt;br/&gt;Gtk.main
&lt;br/&gt;&lt;/code&gt;
&lt;br/&gt;
&lt;br/&gt;You can see from the &lt;a href=&quot;http://twitxr.com/image/107122/&quot;&gt;output on the N800&lt;/a&gt; [twitxr.com] as I selected an item from the combo box&#039;.
&lt;br/&gt;
&lt;br/&gt;Resources:
&lt;br/&gt; - &lt;a href=&quot;http://snippets.dzone.com/posts/show/6214&quot;&gt;Adding a text entry box in a Ruby Maemo application&lt;/a&gt; [dzone.com]
&lt;br/&gt; - &lt;a href=&quot;http://ruby-gnome.sourceforge.net/programming/entry.html&quot;&gt;エントリウィジェットとコンボウィジェット - Ruby/Gtk Programming&lt;/a&gt; [sourceforge.net]
&lt;br/&gt; - &lt;a href=&quot;http://ruby-gnome.sourceforge.net/programming/hello.html&quot;&gt;Hello World in Ruby/GTK&lt;/a&gt; [sourceforge.net]</description>
            
            <pubDate>Tue, 07 Oct 2008 08:54:12 -0700</pubDate>
        </item>
            
    </channel>
</rss>
