<?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>Blog &#187; ruby</title>
	<atom:link href="http://blog.cliffano.com/tag/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.cliffano.com</link>
	<description>Geeking, Living, Travelling</description>
	<lastBuildDate>Thu, 26 Jan 2012 10:18:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Known Hosts Issue With Net::SSH</title>
		<link>http://blog.cliffano.com/2010/01/19/known-hosts-issue-with-netssh/</link>
		<comments>http://blog.cliffano.com/2010/01/19/known-hosts-issue-with-netssh/#comments</comments>
		<pubDate>Mon, 18 Jan 2010 13:25:48 +0000</pubDate>
		<dc:creator>Cliffano Subagio</dc:creator>
				<category><![CDATA[Work]]></category>
		<category><![CDATA[.ssh]]></category>
		<category><![CDATA[known_hosts]]></category>
		<category><![CDATA[net-ssh]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://blog.cliffano.com/?p=889</guid>
		<description><![CDATA[This issue bit me twice within a month, and each time I had to spend a couple of hours to figure out the cause of the problem, mostly due to the obscurity of the error messages. So I was using net-ssh-2.0.15 and jruby-openssl-0.5.1 for a piece of code that&#8217;s supposed to perform some remote operations. [...]]]></description>
			<content:encoded><![CDATA[<p>This issue bit me twice within a month, and each time I had to spend a couple of hours to figure out the cause of the problem, mostly due to the obscurity of the error messages.</p>
<p>So I was using <a href="http://net-ssh.rubyforge.org">net-ssh</a>-2.0.15 and <a href="http://github.com/jruby/jruby-openssl">jruby-openssl</a>-0.5.1 for a piece of code that&#8217;s supposed to perform some remote operations. The Net::SSH usage itself was straightforward&#8230;</p>
<pre class="brush: ruby; title: ; notranslate">
Net::SSH.start(@host, @username, :keys =&gt; @keys) do |ssh|
    ...
end
</pre>
<p>When I ran the above snippet on Windows XP, it gave this error message without any further information&#8230;</p>
<pre class="brush: plain; title: ; notranslate">
The system cannot find the path specified
</pre>
<p>Not exactly helpful, eh? And after some sleuthing around, it came down to <code>add(host, key)</code> method in lib/net/ssh/known_hosts.rb :</p>
<pre class="brush: ruby; title: ; notranslate">
def add(host, key)
  File.open(source, &quot;a&quot;) do |file|
    blob = [Net::SSH::Buffer.from(:key, key).to_s].pack(&quot;m*&quot;).gsub(/\s/, &quot;&quot;)
    file.puts &quot;#{host} #{key.ssh_type} #{blob}&quot;
  end
end
</pre>
<p>This method is trying to add an entry to the known_hosts file, which location is stored in <code>source</code> variable. In my case, the variable resolved to C:/.ssh/known_hosts . But the problem was that the .ssh directory didn&#8217;t exist. So I simply created it.</p>
<p>Lo and behold, when I ran this piece of code on a Solaris box weeks later, I hit another error message&#8230;</p>
<pre class="brush: plain; title: ; notranslate">
No such file or directory (IOError)
</pre>
<p>which turned out to be caused by the exact same thing, but this time the location is &lt;script_home&gt;/.ssh/known_hosts . The workaround was the same, I simply created the .ssh directory.</p>
<p>So there you go, hopefully it helps whoever else was confused by the unclear error messages.<br />
And in terms of a long term solution, it would be nice if <code>add(host, key)</code> checks or even creates the .ssh directory before attempting to write known_hosts file.</p>

<p class="FacebookLikeButton"><fb:like href="http%3A%2F%2Fblog.cliffano.com%2F2010%2F01%2F19%2Fknown-hosts-issue-with-netssh%2F" layout="standard" show_faces="false" width="450" action="like" colorscheme="light"></fb:like></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.cliffano.com/2010/01/19/known-hosts-issue-with-netssh/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Image Saving In Watir</title>
		<link>http://blog.cliffano.com/2008/12/30/image-saving-in-watir/</link>
		<comments>http://blog.cliffano.com/2008/12/30/image-saving-in-watir/#comments</comments>
		<pubDate>Mon, 29 Dec 2008 18:03:25 +0000</pubDate>
		<dc:creator>Cliffano Subagio</dc:creator>
				<category><![CDATA[Work]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[watir]]></category>

		<guid isPermaLink="false">http://blog.cliffano.com/?p=434</guid>
		<description><![CDATA[So I got the chance to use Watir again on a short project at work. The last time I used it was about 1.5 years ago, and I was glad to find out that Watir is still a nice library to use. Watir simply works without much hassle. The only issue I had was with [...]]]></description>
			<content:encoded><![CDATA[<p>So I got the chance to use <a href="http://wtr.rubyforge.org/">Watir</a> again on a short project at work. The last time I used it was about 1.5 years ago, and I was glad to find out that Watir is still a nice library to use. Watir simply works without much hassle.</p>
<p>The only issue I had was with <a href="http://wiki.openqa.org/display/WTR/Save+All+Images+on+a+Webpage">image saving</a>. From <a href="http://wtr.rubyforge.org/rdoc/classes/Watir/Image.html">Image class documentation</a> (Watir 1.6), it wasn&#8217;t obvious that save can only be called when image element is directly contained within a browser element.</p>
<p>I was trying to save the first image within a div,</p>
<pre class="brush: ruby; title: ; notranslate">
$browser.div(:id, 'foobar').images[1].save('d:\\temp')
</pre>
<p>which resulted in this error</p>
<pre class="brush: plain; title: ; notranslate">
NoMethodError: undefined method `goto' for #&lt;Watir::Div:0x3fa5d7c&gt;
d:/dev/ruby/lib/ruby/gems/1.8/gems/watir-1.6.2/lib/watir/image.rb:113:in `save'
</pre>
<p>Looking at the implementation of save in <a href="http://svn.openqa.org/fisheye/browse/watir/trunk/watir/lib/watir/image.rb?r=1662">image.rb</a>,</p>
<pre class="brush: ruby; title: ; notranslate">
def save(path)
  require 'watir/windowhelper'
  WindowHelper.check_autoit_installed
  @container.goto(src)
  begin
    thrd = fill_save_image_dialog(path)
    @container.document.execCommand(&quot;SaveAs&quot;)
    thrd.join(5)
  ensure
    @container.back
   end
end
</pre>
<p>it shows that save relies on the existence of goto and back methods within the container of the element, meaning that calling save method will tell the browser to go to the image src value, save it, and then click the back button. Hence image must be contained directly within a browser element.</p>
<p>I ended up having to use XPath because the image element doesn&#8217;t have any id or class that allows me to directly reference it from a browser element.</p>
<pre class="brush: ruby; title: ; notranslate">
$browser.image(:xpath, &quot;//div[@id='foobar']/img&quot;).save(&quot;d:\\temp&quot;)
</pre>
<p>It would be nicer if @container can be replaced by something like find_root_container or something that traverses the ancestor container elements and eventually finds a browser element.</p>
<p>Another nice improvement to the save method implementation would be instead of going to the image src and then clicking back, which could potentially lose the state of a page, it would be nicer to open a new window and close it afterward.</p>

<p class="FacebookLikeButton"><fb:like href="http%3A%2F%2Fblog.cliffano.com%2F2008%2F12%2F30%2Fimage-saving-in-watir%2F" layout="standard" show_faces="false" width="450" action="like" colorscheme="light"></fb:like></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.cliffano.com/2008/12/30/image-saving-in-watir/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

