<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>dan.thoughts &#187; Ruby</title>
	<atom:link href="http://blog.sosedoff.com/category/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.sosedoff.com</link>
	<description>Web-development, PHP, Ruby, Sinatra, Merb, Rails, MySQL, SQLite, Web Services.</description>
	<lastBuildDate>Sat, 03 Jul 2010 05:46:21 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Debugging PHP applications in terminal</title>
		<link>http://blog.sosedoff.com/2010/07/03/debugging-php-applications-in-terminal/</link>
		<comments>http://blog.sosedoff.com/2010/07/03/debugging-php-applications-in-terminal/#comments</comments>
		<pubDate>Sat, 03 Jul 2010 05:45:39 +0000</pubDate>
		<dc:creator>Dan Sosedoff</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[console]]></category>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[eventmachine]]></category>
		<category><![CDATA[server]]></category>

		<guid isPermaLink="false">http://blog.sosedoff.com/?p=251</guid>
		<description><![CDATA[Most of Ruby web frameworks have terminal logging in development environments. It makes application debugging process much easier than using file logging. Especially for AJAX requests. Of course there is simple solution &#8211; use Firebug and javascript console. Unfortunately it is not that convenient. 
So, one day i came up with idea to make the [...]]]></description>
			<content:encoded><![CDATA[<p>Most of Ruby web frameworks have terminal logging in development environments. It makes application debugging process much easier than using file logging. Especially for AJAX requests. Of course there is simple solution &#8211; use Firebug and javascript console. Unfortunately it is not that convenient. </p>
<p>So, one day i came up with idea to make the same ruby-like style of application logging, even with colorized output.<br />
I decided to use <a href="http://eventmachine.rubyforge.org/">EventMachine</a> library as a server platform. And API is based on JSON packets, via <a href="http://flori.github.com/json/">json/pure</a>. Simple, isnt it?</p>
<p>And i called it DebugServer. Pretty understandable <img src='http://blog.sosedoff.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h3>Installation</h3>
<p>To install just type</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> debugserver</pre></div></div>

<p>And for information type:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ debugserver <span style="color: #660033;">-i</span></pre></div></div>

<pre>
Usage: debugserver [options]
    -h, --host HOSTNAME              Server hostname
    -p, --port PORT                  Server port
    -i, --info                       Get usage information
</pre>
<p>By default it will start on localhost:9000. </p>
<h3>Usage in PHP</h3>
<p>First, download library from GitHub repository: <a href="http://github.com/sosedoff/debugclient-php">http://github.com/sosedoff/debugclient-php</a></p>
<p>And then:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// place it into app initialization file</span>
<span style="color: #000088;">$debug</span> <span style="color: #339933;">=</span> DebugClient<span style="color: #339933;">::</span><span style="color: #004000;">instance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$debug</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">connect</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// .... and write it to terminal output</span>
<span style="color: #000088;">$obj</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
  <span style="color: #0000ff;">'id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">rand</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #208080;">0xFFFF</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
  <span style="color: #0000ff;">'name'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Sample name'</span><span style="color: #339933;">,</span>
  <span style="color: #0000ff;">'time'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">strftime</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'%m-%d-%Y'</span><span style="color: #339933;">,</span> <span style="color: #990000;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// these functions are globally defined</span>
debug_clear<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// clear terminal</span>
debug<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'This is a plain text message.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
debug_info<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'This is an informational message.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
debug_warning<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'This is a warning message.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
debug_error<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'This is an error message.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
debug_dump<span style="color: #009900;">&#40;</span><span style="color: #000088;">$obj</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// optional</span>
<span style="color: #000088;">$debug</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Results:<br />
<img src="http://blog.sosedoff.com/wp-content/uploads/2010/07/debugserver.png" alt="Output" /></p>
<h3>Sources</h3>
<p>DebugServer: <a href="http://github.com/sosedoff/debugserver">http://github.com/sosedoff/debugserver</a><br />
PHP Client: <a href="http://github.com/sosedoff/debugclient-php">http://github.com/sosedoff/debugclient-php</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sosedoff.com/2010/07/03/debugging-php-applications-in-terminal/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Generate sitemaps with Ruby and XmlSitemap gem</title>
		<link>http://blog.sosedoff.com/2010/06/18/generate-sitemaps-with-ruby-and-xmlsitemap-gem/</link>
		<comments>http://blog.sosedoff.com/2010/06/18/generate-sitemaps-with-ruby-and-xmlsitemap-gem/#comments</comments>
		<pubDate>Fri, 18 Jun 2010 23:10:38 +0000</pubDate>
		<dc:creator>Dan Sosedoff</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[gems]]></category>
		<category><![CDATA[generation]]></category>
		<category><![CDATA[merb]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[sinatra]]></category>
		<category><![CDATA[sitemap]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://blog.sosedoff.com/?p=244</guid>
		<description><![CDATA[Made a simple gem for website sitemap generation. Could be used in any Ruby/Rails/Merb/Sinatra application. It does not have any caching in that case if you want to use framework built-in cache methods. 
Installation:

$ sudo gem install xml-sitemap

Example

pages = Page.all&#40;:order =&#62; &#91;:updated_at.desc&#93; # DM model
map = XmlSitemap::Map.new&#40;'somedomain.com'&#41; do &#124;m&#124;
  m.add&#40;:url =&#62; '/', :period =&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>Made a simple gem for website sitemap generation. Could be used in any Ruby/Rails/Merb/Sinatra application. It does not have any caching in that case if you want to use framework built-in cache methods. </p>
<p>Installation:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> xml-sitemap</pre></div></div>

<h3>Example</h3>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">pages = Page.<span style="color:#9900CC;">all</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:order</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:updated_at</span>.<span style="color:#9900CC;">desc</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#008000; font-style:italic;"># DM model</span>
map = <span style="color:#6666ff; font-weight:bold;">XmlSitemap::Map</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'somedomain.com'</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>m<span style="color:#006600; font-weight:bold;">|</span>
  m.<span style="color:#9900CC;">add</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:url</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'/'</span>, <span style="color:#ff3333; font-weight:bold;">:period</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:daily</span>, <span style="color:#ff3333; font-weight:bold;">:priority</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">1.0</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  m.<span style="color:#9900CC;">add</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:url</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'/contractors'</span>, <span style="color:#ff3333; font-weight:bold;">:period</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:daily</span>, <span style="color:#ff3333; font-weight:bold;">:priority</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">1.0</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  pages.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>p<span style="color:#006600; font-weight:bold;">|</span>
    m.<span style="color:#9900CC;">add</span><span style="color:#006600; font-weight:bold;">&#40;</span>
      <span style="color:#ff3333; font-weight:bold;">:url</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> url_for_page<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0066; font-weight:bold;">p</span><span style="color:#006600; font-weight:bold;">&#41;</span>,
      <span style="color:#ff3333; font-weight:bold;">:updated</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#CC0066; font-weight:bold;">p</span>.<span style="color:#9900CC;">updated_at</span>,
      <span style="color:#ff3333; font-weight:bold;">:priority</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">0.5</span>,
      <span style="color:#ff3333; font-weight:bold;">:period</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:never</span>
    <span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#008000; font-style:italic;"># render the sitemap</span>
<span style="color:#CC0066; font-weight:bold;">puts</span> map.<span style="color:#9900CC;">render</span></pre></div></div>

<h3>Sinatra Example</h3>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># ... your code</span>
&nbsp;
get <span style="color:#996600;">'/sitemap.xml'</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  map = <span style="color:#6666ff; font-weight:bold;">XmlSitemap::Map</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'domain.com'</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>m<span style="color:#006600; font-weight:bold;">|</span>
    m.<span style="color:#9900CC;">add</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:url</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'/'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    m.<span style="color:#9900CC;">add</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:url</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'/posts'</span>, <span style="color:#ff3333; font-weight:bold;">:period</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:weekly</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  headers<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'Content-Type'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">'text/xml'</span>
  map.<span style="color:#9900CC;">render</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># ... more code</span></pre></div></div>

<h3>Options</h3>
<p>:url &#8211; page path, relative to domain (ex.: /test), String.<br />
:period &#8211; freqchange attribute, Symbol, :none, :never, :always, :hourly, :daily, :weekly, :monthly, :yearly<br />
:priority &#8211; priority attribute, Float class,(0.0..1.0)<br />
:updated &#8211; (optional) last_update attribute, Time class</p>
<h3>Source Code</h3>
<p><a href="http://github.com/sosedoff/xml-sitemap">http://github.com/sosedoff/xml-sitemap</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sosedoff.com/2010/06/18/generate-sitemaps-with-ruby-and-xmlsitemap-gem/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Amazon product images on your website</title>
		<link>http://blog.sosedoff.com/2010/06/15/using-amazon-product-images-on-your-website/</link>
		<comments>http://blog.sosedoff.com/2010/06/15/using-amazon-product-images-on-your-website/#comments</comments>
		<pubDate>Tue, 15 Jun 2010 06:20:17 +0000</pubDate>
		<dc:creator>Dan Sosedoff</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Web Services]]></category>
		<category><![CDATA[amazon]]></category>
		<category><![CDATA[ecs]]></category>
		<category><![CDATA[images]]></category>
		<category><![CDATA[scaling]]></category>

		<guid isPermaLink="false">http://blog.sosedoff.com/?p=237</guid>
		<description><![CDATA[Amazon has an awesome image service. You can use their product images on your site, adjusting them for you needs. All you have to know &#8211; one image url of your product. Having that string will provide you an access to its dynamic image scaling service which i had to use recently. 
So, lets say [...]]]></description>
			<content:encoded><![CDATA[<p>Amazon has an awesome image service. You can use their product images on your site, adjusting them for you needs. All you have to know &#8211; one image url of your product. Having that string will provide you an access to its dynamic image scaling service which i had to use recently. </p>
<p>So, lets say you have books on your website, but you dont have any good images for them. There is 2 ways to solve your problem: 1) download it from whatever place and resize 2) use amazon!</p>
<p>Here goes small overview.</p>
<p>Unfortunately, i didnt have any time to play with image service for different countries, but i assume that wont change that much.  Lets take a look on a regular image:</p>
<p>http://ecx.images-amazon.com/images/I/41ygBmdaIfL._SL500_SS100_.jpg</p>
<p>It has different parts:<br />
1) URL base: http://ecx.images-amazon.com/images/I/<br />
2) Image code: 41ygBmdaIfL<br />
3) Size format (surrounded by underscores): _SL500_SS100_<br />
4) Format: jpg/gif/png</p>
<p>Some words about image format. It can vary from square thumbnails to images with specific max width and height. For example: _SX100_ will produce image that 100 pixels wide, height will be calculated proportionally. SH100 will give opposite result, scaled by 100 pixels maximum height, SS100 &#8211; 100&#215;100 pixels thumbnail. And so on, you can find other similar crop codes while exploring amazon store on different pages, all you need is to take a look on image sources. </p>
<p>Now, we need to use this with Ruby:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'net/http'</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">module</span> Amazon
  <span style="color:#008000; font-style:italic;"># parse amazon image url and get image code and extension</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">parse_image</span><span style="color:#006600; font-weight:bold;">&#40;</span>url<span style="color:#006600; font-weight:bold;">&#41;</span>
    result = url.<span style="color:#9900CC;">scan</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span>^http:\<span style="color:#006600; font-weight:bold;">/</span>\<span style="color:#006600; font-weight:bold;">/</span>ecx.<span style="color:#9900CC;">images</span><span style="color:#006600; font-weight:bold;">-</span>amazon.<span style="color:#9900CC;">com</span>\<span style="color:#006600; font-weight:bold;">/</span>images\<span style="color:#006600; font-weight:bold;">/</span>I\<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#91;</span>a<span style="color:#006600; font-weight:bold;">-</span>z0<span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">9</span>\<span style="color:#006600; font-weight:bold;">-</span>\<span style="color:#006600; font-weight:bold;">%</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006666;">1</span>,<span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#40;</span>.<span style="color:#006600; font-weight:bold;">*</span><span style="color:#006600; font-weight:bold;">&#41;</span>_.<span style="color:#006600; font-weight:bold;">&#40;</span>jpg<span style="color:#006600; font-weight:bold;">|</span>jpeg<span style="color:#006600; font-weight:bold;">|</span>gif<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">/</span>i<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">unless</span> result.<span style="color:#0000FF; font-weight:bold;">nil</span>?
      <span style="color:#9966CC; font-weight:bold;">unless</span> result<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#0000FF; font-weight:bold;">nil</span>?
        match = result.<span style="color:#9900CC;">first</span>
        <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#006600; font-weight:bold;">&#123;</span>:code <span style="color:#006600; font-weight:bold;">=&gt;</span> match.<span style="color:#9900CC;">first</span>.<span style="color:#9900CC;">to_s</span>, <span style="color:#ff3333; font-weight:bold;">:extension</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> match.<span style="color:#9900CC;">last</span>.<span style="color:#9900CC;">to_s</span><span style="color:#006600; font-weight:bold;">&#125;</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># make a new amazon image url based on code and size</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">make_image</span><span style="color:#006600; font-weight:bold;">&#40;</span>image, size<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#996600;">&quot;http://ecx.images-amazon.com/images/I/#{image[:code]}._#{size.upcase}.#{image[:extension]}&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># check if actual image exists</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">check_image</span><span style="color:#006600; font-weight:bold;">&#40;</span>url<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">begin</span>
      uri = <span style="color:#CC00FF; font-weight:bold;">URI</span>.<span style="color:#9900CC;">parse</span><span style="color:#006600; font-weight:bold;">&#40;</span>url<span style="color:#006600; font-weight:bold;">&#41;</span>
      req = <span style="color:#6666ff; font-weight:bold;">Net::HTTP::Get</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>uri.<span style="color:#9900CC;">path</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      res = <span style="color:#6666ff; font-weight:bold;">Net::HTTP</span>.<span style="color:#9900CC;">start</span><span style="color:#006600; font-weight:bold;">&#40;</span>uri.<span style="color:#9900CC;">host</span>, uri.<span style="color:#9900CC;">port</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>http<span style="color:#006600; font-weight:bold;">|</span> http.<span style="color:#9900CC;">request</span><span style="color:#006600; font-weight:bold;">&#40;</span>req<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
      <span style="color:#0000FF; font-weight:bold;">return</span> res.<span style="color:#9900CC;">code</span> == <span style="color:#996600;">'200'</span> <span style="color:#006600; font-weight:bold;">&amp;&amp;</span> res.<span style="color:#9900CC;">content_length</span>.<span style="color:#9900CC;">to_i</span> <span style="color:#006600; font-weight:bold;">&gt;</span> <span style="color:#006666;">0</span>
    <span style="color:#9966CC; font-weight:bold;">rescue</span> <span style="color:#CC00FF; font-weight:bold;">Exception</span>
      <span style="color:#0000FF; font-weight:bold;">false</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>And usage:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">url = <span style="color:#996600;">'http://ecx.images-amazon.com/images/I/51O65dIoZCL._SX117_.jpg'</span>
