<?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"
	>

<channel>
	<title>Vanderbrew &#187; Ruby</title>
	<atom:link href="http://vanderbrew.com/blog/category/code/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://vanderbrew.com/blog</link>
	<description>Beer, Food, Code, Writing, Creativity, Life</description>
	<pubDate>Thu, 16 Oct 2008 07:10:46 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5</generator>
	<language>en</language>
			<item>
		<title>Marking Duplicate Web Archive Items in Yojimbo</title>
		<link>http://vanderbrew.com/blog/2008/02/02/marking-duplicate-web-archive-items-in-yojimbo/</link>
		<comments>http://vanderbrew.com/blog/2008/02/02/marking-duplicate-web-archive-items-in-yojimbo/#comments</comments>
		<pubDate>Sat, 02 Feb 2008 22:15:50 +0000</pubDate>
		<dc:creator>matt</dc:creator>
		
		<category><![CDATA[Code]]></category>

		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://vanderbrew.com/blog/2008/02/02/marking-duplicate-web-archive-items-in-yojimbo/</guid>
		<description><![CDATA[I saw Archive Flagged Items from NetNewsWire into Yojimbo (via) and found it a really neat tool. I've started using it to keep a more permanent record of interesting new articles.
I have lots of news articles flagged and I've had the import crash on me before for various reasons which has resulted in some duplicate [...]]]></description>
			<content:encoded><![CDATA[<p>I saw <a href="http://snippets.dzone.com/posts/show/5001">Archive Flagged Items from NetNewsWire into Yojimbo</a> (<a href="http://ranchero.com/?comments=1&#038;postid=1801">via</a>) and found it a really neat tool. I've started using it to keep a more permanent record of interesting new articles.</p>
<p>I have lots of news articles flagged and I've had the import crash on me before for various reasons which has resulted in some duplicate web archives being created. The reason for the duplicates is usually because there was a redirect to the actual article that Yojimbo followed, so the URL in NetNewsWire doesn't match the Yojimbo URL and checking for existing items on load doesn't work.</p>
<p>This was a great opportunity for me to explore <a href="http://rubyosa.rubyforge.org/" title="RubyOSA: Ruby/AppleEvent Bridge">RubyOSA</a> and continue learning <a href="http://www.ruby-lang.org/" title="Ruby Programming Language">Ruby</a> so I wrote a script to detect duplicate web archives based on name and mark them with a "Duplicate" label.</p>
<div class="igBar"><span id="lruby-2"><a href="#" onclick="javascript:showCodeTxt('ruby-2'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">RUBY:</span>
<div id="ruby-2">
<div class="ruby">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000; font-style:italic;">#!/usr/local/bin/ruby</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#CC0066; font-weight:bold;">require</span> 'rubygems'</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#CC0066; font-weight:bold;">require</span> 'rbosa'</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">yojimbo = OSA.<span style="color:#9900CC;">app</span><span style="color:#006600; font-weight:bold;">&#40;</span>'Yojimbo'<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">seen = Hash.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">false</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000; font-style:italic;"># Duplicate label details</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">duplicateLabelName = 'Duplicate'</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000; font-style:italic;"># An almost painful red</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">duplicateLabelColor = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;color:#800000;">65535</span>, <span style="color:#006666;color:#800000;">1536</span>, <span style="color:#006666;color:#800000;">4628</span><span style="color:#006600; font-weight:bold;">&#93;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">duplicateLabel = <span style="color:#0000FF; font-weight:bold;">nil</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000; font-style:italic;"># See if we already have a label named 'Duplicate' and save it</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">yojimbo.<span style="color:#9900CC;">labels</span>.<span style="color:#9900CC;">map</span>&nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span> |l| l.<span style="color:#9900CC;">name</span> == duplicateLabelName &amp;&amp; duplicateLabel = l <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000; font-style:italic;"># Make a label if we don't have it already</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>duplicateLabel.<span style="color:#0000FF; font-weight:bold;">nil</span>?<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; duplicateLabel = yojimbo.<span style="color:#9900CC;">make</span><span style="color:#006600; font-weight:bold;">&#40;</span>OSA::Yojimbo::Label,</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF; font-weight:bold;">nil</span>,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; :color =&gt; duplicateLabelColor,</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; :name =&gt; duplicateLabelName<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">end</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">yojimbo.<span style="color:#9900CC;">web_archive_items</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> |f|</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>seen.<span style="color:#9966CC; font-weight:bold;">include</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>f.<span style="color:#9900CC;">name</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">"Found a duplicate: #{f.name}"</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; f.<span style="color:#9900CC;">label</span>= duplicateLabel</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; seen<span style="color:#006600; font-weight:bold;">&#91;</span>f.<span style="color:#9900CC;">name</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">label</span>= duplicateLabel</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">else</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; seen<span style="color:#006600; font-weight:bold;">&#91;</span>f.<span style="color:#9900CC;">name</span><span style="color:#006600; font-weight:bold;">&#93;</span> = f</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">end</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
]]></content:encoded>
			<wfw:commentRss>http://vanderbrew.com/blog/2008/02/02/marking-duplicate-web-archive-items-in-yojimbo/feed/</wfw:commentRss>
		</item>
		<item>
		<title>My First Rails Plugin - JavaScriptFunction</title>
		<link>http://vanderbrew.com/blog/2006/07/15/my-first-rails-plugin-javascriptfunction/</link>
		<comments>http://vanderbrew.com/blog/2006/07/15/my-first-rails-plugin-javascriptfunction/#comments</comments>
		<pubDate>Sat, 15 Jul 2006 20:33:53 +0000</pubDate>
		<dc:creator>matt</dc:creator>
		
		<category><![CDATA[Code]]></category>

		<category><![CDATA[Internet]]></category>

		<category><![CDATA[Rails]]></category>

		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://vanderbrew.com/blog/2006/07/15/my-first-rails-plugin-javascriptfunction/</guid>
		<description><![CDATA[I'm working on a Rails app using RJS and Prototype Window Class. I needed to be able to return an anonymous JavaScript function in my RJS template but when passing it in a string to page.call it kept getting quoted and didn't work right (as you would expect).
I solved it by creating a JavaScriptFunction class [...]]]></description>
			<content:encoded><![CDATA[<p>I'm working on a Rails app using RJS and <a href="http://prototype-window.xilinus.com/">Prototype Window Class</a>. I needed to be able to return an anonymous JavaScript function in my RJS template but when passing it in a string to <code>page.call</code> it kept getting quoted and didn't work right (as you would expect).</p>
<p>I solved it by creating a JavaScriptFunction class and helpers so that it's easily usable in an RJS template. Browse the <a href="http://svn.vanderbrew.com/svn/repos/plugins/javascript_function/">plugin</a> or install it:</p>
<p><code>
<pre>
# With subversion
./script/plugin install -x http://svn.vanderbrew.com/svn/repos/plugins/javascript_function/

# Without subversion
./script/plugin install http://svn.vanderbrew.com/svn/repos/plugins/javascript_function/
</pre>
<p></code></p>
<p>To use it, just do:<br />
<code>
<pre>
page.call 'Dialog.confirm', "New Thing - do you want to add it?",
            { :windowParameters => { :width => 300 },
              :sokLabel => 'Yes',
              :cancelLabel => 'No',
              :buttonClass => 'myButtonClass',
              :id => 'myDialogId',
              :cancel => anonymous_javascript_function(:parameters => ["win"],
                         :body => "$('#{@element_id}').innerHTML = '#{escape_javascript @thing.name}'"),
              :sok => anonymous_javascript_function(:parameters => ["win"],
                         :body => "return true;")
            }
</pre>
<p></code></p>
<p>It's my first plugin so I'm open to any feedback you have about it. Please use the <a href="/blog/contact/">Contact form</a> to reach me.</p>
<p>Note - the keys <code>:sokLabel</code> and <code>:sok</code> shouldn't have an 's' in the front for real implementation with the JS library - I did that to prevent an emoticon from appearing thanks to WordPress.</p>
]]></content:encoded>
			<wfw:commentRss>http://vanderbrew.com/blog/2006/07/15/my-first-rails-plugin-javascriptfunction/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Testing Rails - Posting to another controller</title>
		<link>http://vanderbrew.com/blog/2005/12/31/testing-rails-posting-to-another-controller/</link>
		<comments>http://vanderbrew.com/blog/2005/12/31/testing-rails-posting-to-another-controller/#comments</comments>
		<pubDate>Sat, 31 Dec 2005 10:45:00 +0000</pubDate>
		<dc:creator>matt</dc:creator>
		
		<category><![CDATA[Code]]></category>

		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://vanderbrew.com/blog/?p=18</guid>
		<description><![CDATA[I've spent a fair chunk of time this morning trying to get my functional tests on my rails app working with the login component. Here's the result of my time, presented in the hopes that it will help someone else who's stuck on the same thing.
I'm using ModelSecurity for the user login component because I'd [...]]]></description>
			<content:encoded><![CDATA[<p>I've spent a fair chunk of time this morning trying to get my functional tests on my rails app working with the login component. Here's the result of my time, presented in the hopes that it will help someone else who's stuck on the same thing.</p>
<p>I'm using <a href="http://rubyforge.org/projects/model-security/">ModelSecurity</a> for the user login component because I'd also like to use the model security bits. Since I've got a before_filter to verify a user is logged in in my controller, I need to log in the user before I can test anything. Logging in the user is easy, right - I just post to the <em>login</em> action of the <em>user</em> controller. Here it is, wrapped in a function because I'll have to call it multiple times:</p>
<pre><code>
  def login_Neo
    post :login, :user=>{:login=>users(:neo).login, :password=>NEO_PASSWORD}
  end

  def test_list
    login_Neo
    get :list
    assert_response :success
    assert_template 'list'
    assert_not_nil assigns(:recipes)
  end
</code></pre>
<p>Ok, I'm sure that I've got a problem because my controller doesn't have a login action, but I decided to run it and see what happens.</p>
<pre><code>Expected response to be a <:success>, but was <302></code></pre>
<p>Yep, I'm being redirected to the user controller because of my before_filter.</p>
<p>Now, I know that I need to make it post to the user controller, not the recipedex controller. Much googling, reading and thinking later, I discover that the <em>post</em> method being used here is defined in ActionPack from Rails. And, once I dig up the source for that, I discovered that <em>post</em> simply uses the <em>@controller</em> instance variable.</p>
<p>Aha! One simple change and I'm on my way:</p>
<pre><code>
  def login_Neo
    controller_bak = @controller
    @controller = UserController.new
    post :login, :user=>{:login=>users(:neo).login, :password=>NEO_PASSWORD}
    @controller = controller_bak
  end
</code></pre>
<p>Now, it posts where I want it to, sets User.current as I expect and everything works!</p>
]]></content:encoded>
			<wfw:commentRss>http://vanderbrew.com/blog/2005/12/31/testing-rails-posting-to-another-controller/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
