<?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>Linden LAN &#187; Ruby on Rails</title>
	<atom:link href="http://www.lindenlan.net/tag/ruby-on-rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.lindenlan.net</link>
	<description></description>
	<lastBuildDate>Sat, 29 Nov 2014 04:54:20 +0000</lastBuildDate>
	<language>en-US</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	
	<item>
		<title>Make Rails Play Nice With FLVPlayback Skin</title>
		<link>http://www.lindenlan.net/2010/04/03/make-rails-play-nice-with-flvplayback-skin/</link>
		<comments>http://www.lindenlan.net/2010/04/03/make-rails-play-nice-with-flvplayback-skin/#comments</comments>
		<pubDate>Sat, 03 Apr 2010 08:11:02 +0000</pubDate>
		<dc:creator><![CDATA[Brian]]></dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.lindenlan.net/?p=372</guid>
		<description><![CDATA[Flash assets like an FLVPlayback skin will typically be located in your public folder. However, according to http://kb2.adobe.com/cps/608/608abffd.html, “in a loading scenario, the skin SWF for the FLVPlayback component must be relative to the loading HTML file containing the parent SWF on the server, not to the location of the loaded SWF.” This is bad, [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Flash assets like an FLVPlayback skin will typically be located in your public folder.  However, according to <a href="http://kb2.adobe.com/cps/608/608abffd.html">http://kb2.adobe.com/cps/608/608abffd.html</a>, “in a loading scenario, the skin SWF for the FLVPlayback component must be relative to the loading HTML file containing the parent SWF on the server, not to the location of the loaded SWF.”  This is bad, since when you load a page, the URL will typically be /:controller/:action,  which means the FLVPlayback skin URL will be /:controller/myskin.swf even if your parent SWF is in /public.  You can verify this in Firebug on the Net tab.  The problem will manifest itself with a loaded Flash movie with no controls.  You can fix this by creating a rewrite rule in your .htaccess file.</p>
<pre class="brush: bash">
RewriteRule ^.*/myskin.swf$ /pathto/myskin.swf
</pre>
<p>Any request ending in myskin.swf will be redirected to /pathto/myskin.swf under the public folder.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lindenlan.net/2010/04/03/make-rails-play-nice-with-flvplayback-skin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Gotcha!</title>
		<link>http://www.lindenlan.net/2009/03/02/gotcha/</link>
		<comments>http://www.lindenlan.net/2009/03/02/gotcha/#comments</comments>
		<pubDate>Mon, 02 Mar 2009 16:24:34 +0000</pubDate>
		<dc:creator><![CDATA[Brian]]></dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.lindenlan.net/?p=289</guid>
		<description><![CDATA[So I had to move an application that I’m developing from a MediaTemple (dv) Dedicated-Virtual to a Ruby on Rails GridContainer running on a MediaTemple (gs) Grid-Service. Most of the tutorials I found that covered installing a Rails app on a GridContainer were somewhat dated. Things that were different than expected include: Rails, a few [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>So I had to move an application that I’m developing from a <a href="http://mediatemple.net/webhosting/dv/">MediaTemple (dv) Dedicated-Virtual</a> to a <a href="http://mediatemple.net/webhosting/gs/features/containers.php#ror">Ruby on Rails GridContainer</a> running on a <a href="http://mediatemple.net/webhosting/gs/">MediaTemple (gs) Grid-Service</a>.   Most of the tutorials I found that covered installing a Rails app on a GridContainer were somewhat dated.  Things that were different than expected include:</p>
<ol>
<li>Rails, a few precompiled gems (like RMagick), and a test app are automatically installed for you.  Most of the tutorials walk you through installing Rails and the skeleton app from SSH.  That’s no longer necessary.</li>
<li>For Capistrano, you need to set the <code>syspath</code> option (“System” in the control panel) to <code>/home/[xxxxx]/containers/rails/[app_path]/current</code> where [xxxxx] is your GridContainer number and [app_path] is where you want your app located.   I kept the app path and app name the same.</li>
<li>You can’t edit application options from the web control panel.  You have to do this from a SSH session using <code>mtr set_option</code>.  You may need to do this to change the <code>syspath</code> or to set the <code>environment</code>.  For example, to set the environment to “staging” you use the following command: <code>mtr set_option [app_name] environment=staging</code>.</li>
<li>If you change the <code>syspath</code> make sure to update the symbolic link to the app’s public folder under your app’s domain, otherwise you’ll get an app not found error.  In other words, <code>~/domains/example.com/html</code> should point to <code>/home/[xxxxx]/containers/rails/[app_path]/current/public</code>.
<li>When an application fails to start, you get no feedback about the cause.  Check log/mongrel.log for details as to why your application fails to start.</li>
<li>After changing the <code>syspath</code>, the app may not restart.  You may get an <code>Address already in use - bind(2) (Errno::EADDRINUSE)</code>.  To resolve this, I ended up having to reboot the container.</li>
<li>For some reason, <code>rake gems:install</code> didn’t work.  I had to manually install each gem.</li>
</ol>
<p><br/></p>
<p>I definitely had a lot more control over the installation when I had the application running on the (dv)  using <a href="http://www.modrails.com/">Passenger Phusion</a>, especially having the ability to compile software.  However, the GridContainer runs a lot faster.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lindenlan.net/2009/03/02/gotcha/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RSpec, Autotest, and Ruby-Libnotify</title>
		<link>http://www.lindenlan.net/2008/03/03/rspec-autotest-and-ruby-libnotify/</link>
		<comments>http://www.lindenlan.net/2008/03/03/rspec-autotest-and-ruby-libnotify/#comments</comments>
		<pubDate>Tue, 04 Mar 2008 04:35:37 +0000</pubDate>
		<dc:creator><![CDATA[Brian]]></dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.lindenlan.net/2008/03/03/rspec-autotest-and-ruby-libnotify/</guid>
		<description><![CDATA[After many false starts, I decided that I really needed to wrap my head around unit testing when writing Rails applications. I more or less completed a Rails 1.2.3 application without any formal tests, and I would like to upgrade it to 2.0.2 and make it RESTful in the process. At the same time, I’ve [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>After many false starts, I decided that I really needed to wrap my head around unit testing when writing Rails applications.  I more or less completed a Rails 1.2.3 application without any formal tests, and I would like to upgrade it to 2.0.2 and make it RESTful in the process.  At the same time, I’ve moved from a Windows development environment to a *nix one after installing Xubuntu on my laptop (an old Compaq Presario).  I’ve also switched from Cream to Emacs.  Despite my Windows desktop being more than twice as fast as my laptop, I just could not stand not being in a true *nix environment.  Too much of the Windows idiosyncrasies got on my nerves.  And my switch from Cream to Emacs was because I just didn’t like the instability of the hacks required to make Vim less of a modal editor.  If I tire of Emacs, I may try pure Vim instead, but I remember <a href="http://www.lindenlan.net/2006/10/27/i-have-cream-but-could-use-more-sugar/">installing Cream</a> simply because I didn’t like pure Vim to start with.  So with these various changes going on with my Rails programming environment, I figured it was an ideal time to learn to formally test my applications.  Of course the first part is setting up the testing environment so that it is easy to use, stays out of your way, and is informative.</p>
<p><span id="more-52"></span></p>
<p>RSpec is the current black when it comes to testing.  Seeing how it’s adopted by <a href="http://merbivore.com/">merb</a> by default and I’m targetting merb for an old app I shelved because Rails just didn’t have the high performance yet to pull it off, I figured it would be the test method I should learn.  It also helps that RSpec is just more readable than Test::Unit.  Installation is more or less trivial and is covered succinctly in the <a href="http://rspec.info/documentation/rails/install.html">RSpec documentation</a>.  Just remember to install RSpec as a plugin and not as a gem.  Autotest will puke otherwise.  You can also use the <code>-x</code> option if you want to install it as an svn external.  (Another option would be <a href="http://piston.rubyforge.org/">piston</a> another gem I need to look at.)</p>
<pre class="brush: bash">
ruby script/plugin install http://rspec.rubyforge.org/svn/tags/CURRENT/rspec
ruby script/plugin install http://rspec.rubyforge.org/svn/tags/CURRENT/rspec_on_rails
</pre>
<p>Then you bootstrap the plugin which installs the generators and rake tasks.</p>
<pre class="brush: bash">
ruby script/generate rspec
ruby script/generate rspec_model foo
rake db:migrate
rake spec
</pre>
<p>If all goes well, rspec should run and you should get a result similar to this:</p>
<pre class="brush: bash">
.
Finished in 0.313 seconds
1 example, 0 failures
</pre>
<p>Now that RSpec is running properly, we want it to run automatically.  That’s where ZenTest comes in.  (The capitalization is intentional.)</p>
<pre class="brush: bash">
sudo gem install ZenTest
</pre>
<p>ZenTest contains autotest.  You start autotest from the root of your Rails application.</p>
<pre class="brush: bash">
autotest
</pre>
<p>Autotest will then sit there continually checking your app folders for any file changes.  When one is detected that requires RSpec to run, autotest will fire off the rake task to do so.  Go ahead and edit <code>./app/models/foo.rb</code> by adding a blank line and then save it.  When you return to the terminal window you should see that the test ran and you got the same result as before.</p>
<p>There is a prettier and more informative alternative than the results provided in the terminal.  RSpec can produce HTML output as well.  Create a folder <code>./doc/spec/</code> for the output folder.  Now open up <code>./spec/spec.opts</code> in your editor and add the following lines.</p>
<pre class="brush: bash">
--format 
html:doc/spec/report.html
</pre>
<p>This will cause an HTML report to be generated every time a test is run, in addition to the terminal output.  The HTML report not only tells you what tests failed and passed but also where the failures occurred.  The HTML format is much easier to navigate than the terminal output.</p>
<p>Mac OS X users have a notification program called <a href="http://growl.info/">Growl</a> that autotest hooks into.  On Windows there’s <a href="http://www.fullphat.net/">Snarl</a>.  For Linux, there’s libnotify.  libnotify is not a standalone application like Growl or Snarl, but a library around which an application, or in this case, an applet must be written.  There’s a handful of how-tos that walk you thru hooking autotest to libnotify, but the one I considered the best was this blog post, <a href="http://www.ikhono.net/2007/12/16/gnome-autotest-notifications">Gnome autotest Notifications</a>.  If you follow those instructions, you should get a working notifier, but I would recommend replacing his .autotest file with my <a href='http://www.lindenlan.net/wp-content/uploads/2008/03/autotest.txt' title='Autotest File'>.autotest file</a>:</p>
<pre class="brush: ruby">
require &#039;rnotify&#039;
require &#039;gtk2&#039;
require &#039;launchy&#039;

module Autotest::RNotify
  class Notification
    attr_accessor :verbose, :image_root, :tray_icon, :notification, 
                  :image_pass, :image_pending, :image_fail,
                  :image_file_pass, :image_file_pending, :image_file_fail,
                  :status_image_pass, :status_image_pending, :status_image_fail
    
    def initialize(timeout = 5000, 
                   image_root = &quot;#{ENV[&#039;HOME&#039;]}/.autotest_images&quot; , 
                   report_url = &quot;doc/spec/report.html&quot;,
                   verbose = false)
      self.verbose = verbose
      self.image_root = image_root
      self.image_file_pass = &quot;#{image_root}/pass.png&quot;
      self.image_file_pending = &quot;#{image_root}/pending.png&quot;
      self.image_file_fail = &quot;#{image_root}/fail.png&quot;

      raise(&quot;#{image_file_pass} not found&quot;) unless File.exists?(image_file_pass)
      raise(&quot;#{image_file_pending} not found&quot;) unless File.exists?(image_file_pending)
      raise(&quot;#{image_file_fail} not found&quot;) unless File.exists?(image_file_fail)
      
      puts &#039;Autotest Hook: loading Notify&#039; if verbose
      Notify.init(&#039;Autotest&#039;) || raise(&#039;Failed to initialize Notify&#039;)

      puts &#039;Autotest Hook: initializing tray icon&#039; if verbose
      self.tray_icon = Gtk::StatusIcon.new
      tray_icon.pixbuf = Gdk::Pixbuf.new(image_file_pending,22,22)
      tray_icon.tooltip = &#039;RSpec Autotest&#039;

      puts &#039;Autotest Hook: Creating Notifier&#039; if verbose
      self.notification = Notify::Notification.new(&#039;X&#039;, nil, nil, tray_icon)

      notification.timeout = timeout

      puts &#039;Autotest Hook: Connecting mouse click event&#039; if verbose
      tray_icon.signal_connect(&quot;activate&quot;) do
        Launchy::Browser.new.visit(report_url)
      end
      
      Thread.new { Gtk.main }
      sleep 1
      tray_icon.embedded? || raise(&#039;Failed to set up tray icon&#039;)
    end
    
    def notify(icon, tray, title, message)
      notification.update(title, message, nil)
      notification.pixbuf_icon = icon
      tray_icon.tooltip = &quot;Last Result: #{message}&quot;
      tray_icon.pixbuf = tray
      notification.show
    end
    
    def passed(title, message)
      self.image_pass ||= Gdk::Pixbuf.new(image_file_pass, 48, 48)
      self.status_image_pass ||= Gdk::Pixbuf.new(image_file_pass, 22, 22)
      notify(image_pass, status_image_pass, title, message)
    end
    
    def pending(title, message)
      self.image_pending ||= Gdk::Pixbuf.new(image_file_pending, 48, 48)
      self.status_image_pending ||= Gdk::Pixbuf.new(image_file_pending, 22, 22)
      notify(image_pending, status_image_pending, title, message)
    end
    
    def failed(title, message) 
      self.image_fail ||= Gdk::Pixbuf.new(image_file_fail, 48, 48)
      self.status_image_fail ||= Gdk::Pixbuf.new(image_file_fail, 22, 22)
      notify(image_fail, status_image_fail, title, message)
    end
    
    def quit
      puts &#039;Autotest Hook: Shutting Down...&#039; if verbose
      #Notify.uninit
      Gtk.main_quit
    end
  end

  Autotest.add_hook :initialize do |at|
    @notify = Notification.new
  end

  Autotest.add_hook :ran_command do |at|
    results = at.results.last

    unless results.nil?
      output = results[/(\d+)\s+examples?,\s*(\d+)\s+failures?(,\s*(\d+)\s+pending)?/]
      if output
        failures = $~[2].to_i
        pending = $~[4].to_i
      end
      
      if failures &gt; 0
        @notify.failed(&quot;Tests Failed&quot;, output)
      elsif pending &gt; 0
        @notify.pending(&quot;Tests Pending&quot;, output)
      else
        unless at.tainted
          @notify.passed(&quot;All Tests Passed&quot;, output)
        else
          @notify.passed(&quot;Tests Passed&quot;, output)
        end
      end
    end
  end

  Autotest.add_hook :quit do |at|
    @notify.quit
  end
end
</pre>
<p>The improvements I made are to (a) forego using themeable icons and stick strictly with the <a href="http://www.thelucid.com/articles/2007/07/30/autotest-growl-fail-pass-smilies">Autotest Growl Fail/Pass Smilies</a> (b) run a check to make sure the images exist otherwise raise an error, and © load the RSpec HTML report when you click the icon in the system tray.  In order for the onclick event to work, you need to install the launchy gem.</p>
<pre class="brush: bash">
sudo gem install launchy
</pre>
<p>After all that is up and running, you should have a fully functioning test environment that will automatically run (after starting autotest in a terminal) with a notification applet running in your system tray that you can click to load a well-formatted HTML report in your browser.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lindenlan.net/2008/03/03/rspec-autotest-and-ruby-libnotify/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Subversion + Rails In Less Than Five Minutes (on Windows)</title>
		<link>http://www.lindenlan.net/2007/06/17/subversion-rails-in-less-than-five-minutes-on-windows/</link>
		<comments>http://www.lindenlan.net/2007/06/17/subversion-rails-in-less-than-five-minutes-on-windows/#comments</comments>
		<pubDate>Mon, 18 Jun 2007 01:48:17 +0000</pubDate>
		<dc:creator><![CDATA[Brian]]></dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.lindenlan.net/2007/06/17/subversion-rails-in-less-than-five-minutes-on-windows/</guid>
		<description><![CDATA[Inspired by a couple of articles and even a screencast, I wrote a short batch file that creates a Rails application and automatically loads it into a subversion repository. It works by first creating a temp folder, generating the rails app there, renaming the app folder to trunk, creating the accompanying branches and tags folder, [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Inspired by a <a href="http://blog.mondragon.cc/articles/2006/11/05/subversion-rails-in-five-minutes">couple</a> of <a href="http://snippets.dzone.com/tag/configure_for_svn">articles</a> and even a <a href="http://railscasts.com/episodes/36">screencast</a>, I wrote a short batch file that creates a Rails application and automatically loads it into a subversion repository.  It works by first creating a temp folder, generating the rails app there, renaming the app folder to <a href="http://en.wikipedia.org/wiki/Trunk_%28software%29">trunk</a>, creating the accompanying <a href="http://en.wikipedia.org/wiki/Branching_%28software%29">branches</a> and <a href="http://en.wikipedia.org/wiki/Revision_tag">tags</a> folder, and then deleting/renaming a bunch of non-essential files.  Once that’s done it imports the three folders into a specified subversion repository.  Once the import is complete, the temp folder is deleted and then the trunk is checked out.  Finally it cleans-up by copying the database.yml file and ignoring the tmp and log folders.  That’s it.</p>
<p><span id="more-28"></span></p>
<pre class="brush: bash">
@echo off

if &quot;%1&quot;==&quot;&quot; goto :NOAPPNAME
if &quot;%2&quot;==&quot;&quot; goto :NOUSERNAME
if &quot;%3&quot;==&quot;&quot; goto :NOSVNREPO

mkdir svntemp
cd svntemp 
mkdir branches
mkdir tags
call rails %1
mv %1 trunk
cd trunk
mv config/database.yml config/database_example.yml
rm -r log/*
rm -r tmp/*
cd ..
call svn import --username %2 . %3 -m &quot;initial import&quot;
cd ..
rm -r svntemp
call svn co %3/trunk %1
cd %1
cp config/database_example.yml config/database.yml
call svn propset svn:ignore database.yml config/
call svn propset svn:ignore &quot;*&quot; log/
call svn propset svn:ignore &quot;*&quot; tmp/
svn commit -m &quot;ignoring files&quot;

goto :END

:NOAPPNAME
echo &quot;ERROR: No application name provided.&quot;
goto :END

:NOSVNREPO
echo &quot;ERROR: No subversion repository provided. svn://path/to/repo&quot;
goto :END

:NOUSERNAME
echo &quot;ERROR: No username provided.&quot;
goto :END

:END
</pre>
<p>It’s not bad for a first pass.  It’d be good to have a shell script that does the same thing and it shouldn’t be too hard to port.  If I were to rewrite it using Windows scripting, I’d be able to provide better error checking.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lindenlan.net/2007/06/17/subversion-rails-in-less-than-five-minutes-on-windows/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>I Have Cream But Could Use More Sugar</title>
		<link>http://www.lindenlan.net/2006/10/27/i-have-cream-but-could-use-more-sugar/</link>
		<comments>http://www.lindenlan.net/2006/10/27/i-have-cream-but-could-use-more-sugar/#comments</comments>
		<pubDate>Sat, 28 Oct 2006 02:17:40 +0000</pubDate>
		<dc:creator><![CDATA[Brian]]></dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Editor]]></category>
		<category><![CDATA[IDE]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.lindenlan.net/2006/10/28/i-have-cream-but-could-use-more-sugar/</guid>
		<description><![CDATA[I currently develop on a Windows machine. (You can cut the snickering.) Therefore, I don’t have the pleasure of using TextMate. I’m also avoiding IDEs as a matter of course when an editor and CLI often avoids the bloat and subsequently works faster. I first used Scite which shipped with InstantRails. I quickly moved over [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>I currently develop on a Windows machine.  (You can cut the snickering.)  Therefore, I don’t have the pleasure of using <a href="http://macromates.com/">TextMate</a>.  I’m also avoiding IDEs as a matter of course when an editor and CLI often avoids the bloat and subsequently works faster.   I first used Scite which shipped with <a href="http://instantrails.rubyforge.org/wiki/wiki.pl">InstantRails</a>.  I quickly moved over to <a href="http://www.jedit.org/">jEdit</a> when I switched to Rails on <a href="http://www.cygwin.com/">Cygwin</a>.  With the right set of plugins you can quickly and easily get a TextMate-like editor.  I decided to give <a href="http://www.vim.org/">Vim/GVim</a> a try when I saw it in action.  As much as I liked the raw power, things just didn’t make sense to me.  When you learn to use editors a certain way, it’s hard to break old habits.  Enter <a href="http://cream.sourceforge.net/">Cream</a>.   </p>
<p><span id="more-15"></span></p>
<p>Cream makes Vim act like your standard, modern editor by cleverly mapping the UI from what you expect to what Vim expects.  That said, you can also turn off Cream’s mapping temporarily or permanently and make it act more like Vim.  Should you desire to use straight Vim or GVim, you can do that as well.  Cream eases you into Vim better than GVim does.  In fact, GVim is more a middleman between you and Vim whereas Cream acts more like a translator.</p>
<p>Vim 7 has built-in stuff like folds and diff mode.  It ships with the <a href="http://vim-ruby.rubyforge.org/">vim-ruby scripts</a> which enables things like autocomplete and syntax highlighting for Ruby.  Cream adds tabbed documents (but I find them to be more cumbersome especially now that I can use Alt-W 1 thru 9).  Cream is nice because you can use your mouse for selection and do cut and paste via Ctrl-X and Ctrl-V which one would expect.  Then there’s the <a href="http://www.tpope.net/node/96">rails plugin</a> that exposes many handy commands that hook into the fact you can call system commands so you can generate a model or run a rake task from within Vim.</p>
<p>For all the stuff you get out of the box, Cream has some annoyances.  For example, choosing a color theme for your syntax highlighting is, for the most part, limited to the default ones provided by Cream.  You can hack the scripts to add your own or you can load one via a configuration file, but that overrides the ability to use the color preferences.  As for creating a custom color scheme, that is a programming task in and of itself.  I do see the value of Vim’s all-keyboard methodology (a consequence of Vi being written before the mouse was invented).  Once learned it’s very efficient.  Though one thing that annoys the heck out of me is the choice for navigation keys, primarily for left and right.  I can understand the point of maintaining the hand positions on the homebase keys, hence J being mapped to down, down being the most frequent navigation.  However, coming from an arrow keys, numpad, and WSAD history, the key mappings for K, L, and H just aren’t that intuitive to me.  It would’ve been nice for DF to be mapped to left-right and JK to down-up thereby giving each hand an axis to control, or maybe IJKL be mapped similar to WASD, but in either case, the one letter mnemonics for commands would be lost.  Granted the arrow keys do function, but that removes a hand from the homebase keys which isn’t all that efficient and if you’re doing that then a mouse would be just as good to navigate.  Yes, it’s possible to remap keys but then what happens when you move to another machine without your customizations?</p>
<p>Still despite it’s shortcomings, I think Cream will most likely replace jEdit as my editor of choice on Windows.  The shortcomings are more than likely artificial due to my lack of experience and practice.  There’s definitely a lot of features to go through and by far the worst annoyance is a lack of documentation showing proper workflow using Cream/Vim.  </p>
<p><strong>Update:</strong> I did find this <a href="http://youtube.com/watch?v=30P8DSNOZuU">Ruby on Rails, Vim, and rails.vim</a> which is a remix of the RoR <a href="http://www.rubyonrails.org/screencasts">Creating a weblog in 15 minutes screencast</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lindenlan.net/2006/10/27/i-have-cream-but-could-use-more-sugar/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>setLength extension for Control.Slider</title>
		<link>http://www.lindenlan.net/2006/10/20/setlength-extension-for-controlslider/</link>
		<comments>http://www.lindenlan.net/2006/10/20/setlength-extension-for-controlslider/#comments</comments>
		<pubDate>Sat, 21 Oct 2006 05:20:52 +0000</pubDate>
		<dc:creator><![CDATA[Brian]]></dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.lindenlan.net/2006/10/21/setlength-extension-for-controlslider/</guid>
		<description><![CDATA[The UI on a project of mine had to be resizable. The UI included a script.aculo.us slider which unfortunately did not have a resize method nor was it smart enough to update itself should the underlying element be resized. So I created the following extension: Object.extend(Control.Slider.prototype, { setLength: function(length) { // resize the element if [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>The UI on a project of mine had to be resizable.  The UI included a <a href="http://script.aculo.us/">script.aculo.us</a> <a href="http://wiki.script.aculo.us/scriptaculous/show/Slider">slider</a> which unfortunately did not have a resize method nor was it smart enough to update itself should the underlying element be resized. So I created the following extension:</p>
<p><span id="more-13"></span></p>
<pre class="brush: js">
Object.extend(Control.Slider.prototype, {
  setLength: function(length) {
    // resize the element
    if (this.isVertical()) {
      Element.setStyle(this.track, {height: length + &quot;px&quot;});
    } else {
      Element.setStyle(this.track, {width: length + &quot;px&quot;});
    }
    
    // update lengths
    this.trackLength = this.maximumOffset() - this.minimumOffset();

    this.handleLength = this.isVertical() ? 
      (this.handles[0].offsetHeight != 0 ? 
        this.handles[0].offsetHeight : this.handles[0].style.height.replace(/px$/,&quot;&quot;)) : 
      (this.handles[0].offsetWidth != 0 ? this.handles[0].offsetWidth : 
        this.handles[0].style.width.replace(/px$/,&quot;&quot;));
    
    // reposition handles
    this.handles.each( function(h,i) {
      h.style[this.isVertical() ? &#039;top&#039; : &#039;left&#039;] = 
        this.translateToPx(this.values[i]);
    }.bind(this));
  }
})
</pre>
<p>Just drop this code into your <a href="http://wiki.script.aculo.us/scriptaculous/show/HowtoExtendAndOverride">extensions.js</a> file and you should be good to go.  Then just call the instance method like so <code>mySlider.setLength(newLength)</code> where <code>newLength</code> is an integer value.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lindenlan.net/2006/10/20/setlength-extension-for-controlslider/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Control.Touchpad for script.aculo.us</title>
		<link>http://www.lindenlan.net/2006/10/13/controltouchpad-for-scriptaculous/</link>
		<comments>http://www.lindenlan.net/2006/10/13/controltouchpad-for-scriptaculous/#comments</comments>
		<pubDate>Fri, 13 Oct 2006 17:35:48 +0000</pubDate>
		<dc:creator><![CDATA[Brian]]></dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.lindenlan.net/2006/10/13/controltouchpad-for-scriptaculous/</guid>
		<description><![CDATA[I’ve submitted a patch to the Rails developers that adds a Touchpad control to script.aculo.us. It is a 2D control based heavily off of Slider and so shares some of the same options and behavior. The Touchpad callbacks output an array [x, y] rather than a single value v which is what Slider does. Touchpad [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>I’ve submitted a patch to the Rails developers that adds a <a href="http://en.wikipedia.org/wiki/Touchpad">Touchpad</a> control to <a href="http://script.aculo.us/">script.aculo.us</a>.  It is a 2D control based heavily off of <a href="http://wiki.script.aculo.us/scriptaculous/show/Slider">Slider</a> and so shares some of the same options and behavior.  The Touchpad callbacks output an array [x, y] rather than a single value v which is what Slider does.  Touchpad also has no handles so the last value is not preserved.</p>
<p><span id="more-12"></span></p>
<p>Patch: <a href="http://dev.rubyonrails.org/ticket/6398">http://dev.rubyonrails.org/ticket/6398</a></p>
<div id="pad1" style="width:100px;height:100px;background:gray;"></div>
<p id="debug1"><a href="#" onclick="demo();tp.setEnabled();return false;">Enable</a></p>
<p>So what can you do with it?  The basic use is simply to capture mouse input in a defined area of a web page and then map that input to a specific range of values.  Another use would be to hook the output of the Touchpad to the inputs of two Sliders.  This way you have one controller that can control two controllers simultaneously.  (Additionally, this preserves the last value of the Touchpad unless of course you move the Slider independent of the Touchpad.)  Another slick use is one that I’ve seen requested on the forums.  If you hide the overflow of the Touchpad and then nest a really wide div that contains thumbnails for products, you can then limit the output of the Touchpad to horizontal values—the vertical values are simply clamped to 0—and then use the callback to set the left coordinate of the child div.  Now you can scroll through your products without an ugly scrollbar.</p>
<p>If this sounds like something you can use and you can’t wait til the developers choose to add it to the trunk, then go visit the URL above.  Then simply download and run the attached diff file on your script.aculo.us installation using <a href="http://subversion.tigris.org/">Subversion</a>.  I recommend you run the functional test included in the patch (tests/run_functional_test.html –&gt; click on touchpad_test in the left frame) to see some examples of the touchpad in action.</p>
<p>script.aculo.us is at version 1.6.4 at the time of this writing.  </p>
]]></content:encoded>
			<wfw:commentRss>http://www.lindenlan.net/2006/10/13/controltouchpad-for-scriptaculous/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Be Explicit, B-E-Explicit</title>
		<link>http://www.lindenlan.net/2006/10/02/be-explicit-b-e-explicit/</link>
		<comments>http://www.lindenlan.net/2006/10/02/be-explicit-b-e-explicit/#comments</comments>
		<pubDate>Tue, 03 Oct 2006 05:39:55 +0000</pubDate>
		<dc:creator><![CDATA[Brian]]></dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.lindenlan.net/2006/10/03/be-explicit-b-e-explicit/</guid>
		<description><![CDATA[Ruby’s beauty is often attributed to its terseness. However, there are times when you need to be really explicit in order to coax it to do your bidding. For example, a Rails form helper needs a bunch of parantheses and curly braces in order to be a named element. Which makes sense, as :id can [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Ruby’s beauty is often attributed to its terseness.  However, there are times when you need to be really explicit in order to coax it to do your bidding.  For example, a Rails form helper needs a bunch of parantheses and curly braces in order to be a named element.  Which makes sense, as <code>:id</code> can represent a Rails (ActiveRecord) object ID or a DOM element ID.  The Ruby punctuation removes such ambiguity.</p>
<p><span id="more-10"></span></p>
<pre class="brush: ruby">
&lt;%= form_tag( {:controller =&gt; &#039;controller&#039;, :action =&gt; &#039;action&#039;, :id =&gt; 1}, {:id =&gt; &#039;test&#039;, :name =&gt; &#039;test&#039;} )%&gt;
</pre>
<p>This code then produces this HTML.</p>
<pre class="brush: html">
&lt;form action=&quot;/controller/action/1&quot; id=&quot;test&quot; method=&quot;post&quot; name=&quot;test&quot;&gt;
</pre>
<p>Not using the punctuation results in the ID being gobbled up by the URL, or attributes being tacked on to the URL as query string values, or an oh so helpful compile error.  Mmmm taste the sarcasm.</p>
<p>The only reference to this was found, not in the API, but buried in some Rails mailing list thread indexed by Google.  I figured I’d preserve this tidbit for prosperity seeing how I couldn’t find it on another blog.</p>
<p><strong>Note:</strong> Naming <code>form_remote_tag</code> is done differently.  After deciphering the syntax by looking at the source code for the helper, it turns out the key is the <code>:html</code> option.</p>
<pre class="brush: ruby">
&lt;%= form_remote_tag :url =&gt; {:controller =&gt; &#039;controller&#039;, :action =&gt; &#039;action&#039;, :id =&gt; 1}, :html =&gt; {:id =&gt; &#039;test&#039;, :name =&gt; &#039;test&#039;} %&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.lindenlan.net/2006/10/02/be-explicit-b-e-explicit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hey Session, Did You Forget to Delete Me?</title>
		<link>http://www.lindenlan.net/2006/09/21/hey-session-did-you-forget-to-delete-me/</link>
		<comments>http://www.lindenlan.net/2006/09/21/hey-session-did-you-forget-to-delete-me/#comments</comments>
		<pubDate>Fri, 22 Sep 2006 04:17:46 +0000</pubDate>
		<dc:creator><![CDATA[Brian]]></dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.lindenlan.net/?p=6</guid>
		<description><![CDATA[A typical rails design pattern is to store object ids in session variables rather than the objects themselves. Objects can be unwieldy depending on size, complexity, and associations. Ids on the the other hand are small, sleek, and more agile. So to get an object you do the following. instance = Object.find(session[:object_id]) Session data tends [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>A typical rails <a href="http://en.wikipedia.org/wiki/Design_pattern_%28computer_science%29">design pattern</a> is to store object ids in session variables rather than the objects themselves.  Objects can be unwieldy depending on size, complexity, and associations.  Ids on the the other hand are small, sleek, and more <a href="http://en.wikipedia.org/wiki/Agile_development">agile</a>.</p>
<p><span id="more-6"></span></p>
<p>So to get an object you do the following.</p>
<pre class="brush: ruby">
instance = Object.find(session[:object_id])
</pre>
<p>Session data tends to be temporary.  Now if the session variable is nothing but a reference to an object that is persistent, say the current user, then deleting the session object is no big deal.  However, if the intention is that the object the variable references is also temporary that <em>could</em> be a problem.  Now using the above code to obtain an instance, you can always call</p>
<pre class="brush: ruby">
instance.destroy
</pre>
<p>then just set your session variable to a new value, or nullify it (and automagically remove it from the session object).</p>
<p>Now here’s where it get’s tricky.  What if the user agent does not call the action to manually destroy the instance?  Maybe the person behind the browser had to go get a <a href="http://pointfiveblog.com/index.php/2005/08/280">cup of coffee</a>.    Maybe the coder behind <em>your</em> app—wink, wink, nudge, nudge—didn’t put in the action to manage temporary objects.  In any case, the session will expire and your scheduled cron job will clear the sessions dutifully in the case of PStore or ActiveRecordStore, or will expire outright in the case of Memcached.  Unfortunately, the object to which the session pointed will linger on (unless of course you add that code to the cron job as well, but that is arguably bad (see below)).</p>
<p>So, what’s the solution?  Thanks to a tip from RubyPanther on <a href="http://freenode.net/">#rubyonrails</a> and a bit of <a href="http://habtm.com/articles/2005/12/15/whos-online">Google searching</a>, I managed to hack something together.</p>
<p>First, <a href="http://wiki.rubyonrails.org/rails/pages/HowtoChangeSessionStore">setup Rails to store sessions in an ActiveRecord store</a>.  With that you’ll get a sessions table.  Most of what Rails does with the sessions table is hidden behind the scenes, and you want to keep it that way.  This doesn’t mean we can’t stick our hand into the <em>cookie jar</em>.  (OK that’s a bad pun.)  So next let’s create a new model.</p>
<pre class="brush: ruby">
class Session &lt; ActiveRecord::Base
  # borrowed from lib/action_controller/session/active_record_store.rb
  def marshal(data)   Base64.encode64(Marshal.dump(data)) if data end
  def unmarshal(data) Marshal.load(Base64.decode64(data)) if data end

  def before_destroy
  data = self.unmarshal(self.data)
    if data[:object] then
      object = Object.find(data[:object])
      object.destroy
    end
    true
  end
end
</pre>
<p>Because the sessions table is an ActiveRecord store, we can create an ActiveRecord model to get access to it.  The marshalling functions are needed to access the session data which is nothing more than a hash.  Then all we need to do is to define the <code>before_destroy</code> callback to destroy the object that matches the id stored in <code>data[:object]</code>.  Now with the following call</p>
<pre class="brush: ruby">
s = Session.find(1)
s.destroy
</pre>
<p>The session object as well as the object referenced by <code>session[:object]</code> will be destroyed.</p>
<p>So why the trouble of doing this as opposed to just managing it in the script file called by the cron job?   Well for one thing, your script becomes cleaner.</p>
<pre class="brush: ruby">
Sessions.find(:all, :conditions =&gt; [&quot;updated_at &lt;= ?&quot;, Time.now]).each { |session| 
  session.destroy 
}
</pre>
<p>Then there’s the argument that how an object is destroyed should be defined in a model definition.  Plus if the code can be improved to use introspection to determine which object to delete based on the hash key, then all the better.</p>
<p>What would be cooler?  How about making a session object associative?  Wouldn’t it be cool to do something like</p>
<pre class="brush: ruby">
object.session.create # object.session_id belongs_to :sessions, :dependent =&gt; true
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.lindenlan.net/2006/09/21/hey-session-did-you-forget-to-delete-me/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