info = Amazon.<span style="color:#9900CC;">parse_image</span><span style="color:#006600; font-weight:bold;">&#40;</span>url<span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">unless</span> info.<span style="color:#0000FF; font-weight:bold;">nil</span>?
  new_url = Amazon.<span style="color:#9900CC;">make_image</span><span style="color:#006600; font-weight:bold;">&#40;</span>info, <span style="color:#996600;">'sx100'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">if</span> Amazon.<span style="color:#9900CC;">check_image</span><span style="color:#006600; font-weight:bold;">&#40;</span>new_url<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Cool! Resized image: #{new_url}&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">else</span>
    <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Sorry, this image does not exist!&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">else</span>
  <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Cant identify image!&quot;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Some notes about the process. The only reason why method &#8220;check_image&#8221; uses GET method instead of HEAD is because if image cannot be generated or not found in amazon`s cache the response is still valid sometimes. I`ve checked it on 50k images and sometimes HEAD request indicates that response is valid while it not supposed to. Otherwise i would use HEAD.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sosedoff.com/2010/06/15/using-amazon-product-images-on-your-website/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Handy HTTP requests with Curb and Ruby</title>
		<link>http://blog.sosedoff.com/2010/06/13/handy-http-requests-with-curb-and-ruby/</link>
		<comments>http://blog.sosedoff.com/2010/06/13/handy-http-requests-with-curb-and-ruby/#comments</comments>
		<pubDate>Sun, 13 Jun 2010 05:43:49 +0000</pubDate>
		<dc:creator>Dan Sosedoff</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Web Services]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[crawlers]]></category>
		<category><![CDATA[curb]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[networking]]></category>
		<category><![CDATA[requests]]></category>

		<guid isPermaLink="false">http://blog.sosedoff.com/?p=232</guid>
		<description><![CDATA[While working on one of the projects, i tried to find multi-purpose HTTP request class that can use different network interfaces/ip addresses with retry option (if connection slow or server not responding for some reason). 
Here is a small class wrapper build on top of Ruby Curb implemented as a module:

module ApiRequest
  USER_AGENTS = [...]]]></description>
			<content:encoded><![CDATA[<p>While working on one of the projects, i tried to find multi-purpose HTTP request class that can use different network interfaces/ip addresses with retry option (if connection slow or server not responding for some reason). </p>
<p>Here is a small class wrapper build on top of Ruby <a href="http://curb.rubyforge.org/">Curb</a> implemented as a module:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">module</span> ApiRequest
  USER_AGENTS = <span style="color:#006600; font-weight:bold;">&#91;</span>
    <span style="color:#996600;">'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3'</span>,
    <span style="color:#996600;">'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727)'</span>,
    <span style="color:#996600;">'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.3) Gecko/20100423 Ubuntu/10.04 (lucid) Firefox/3.6.3'</span>,
    <span style="color:#996600;">'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.70 Safari/533.4'</span>,
    <span style="color:#996600;">'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.2) Gecko/20100323 Namoroka/3.6.2'</span>,
    <span style="color:#996600;">'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.9) Gecko/20100401 Ubuntu/9.10 (karmic) Firefox/3.5.9'</span>
  <span style="color:#006600; font-weight:bold;">&#93;</span>
&nbsp;
  CONNECTION_TIMEOUT = <span style="color:#006666;">10</span>
&nbsp;
  @@interfaces = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># get random user-agent string for usage</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> random_agent
    USER_AGENTS<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#CC0066; font-weight:bold;">rand</span><span style="color:#006600; font-weight:bold;">&#40;</span>USER_AGENTS.<span style="color:#9900CC;">size</span><span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#93;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># get random IP/network interface specified in @@interfaces</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> random_interface
    size = @@interfaces.<span style="color:#9900CC;">size</span>
    size <span style="color:#006600; font-weight:bold;">&gt;</span> <span style="color:#006666;">0</span> ? @@interfaces<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#CC0066; font-weight:bold;">rand</span><span style="color:#006600; font-weight:bold;">&#40;</span>size<span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#93;</span> : <span style="color:#0000FF; font-weight:bold;">nil</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># perform request, assign_to - specify network interface/ip</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> perform<span style="color:#006600; font-weight:bold;">&#40;</span>url, assign_to=<span style="color:#0000FF; font-weight:bold;">nil</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#CC0066; font-weight:bold;">puts</span> url
    interface = assign_to.<span style="color:#0000FF; font-weight:bold;">nil</span>? ? <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">random_interface</span> : assign_to
    req = <span style="color:#6666ff; font-weight:bold;">Curl::Easy</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>url<span style="color:#006600; font-weight:bold;">&#41;</span>
    req.<span style="color:#9900CC;">timeout</span> = CONNECTION_TIMEOUT
    req.<span style="color:#9900CC;">interface</span> = interface <span style="color:#9966CC; font-weight:bold;">unless</span> interface.<span style="color:#0000FF; font-weight:bold;">nil</span>?
    req.<span style="color:#9900CC;">headers</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'User-Agent'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">random_agent</span>
    <span style="color:#9966CC; font-weight:bold;">begin</span>
      req.<span style="color:#9900CC;">perform</span>
      <span style="color:#9966CC; font-weight:bold;">if</span> req.<span style="color:#9900CC;">response_code</span> == <span style="color:#006666;">200</span>
        <span style="color:#0000FF; font-weight:bold;">return</span> req.<span style="color:#9900CC;">downloaded_bytes</span> <span style="color:#006600; font-weight:bold;">&gt;</span> <span style="color:#006666;">0</span> ? req.<span style="color:#9900CC;">body_str</span> : <span style="color:#0000FF; font-weight:bold;">nil</span>
      <span style="color:#9966CC; font-weight:bold;">else</span>
        <span style="color:#0000FF; font-weight:bold;">nil</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">rescue</span> <span style="color:#CC00FF; font-weight:bold;">Exception</span>
      <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#0000FF; font-weight:bold;">nil</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># perform request by number of attempts</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> fetch<span style="color:#006600; font-weight:bold;">&#40;</span>url, attempts=<span style="color:#006666;">3</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    result = <span style="color:#0000FF; font-weight:bold;">nil</span>
    1.<span style="color:#9900CC;">upto</span><span style="color:#006600; font-weight:bold;">&#40;</span>attempts<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>a<span style="color:#006600; font-weight:bold;">|</span>
      result = <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">perform</span><span style="color:#006600; font-weight:bold;">&#40;</span>url<span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;">break</span> <span style="color:#9966CC; font-weight:bold;">unless</span> result.<span style="color:#0000FF; font-weight:bold;">nil</span>?
    <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#0000FF; font-weight:bold;">return</span> result
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>And sample usage:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> TestRequest
  <span style="color:#9966CC; font-weight:bold;">include</span> ApiRequest
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> foo
     body = <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">fetch</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'http://google.com'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>If module variable &#8220;<em>@@interfaces</em>&#8221; is array of ip addresses or network interfaces then one of them (randomly selected) will be used to perform request. Also, function &#8220;<em>fetch</em>&#8221; has parameter &#8220;<em>attempts</em>&#8221; which set to 3 by default. It means that operation will be invoked n times until result is downloaded from url. Otherwise &#8211; it returns nil.<br />
Function perform has a parameter &#8220;<em>assign_to</em>&#8221; (which it not used in &#8220;<em>fetch</em>&#8221; function) that allows to bind request to specified interface.  It is useful if you have situation when you might use different workers that bound to exact interface or just one that uses random ip`s. Also, class <em>ApiRequest</em> has a list of user agents which it uses randomly for each performed request.</p>
<p>Pastie: <a href="http://pastie.org/private/j19j3hbebte9bjqaydslmg">http://pastie.org/private/j19j3hbebte9bjqaydslmg</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sosedoff.com/2010/06/13/handy-http-requests-with-curb-and-ruby/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Making HTTP requests from different network interfaces with Ruby and Curb</title>
		<link>http://blog.sosedoff.com/2010/06/09/making-http-requests-from-different-network-interfaces-with-ruby-and-curb/</link>
		<comments>http://blog.sosedoff.com/2010/06/09/making-http-requests-from-different-network-interfaces-with-ruby-and-curb/#comments</comments>
		<pubDate>Thu, 10 Jun 2010 04:31:17 +0000</pubDate>
		<dc:creator>Dan Sosedoff</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Web Services]]></category>
		<category><![CDATA[curb]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[get]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[net]]></category>
		<category><![CDATA[requests]]></category>

		<guid isPermaLink="false">http://blog.sosedoff.com/?p=228</guid>
		<description><![CDATA[At some point you will find that you have reached requests per IP limit while using some API or crawling resources. And if you`re doing it via standard Net::HTTP you`ll face the problem that you cannot assign request class to specified network interface (or IP). Bummer? No. Even if you cant do it with core [...]]]></description>
			<content:encoded><![CDATA[<p>At some point you will find that you have reached requests per IP limit while using some API or crawling resources. And if you`re doing it via standard <a href="http://ruby-doc.org/core/classes/Net/HTTP.html">Net::HTTP</a> you`ll face the problem that you cannot assign request class to specified network interface (or IP). Bummer? No. Even if you cant do it with core class you might take a look on <a href="http://curb.rubyforge.org/">Curb</a> &#8211; libcurl ruby binding. It has everything that you need to make regular get/post/etc requests. And of course &#8211; easy.</p>
<p>A simple example (real ip`s are changed):</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rubygems'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'curb'</span>
&nbsp;
ip_addresses = <span style="color:#006600; font-weight:bold;">&#91;</span>
  <span style="color:#996600;">'1.1.1.1'</span>,
  <span style="color:#996600;">'2.2.2.2'</span>,
  <span style="color:#996600;">'3.3.3.3'</span>,
  <span style="color:#996600;">'4.4.4.4'</span>,
  <span style="color:#996600;">'5.5.5.5'</span>
<span style="color:#006600; font-weight:bold;">&#93;</span>
&nbsp;
ip_addresses.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>ip<span style="color:#006600; font-weight:bold;">|</span>
  req = <span style="color:#6666ff; font-weight:bold;">Curl::Easy</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'http://www.ip-adress.com/'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  req.<span style="color:#9900CC;">interface</span> = ip
  req.<span style="color:#9900CC;">perform</span>
  result_ip = req.<span style="color:#9900CC;">body_str</span>.<span style="color:#9900CC;">scan</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/&lt;</span>h2<span style="color:#006600; font-weight:bold;">&gt;</span>My IP address is: <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#91;</span>\d\.<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006666;">1</span>,<span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&lt;</span>\<span style="color:#006600; font-weight:bold;">/</span>h2<span style="color:#006600; font-weight:bold;">&gt;/</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">first</span>
  <span style="color:#CC0066; font-weight:bold;">puts</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;for #{ip} got response: #{result_ip}&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Output (ip`s are changed):</p>
<pre>
for 1.1.1.1 got response: 1.1.1.1
for 2.2.2.2 got response: 2.2.2.2
for 3.3.3.3 got response: 3.3.3.3
for 4.4.4.4 got response: 4.4.4.4
for 5.5.5.5 got response: 5.5.5.5
</pre>
<p>At least its working. Havent done any performance tests.<br />
Sample on pastie: <a href="http://pastie.org/private/afxlcuk1npwjov3wer5hw">http://pastie.org/private/afxlcuk1npwjov3wer5hw</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sosedoff.com/2010/06/09/making-http-requests-from-different-network-interfaces-with-ruby-and-curb/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Making colorized console output with Ruby</title>
		<link>http://blog.sosedoff.com/2010/06/01/making-colorized-console-output-with-ruby/</link>
		<comments>http://blog.sosedoff.com/2010/06/01/making-colorized-console-output-with-ruby/#comments</comments>
		<pubDate>Wed, 02 Jun 2010 03:23:04 +0000</pubDate>
		<dc:creator>Dan Sosedoff</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[ANSI]]></category>
		<category><![CDATA[colors]]></category>
		<category><![CDATA[console]]></category>
		<category><![CDATA[terminal]]></category>

		<guid isPermaLink="false">http://blog.sosedoff.com/?p=214</guid>
		<description><![CDATA[If you develop some console application you might want your output be more informative, have different colors for operations or logging purposes. It is possible to do with general ANSI escape codes, which are supported by most common console terminals.
The ASCII escape structure is pretty simple. It begins with &#8220;ESC&#8221; symbol, which is code 27 [...]]]></description>
			<content:encoded><![CDATA[<p>If you develop some console application you might want your output be more informative, have different colors for operations or logging purposes. It is possible to do with general <a href="http://en.wikipedia.org/wiki/ANSI_escape_code">ANSI escape code</a>s, which are supported by most common console terminals.</p>
<p>The ASCII escape structure is pretty simple. It begins with &#8220;<strong>ESC&#8221;</strong> symbol, which is code 27 in ASCII table. Then <strong>&#8220;[&#8221; </strong>symbol. Parameters that goes after &#8220;<strong>[</strong>&#8221; symbol are separated by &#8220;<strong>;</strong>&#8221; and finally ends with closing sequence: &#8220;<strong>ESC[0m</strong>&#8220;.</p>
<p>You can extend basic ruby String class with following code:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#CC0066; font-weight:bold;">String</span>
    <span style="color:#008000; font-style:italic;"># colorize functions</span>
    <span style="color:#9966CC; font-weight:bold;">def</span> red; colorize<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">self</span>, <span style="color:#996600;">&quot;<span style="color:#000099;">\e</span>[1m<span style="color:#000099;">\e</span>[31m&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>; <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">def</span> green; colorize<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">self</span>, <span style="color:#996600;">&quot;<span style="color:#000099;">\e</span>[1m<span style="color:#000099;">\e</span>[32m&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>; <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">def</span> dark_green; colorize<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">self</span>, <span style="color:#996600;">&quot;<span style="color:#000099;">\e</span>[32m&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>; <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">def</span> yellow; colorize<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">self</span>, <span style="color:#996600;">&quot;<span style="color:#000099;">\e</span>[1m<span style="color:#000099;">\e</span>[33m&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>; <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">def</span> blue; colorize<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">self</span>, <span style="color:#996600;">&quot;<span style="color:#000099;">\e</span>[1m<span style="color:#000099;">\e</span>[34m&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>; <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">def</span> dark_blue; colorize<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">self</span>, <span style="color:#996600;">&quot;<span style="color:#000099;">\e</span>[34m&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>; <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">def</span> pur; colorize<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">self</span>, <span style="color:#996600;">&quot;<span style="color:#000099;">\e</span>[1m<span style="color:#000099;">\e</span>[35m&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>; <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">def</span> colorize<span style="color:#006600; font-weight:bold;">&#40;</span>text, color_code<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#996600;">&quot;#{color_code}#{text}<span style="color:#000099;">\e</span>[0m&quot;</span> ; <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>And sample usage code:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Starting some job...&quot;</span>.<span style="color:#9900CC;">blue</span>
<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Processing thing 1 [#{&quot;</span>OK<span style="color:#996600;">&quot;.green}]&quot;</span>
<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Processing thing 2 [#{&quot;</span><span style="color:#CC0066; font-weight:bold;">FAIL</span><span style="color:#996600;">&quot;.red}]&quot;</span>
<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Oooops! This is a warning!&quot;</span>.<span style="color:#9900CC;">yellow</span>
<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Another color!&quot;</span>.<span style="color:#9900CC;">pur</span></pre></div></div>

<p>The output:</p>
<p><a href="http://blog.sosedoff.com/wp-content/uploads/2010/06/Screenshot.png"><img class="alignnone size-full wp-image-215" title="colored console" src="http://blog.sosedoff.com/wp-content/uploads/2010/06/Screenshot.png" alt="colored console" width="267" height="76" /></a></p>
<p>Nice and useful.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sosedoff.com/2010/06/01/making-colorized-console-output-with-ruby/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to test mailers in Sinatra, Rails and Merb</title>
		<link>http://blog.sosedoff.com/2010/05/03/how-to-test-mailers-in-sinatra-rails-and-merb/</link>
		<comments>http://blog.sosedoff.com/2010/05/03/how-to-test-mailers-in-sinatra-rails-and-merb/#comments</comments>
		<pubDate>Tue, 04 May 2010 04:06:12 +0000</pubDate>
		<dc:creator>Dan Sosedoff</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[mailer]]></category>
		<category><![CDATA[merb]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[sinatra]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://blog.sosedoff.com/?p=203</guid>
		<description><![CDATA[Once you need to test mailers within your Sinara, Rails or Merb application you wish to see a real output. No need to setup delivery via SMTP. Just create an executable ruby script somewhere, for example: /usr/bin/fake-sendmail.sh with following content:

$ touch /usr/bin/fake-sendmail.sh 
$ chmod +x /usr/bin/fake-sendmail.sh  # make it executable (will require root priv.)


#!/usr/bin/ruby
path [...]]]></description>
			<content:encoded><![CDATA[<p>Once you need to test mailers within your Sinara, Rails or Merb application you wish to see a real output. No need to setup delivery via SMTP. Just create an executable ruby script somewhere, for example: /usr/bin/fake-sendmail.sh with following content:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">touch</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>fake-sendmail.sh 
$ <span style="color: #c20cb9; font-weight: bold;">chmod</span> +x <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>fake-sendmail.sh  <span style="color: #666666; font-style: italic;"># make it executable (will require root priv.)</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;">#!/usr/bin/ruby</span>
path = <span style="color:#996600;">&quot;/tmp/fake-mailer&quot;</span>
<span style="color:#CC00FF; font-weight:bold;">Dir</span>.<span style="color:#9900CC;">mkdir</span><span style="color:#006600; font-weight:bold;">&#40;</span>path<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">if</span> !<span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">exists</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>path<span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;#{path}/#{Time.now.to_i}.txt&quot;</span>, <span style="color:#996600;">&quot;w&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>f<span style="color:#006600; font-weight:bold;">|</span>
    f.<span style="color:#CC0066; font-weight:bold;">puts</span> ARGV.<span style="color:#9900CC;">inspect</span>
    <span style="color:#ff6633; font-weight:bold;">$stdin</span>.<span style="color:#9900CC;">each_line</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>line<span style="color:#006600; font-weight:bold;">|</span> f.<span style="color:#CC0066; font-weight:bold;">puts</span> line <span style="color:#006600; font-weight:bold;">&#125;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>And then configure your mailing system:</p>
<h3>1. Sinatra</h3>
<p>There is a plugin for Sinatra (ported from Merb, <a href="http://github.com/foca/sinatra-mailer">http://github.com/foca/sinatra-mailer</a>),</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#6666ff; font-weight:bold;">Sinatra::Mailer</span>.<span style="color:#9900CC;">config</span> = <span style="color:#006600; font-weight:bold;">&#123;</span>:sendmail_path <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;/usr/bin/fake-sendmail.sh&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span>
<span style="color:#6666ff; font-weight:bold;">Sinatra::Mailer</span>.<span style="color:#9900CC;">delivery_method</span> = <span style="color:#ff3333; font-weight:bold;">:sendmail</span></pre></div></div>

<h3>2. Merb</h3>
<p>Edit your development configuration file (config/environments/development.rb)</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#6666ff; font-weight:bold;">Merb::BootLoader</span>.<span style="color:#9900CC;">after_app_loads</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    <span style="color:#6666ff; font-weight:bold;">Merb::Mailer</span>.<span style="color:#9900CC;">delivery_method</span> = <span style="color:#ff3333; font-weight:bold;">:sendmail</span>
    <span style="color:#6666ff; font-weight:bold;">Merb::Mailer</span>.<span style="color:#9900CC;">config</span> = <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#ff3333; font-weight:bold;">:sendmail_path</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'/usr/bin/fake-sendmail.sh'</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<h3>3. Rails.</h3>
<p>Edit your development environment file with following options:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">config.<span style="color:#9900CC;">action_mailer</span>.<span style="color:#9900CC;">delivery_method</span> = <span style="color:#ff3333; font-weight:bold;">:sendmail</span> 
config.<span style="color:#9900CC;">action_mailer</span>.<span style="color:#9900CC;">sendmail_settings</span> = <span style="color:#006600; font-weight:bold;">&#123;</span>:location <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;/usr/bin/fake-sendmail.sh&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.sosedoff.com/2010/05/03/how-to-test-mailers-in-sinatra-rails-and-merb/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Jabber bot with Ruby</title>
		<link>http://blog.sosedoff.com/2009/05/20/jabber-bot-with-ruby/</link>
		<comments>http://blog.sosedoff.com/2009/05/20/jabber-bot-with-ruby/#comments</comments>
		<pubDate>Wed, 20 May 2009 22:20:39 +0000</pubDate>
		<dc:creator>Dan Sosedoff</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[bot]]></category>
		<category><![CDATA[jabber]]></category>
		<category><![CDATA[xmpp4r]]></category>
		<category><![CDATA[xmpp4r-simple]]></category>

		<guid isPermaLink="false">http://blog.sosedoff.com/?p=143</guid>
		<description><![CDATA[Ruby has very powerful tools to create random jabber bots with XMPP protocol. In this article i`ll show just a small sample with a few commands available. 
I got xmpp4r-simple library from Google Code page &#8211; http://code.google.com/p/xmpp4r-simple/. Its kinda old, not updated since 2006, but the sources are really easy to read and understand, and [...]]]></description>
			<content:encoded><![CDATA[<p>Ruby has very powerful tools to create random jabber bots with XMPP protocol. In this article i`ll show just a small sample with a few commands available. </p>
<p>I got xmpp4r-simple library from Google Code page &#8211; <a href="http://code.google.com/p/xmpp4r-simple/">http://code.google.com/p/xmpp4r-simple/</a>. Its kinda old, not updated since 2006, but the sources are really easy to read and understand, and probably modify. </p>
<p>First, we need to install dependencies (gems):</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">$ gem install xmpp4r
$ gem install xmpp4r<span style="color:#006600; font-weight:bold;">-</span>simple</pre></div></div>

<p>And now, the actual ruby code:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;">#!/usr/bin/ruby</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rubygems'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'xmpp4r'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'xmpp4r-simple'</span>
&nbsp;
<span style="color:#ff6633; font-weight:bold;">$jabber_login</span> = <span style="color:#996600;">&quot;YOUR_JABBER_ID_HERE&quot;</span> <span style="color:#008000; font-style:italic;"># test@jabber.org</span>
<span style="color:#ff6633; font-weight:bold;">$jabber_password</span> = <span style="color:#996600;">&quot;YOUR_PASSWORD_HERE&quot;</span> 
<span style="color:#ff6633; font-weight:bold;">$client</span> = <span style="color:#0000FF; font-weight:bold;">nil</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># create jabber connection</span>
<span style="color:#9966CC; font-weight:bold;">def</span> jabber_connect<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">begin</span>
    conn = <span style="color:#6666ff; font-weight:bold;">Jabber::Simple</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>$jabber_login,$jabber_password<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#0000FF; font-weight:bold;">return</span> conn
  <span style="color:#9966CC; font-weight:bold;">rescue</span>
    <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#0000FF; font-weight:bold;">nil</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># send message to jabber client</span>
<span style="color:#9966CC; font-weight:bold;">def</span> jabber_respond<span style="color:#006600; font-weight:bold;">&#40;</span>to, msg<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#ff6633; font-weight:bold;">$client</span>.<span style="color:#9900CC;">deliver</span><span style="color:#006600; font-weight:bold;">&#40;</span>to,msg,:chat<span style="color:#006600; font-weight:bold;">&#41;</span>	
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># get sender jabber id</span>
<span style="color:#9966CC; font-weight:bold;">def</span> jabber_get_jid<span style="color:#006600; font-weight:bold;">&#40;</span>str<span style="color:#006600; font-weight:bold;">&#41;</span>
  matches = str.<span style="color:#9900CC;">match</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#91;</span>a<span style="color:#006600; font-weight:bold;">-</span>z\d_.\<span style="color:#006600; font-weight:bold;">-</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006666;">1</span>,<span style="color:#006666;">32</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>@<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#91;</span>a<span style="color:#006600; font-weight:bold;">-</span>z\d.<span style="color:#006600; font-weight:bold;">-</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006666;">1</span>,<span style="color:#006666;">32</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>\<span style="color:#006600; font-weight:bold;">//</span>i<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#996600;">&quot;#{matches[1]}@#{matches[2]}&quot;</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># ------------------------------------------------------------------- #</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># send server time</span>
<span style="color:#9966CC; font-weight:bold;">def</span> app_time<span style="color:#006600; font-weight:bold;">&#40;</span>jid<span style="color:#006600; font-weight:bold;">&#41;</span>
  jabber_respond<span style="color:#006600; font-weight:bold;">&#40;</span>jid, <span style="color:#996600;">&quot;Server time is: #{Time.now}&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># send some 'help' :)</span>
<span style="color:#9966CC; font-weight:bold;">def</span> app_help<span style="color:#006600; font-weight:bold;">&#40;</span>jid<span style="color:#006600; font-weight:bold;">&#41;</span>
  jabber_respond<span style="color:#006600; font-weight:bold;">&#40;</span>jid, <span style="color:#996600;">&quot;Nobody can help you. You`re alone.&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># process received message</span>
<span style="color:#9966CC; font-weight:bold;">def</span> app_parse_msg<span style="color:#006600; font-weight:bold;">&#40;</span>jid, msg<span style="color:#006600; font-weight:bold;">&#41;</span>
  cmd = msg.<span style="color:#9900CC;">body</span>.<span style="color:#9900CC;">strip</span>
  <span style="color:#9966CC; font-weight:bold;">begin</span>
    <span style="color:#9966CC; font-weight:bold;">case</span> cmd
      <span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#006600; font-weight:bold;">/</span>^help$<span style="color:#006600; font-weight:bold;">/</span>i <span style="color:#9966CC; font-weight:bold;">then</span> app_help<span style="color:#006600; font-weight:bold;">&#40;</span>jid<span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#006600; font-weight:bold;">/</span>^time$<span style="color:#006600; font-weight:bold;">/</span>i <span style="color:#9966CC; font-weight:bold;">then</span> app_time<span style="color:#006600; font-weight:bold;">&#40;</span>jid<span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#006600; font-weight:bold;">/</span>^jid$<span style="color:#006600; font-weight:bold;">/</span>i <span style="color:#9966CC; font-weight:bold;">then</span> jabber_respond<span style="color:#006600; font-weight:bold;">&#40;</span>jid, <span style="color:#996600;">&quot;Your jabber id: #{jid}&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;">else</span>
        jabber_respond<span style="color:#006600; font-weight:bold;">&#40;</span>jid, <span style="color:#996600;">&quot;Unknown command. Try something different.&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">rescue</span> <span style="color:#CC00FF; font-weight:bold;">Exception</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> ex
    jabber_respond<span style="color:#006600; font-weight:bold;">&#40;</span>jid, <span style="color:#996600;">&quot;SYSTEM_ERROR: #{ex}&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># ------------------------------------------------------------------- #</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Connecting to jabber server...&quot;</span>
<span style="color:#ff6633; font-weight:bold;">$client</span> = jabber_connect<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#ff6633; font-weight:bold;">$client</span>
  <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Connected. Waiting for messages...&quot;</span>
  <span style="color:#CC0066; font-weight:bold;">loop</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    <span style="color:#ff6633; font-weight:bold;">$client</span>.<span style="color:#9900CC;">received_messages</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>message<span style="color:#006600; font-weight:bold;">|</span>
      jid = jabber_get_jid<span style="color:#006600; font-weight:bold;">&#40;</span>message.<span style="color:#9900CC;">from</span>.<span style="color:#9900CC;">to_s</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Received message from #{jid}: #{message.body}&quot;</span>
      app_parse_msg<span style="color:#006600; font-weight:bold;">&#40;</span>jid, message<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#CC0066; font-weight:bold;">sleep</span> <span style="color:#006666;">0.1</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">else</span>
  <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Cannot connect. Please try again later.&quot;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>I think, the comments in source code are enough to understand what this bot supposed to do. There are 3 commands available: &#8216;help&#8217;, &#8216;time&#8217;, &#8216;jid&#8217;</p>
<p>Download script here &#8211; <a href="http://files.sosedoff.com/204ab61c/">http://files.sosedoff.com/204ab61c/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sosedoff.com/2009/05/20/jabber-bot-with-ruby/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WebDAV client in ruby</title>
		<link>http://blog.sosedoff.com/2009/05/02/webdav-client-in-ruby/</link>
		<comments>http://blog.sosedoff.com/2009/05/02/webdav-client-in-ruby/#comments</comments>
		<pubDate>Sat, 02 May 2009 05:03:30 +0000</pubDate>
		<dc:creator>Dan Sosedoff</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Web Services]]></category>
		<category><![CDATA[client]]></category>
		<category><![CDATA[Nginx]]></category>
		<category><![CDATA[sockets]]></category>
		<category><![CDATA[webdav]]></category>

		<guid isPermaLink="false">http://blog.sosedoff.com/?p=125</guid>
		<description><![CDATA[Here is a simple example how to make native WebDAV client with Ruby sockets. No additional gems or extensions needed &#8211; just all basic classes.

class WebDAV
	attr_reader :host, :port, :protocol, :chunk_size
	@socket = nil
&#160;
	def initialize&#40;host,port=80,protocol='HTTP/1.1',chunk=8096&#41;
		@host = host.to_s
		@port = port.to_i
		@protocol = protocol
		@chunk_size = chunk.to_i
	end
&#160;
	def build_header&#40;method, path, content_length=nil&#41;
		header = &#34;#{method} #{path} #{@protocol} \r\n&#34;
		header += &#34;Content-Length: #{content_length}\r\n&#34; if !content_length.nil?
		header += [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a simple example how to make native WebDAV client with Ruby sockets. No additional gems or extensions needed &#8211; just all basic classes.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> WebDAV
	attr_reader <span style="color:#ff3333; font-weight:bold;">:host</span>, <span style="color:#ff3333; font-weight:bold;">:port</span>, <span style="color:#ff3333; font-weight:bold;">:protocol</span>, <span style="color:#ff3333; font-weight:bold;">:chunk_size</span>
	<span style="color:#0066ff; font-weight:bold;">@socket</span> = <span style="color:#0000FF; font-weight:bold;">nil</span>
&nbsp;
	<span style="color:#9966CC; font-weight:bold;">def</span> initialize<span style="color:#006600; font-weight:bold;">&#40;</span>host,port=<span style="color:#006666;">80</span>,protocol=<span style="color:#996600;">'HTTP/1.1'</span>,chunk=<span style="color:#006666;">8096</span><span style="color:#006600; font-weight:bold;">&#41;</span>
		<span style="color:#0066ff; font-weight:bold;">@host</span> = host.<span style="color:#9900CC;">to_s</span>
		<span style="color:#0066ff; font-weight:bold;">@port</span> = port.<span style="color:#9900CC;">to_i</span>
		<span style="color:#0066ff; font-weight:bold;">@protocol</span> = protocol
		<span style="color:#0066ff; font-weight:bold;">@chunk_size</span> = chunk.<span style="color:#9900CC;">to_i</span>
	<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
	<span style="color:#9966CC; font-weight:bold;">def</span> build_header<span style="color:#006600; font-weight:bold;">&#40;</span>method, path, content_length=<span style="color:#0000FF; font-weight:bold;">nil</span><span style="color:#006600; font-weight:bold;">&#41;</span>
		header = <span style="color:#996600;">&quot;#{method} #{path} #{@protocol} <span style="color:#000099;">\r</span><span style="color:#000099;">\n</span>&quot;</span>
		header <span style="color:#006600; font-weight:bold;">+</span>= <span style="color:#996600;">&quot;Content-Length: #{content_length}<span style="color:#000099;">\r</span><span style="color:#000099;">\n</span>&quot;</span> <span style="color:#9966CC; font-weight:bold;">if</span> !content_length.<span style="color:#0000FF; font-weight:bold;">nil</span>?
		header <span style="color:#006600; font-weight:bold;">+</span>= <span style="color:#996600;">&quot;Host: #{@host}<span style="color:#000099;">\r</span><span style="color:#000099;">\n</span>&quot;</span>
		header <span style="color:#006600; font-weight:bold;">+</span>= <span style="color:#996600;">&quot;Connection: close<span style="color:#000099;">\r</span><span style="color:#000099;">\n</span><span style="color:#000099;">\r</span><span style="color:#000099;">\n</span>&quot;</span>
		<span style="color:#0000FF; font-weight:bold;">return</span> header
	<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
	<span style="color:#9966CC; font-weight:bold;">def</span> request<span style="color:#006600; font-weight:bold;">&#40;</span>method, path<span style="color:#006600; font-weight:bold;">&#41;</span>
		<span style="color:#CC0066; font-weight:bold;">open</span>
		header = build_header<span style="color:#006600; font-weight:bold;">&#40;</span>method, path<span style="color:#006600; font-weight:bold;">&#41;</span>
		<span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#0066ff; font-weight:bold;">@socket</span>.<span style="color:#9900CC;">write</span><span style="color:#006600; font-weight:bold;">&#40;</span>header<span style="color:#006600; font-weight:bold;">&#41;</span> == header.<span style="color:#9900CC;">length</span> <span style="color:#9966CC; font-weight:bold;">then</span>
			<span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#0066ff; font-weight:bold;">@socket</span>.<span style="color:#CC0066; font-weight:bold;">gets</span>.<span style="color:#CC0066; font-weight:bold;">split</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span>
		<span style="color:#9966CC; font-weight:bold;">end</span>
	<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
	<span style="color:#9966CC; font-weight:bold;">def</span> delete<span style="color:#006600; font-weight:bold;">&#40;</span>path<span style="color:#006600; font-weight:bold;">&#41;</span>
		request<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'DELETE'</span>, path<span style="color:#006600; font-weight:bold;">&#41;</span>
	<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
	<span style="color:#9966CC; font-weight:bold;">def</span> head<span style="color:#006600; font-weight:bold;">&#40;</span>path<span style="color:#006600; font-weight:bold;">&#41;</span>
		request<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'HEAD'</span>, path<span style="color:#006600; font-weight:bold;">&#41;</span>
	<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
	<span style="color:#9966CC; font-weight:bold;">def</span> mkcol<span style="color:#006600; font-weight:bold;">&#40;</span>path<span style="color:#006600; font-weight:bold;">&#41;</span>
		request<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'MKCOL'</span>, path<span style="color:#006600; font-weight:bold;">&#41;</span>
	<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
	<span style="color:#9966CC; font-weight:bold;">def</span> put<span style="color:#006600; font-weight:bold;">&#40;</span>path, localfile, auto_head=<span style="color:#0000FF; font-weight:bold;">true</span><span style="color:#006600; font-weight:bold;">&#41;</span>
		<span style="color:#9966CC; font-weight:bold;">if</span> !<span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">exists</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>localfile<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">||</span> !<span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">readable</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>localfile<span style="color:#006600; font-weight:bold;">&#41;</span>
			<span style="color:#CC0066; font-weight:bold;">raise</span> <span style="color:#996600;">&quot;File not exists or not accessible for reading!&quot;</span>
		<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
		<span style="color:#CC0066; font-weight:bold;">open</span>
&nbsp;
		datalen = <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">size</span><span style="color:#006600; font-weight:bold;">&#40;</span>localfile<span style="color:#006600; font-weight:bold;">&#41;</span>
		header = build_header<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'PUT'</span>, path, datalen<span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
		<span style="color:#9966CC; font-weight:bold;">begin</span>
			<span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#0066ff; font-weight:bold;">@socket</span>.<span style="color:#9900CC;">write</span><span style="color:#006600; font-weight:bold;">&#40;</span>header<span style="color:#006600; font-weight:bold;">&#41;</span> == header.<span style="color:#9900CC;">length</span> <span style="color:#9966CC; font-weight:bold;">then</span>
				written = <span style="color:#006666;">0</span>
				<span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span>localfile,<span style="color:#996600;">'r'</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>f<span style="color:#006600; font-weight:bold;">|</span> 
					<span style="color:#9966CC; font-weight:bold;">until</span> f.<span style="color:#9900CC;">eof</span>? <span style="color:#9966CC; font-weight:bold;">do</span>
						written <span style="color:#006600; font-weight:bold;">+</span>= <span style="color:#0066ff; font-weight:bold;">@socket</span>.<span style="color:#9900CC;">write</span><span style="color:#006600; font-weight:bold;">&#40;</span>f.<span style="color:#9900CC;">read</span><span style="color:#006600; font-weight:bold;">&#40;</span>@chunk_size<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
					<span style="color:#9966CC; font-weight:bold;">end</span>
				<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
				<span style="color:#9966CC; font-weight:bold;">if</span> written == datalen
					close
					<span style="color:#9966CC; font-weight:bold;">if</span> !auto_head
						<span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#0000FF; font-weight:bold;">true</span>
					<span style="color:#9966CC; font-weight:bold;">else</span>
						<span style="color:#0000FF; font-weight:bold;">return</span> head<span style="color:#006600; font-weight:bold;">&#40;</span>path<span style="color:#006600; font-weight:bold;">&#41;</span>
					<span style="color:#9966CC; font-weight:bold;">end</span>
				<span style="color:#9966CC; font-weight:bold;">end</span>
			<span style="color:#9966CC; font-weight:bold;">end</span>
		<span style="color:#9966CC; font-weight:bold;">rescue</span> <span style="color:#CC00FF; font-weight:bold;">Exception</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> e
			<span style="color:#CC0066; font-weight:bold;">puts</span> e
			<span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#0000FF; font-weight:bold;">false</span>
		<span style="color:#9966CC; font-weight:bold;">end</span>
	<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
	<span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#CC0066; font-weight:bold;">open</span>
		<span style="color:#9966CC; font-weight:bold;">begin</span> 
			<span style="color:#0066ff; font-weight:bold;">@socket</span> = TCPSocket.<span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span>@host,@port<span style="color:#006600; font-weight:bold;">&#41;</span>
			<span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#0000FF; font-weight:bold;">true</span>
		<span style="color:#9966CC; font-weight:bold;">rescue</span> <span style="color:#CC00FF; font-weight:bold;">Exception</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> e
			<span style="color:#CC0066; font-weight:bold;">puts</span> e
			<span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#0000FF; font-weight:bold;">false</span>
		<span style="color:#9966CC; font-weight:bold;">end</span>
	<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
	<span style="color:#9966CC; font-weight:bold;">def</span> close
		<span style="color:#9966CC; font-weight:bold;">begin</span>
			<span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#0066ff; font-weight:bold;">@socket</span>.<span style="color:#9900CC;">close</span>
		<span style="color:#9966CC; font-weight:bold;">rescue</span> 
			<span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#0000FF; font-weight:bold;">false</span>
		<span style="color:#9966CC; font-weight:bold;">end</span>
	<span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>This class supports only basic http/dav methods (PUT, DELETE, MKCOL, HEAD) and can be extended very easily and designed to work with all files, reading them by small chunks (default is 8096 bytes).<br />
Im using this class sometimes with nginx.  </p>
<p>Deps:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'socket'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'digest'</span></pre></div></div>

<p>Usage:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># create connection</span>
conn = WebDAV.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'your.host.com'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># upload file (without autocheck), return true/false value</span>
result = conn.<span style="color:#9900CC;">put</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'/test.mp3'</span>,<span style="color:#996600;">'/home/.../..../..../file.mp3'</span>, <span style="color:#0000FF; font-weight:bold;">false</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># upload file with autocheck, returns http response code (201, 404, ... ) so you`ll know what exactly happened</span>
result = conn.<span style="color:#9900CC;">put</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'/test2.mp3'</span>,<span style="color:#996600;">'/home/.../file.mp3'</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>Also, here is a wrapper class to produce MD5, SHA1 file hashes that supports big files.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> FileHash 
	<span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">md5</span><span style="color:#006600; font-weight:bold;">&#40;</span>path<span style="color:#006600; font-weight:bold;">&#41;</span>
		d = <span style="color:#6666ff; font-weight:bold;">Digest::MD5</span>.<span style="color:#9900CC;">new</span>
		<span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span>path,<span style="color:#996600;">'r'</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>f<span style="color:#006600; font-weight:bold;">|</span> 
			d.<span style="color:#9900CC;">update</span><span style="color:#006600; font-weight:bold;">&#40;</span>f.<span style="color:#9900CC;">read</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">8192</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">until</span> f.<span style="color:#9900CC;">eof</span>?
		<span style="color:#9966CC; font-weight:bold;">end</span>
		<span style="color:#0000FF; font-weight:bold;">return</span> d.<span style="color:#9900CC;">hexdigest</span>
	<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
	<span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">sha1</span><span style="color:#006600; font-weight:bold;">&#40;</span>path<span style="color:#006600; font-weight:bold;">&#41;</span>
		d = <span style="color:#6666ff; font-weight:bold;">Digest::SHA1</span>.<span style="color:#9900CC;">new</span>
		<span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span>path,<span style="color:#996600;">'r'</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>f<span style="color:#006600; font-weight:bold;">|</span> 
			d.<span style="color:#9900CC;">update</span><span style="color:#006600; font-weight:bold;">&#40;</span>f.<span style="color:#9900CC;">read</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">8192</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">until</span> f.<span style="color:#9900CC;">eof</span>?
		<span style="color:#9966CC; font-weight:bold;">end</span>
		<span style="color:#0000FF; font-weight:bold;">return</span> d.<span style="color:#9900CC;">hexdigest</span>
	<span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Usage:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">FileHash.<span style="color:#9900CC;">md5</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'/path/to/file'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
FileHash.<span style="color:#9900CC;">sha1</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'/path/to/file'</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>This webdav class not pretending to be stable in production environment, but can be useful for some &#8220;one-time&#8221; tasks with less code. </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sosedoff.com/2009/05/02/webdav-client-in-ruby/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>inet_ntoa and inet_aton in Ruby</title>
		<link>http://blog.sosedoff.com/2009/04/16/inet_ntoa-and-inet_aton-in-ruby/</link>
		<comments>http://blog.sosedoff.com/2009/04/16/inet_ntoa-and-inet_aton-in-ruby/#comments</comments>
		<pubDate>Thu, 16 Apr 2009 07:22:15 +0000</pubDate>
		<dc:creator>Dan Sosedoff</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[inet_aton]]></category>
		<category><![CDATA[inet_ntoa]]></category>

		<guid isPermaLink="false">http://blog.sosedoff.com/?p=134</guid>
		<description><![CDATA[Here is two small functions to convert IP addresses from string representation to integer and vice versa.

def inet_aton&#40;ip&#41;
    ip.split&#40;/\./&#41;.map&#123;&#124;c&#124; c.to_i&#125;.pack&#40;&#34;C*&#34;&#41;.unpack&#40;&#34;N&#34;&#41;.first
end
&#160;
def inet_ntoa&#40;n&#41;
    &#91;n&#93;.pack&#40;&#34;N&#34;&#41;.unpack&#40;&#34;C*&#34;&#41;.join &#34;.&#34;
end

]]></description>
			<content:encoded><![CDATA[<p>Here is two small functions to convert IP addresses from string representation to integer and vice versa.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">def</span> inet_aton<span style="color:#006600; font-weight:bold;">&#40;</span>ip<span style="color:#006600; font-weight:bold;">&#41;</span>
    ip.<span style="color:#CC0066; font-weight:bold;">split</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span>\.<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">map</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>c<span style="color:#006600; font-weight:bold;">|</span> c.<span style="color:#9900CC;">to_i</span><span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">pack</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;C*&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">unpack</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;N&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">first</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">def</span> inet_ntoa<span style="color:#006600; font-weight:bold;">&#40;</span>n<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#006600; font-weight:bold;">&#91;</span>n<span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">pack</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;N&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">unpack</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;C*&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">join</span> <span style="color:#996600;">&quot;.&quot;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.sosedoff.com/2009/04/16/inet_ntoa-and-inet_aton-in-ruby/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
