<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <title>Peppy Heppy - Home</title>
  <id>tag:peppyheppy.com,2010:mephisto/</id>
  <generator version="0.7.3" uri="http://mephistoblog.com">Mephisto Noh-Varr</generator>
  <link href="http://peppyheppy.com/feed/atom.xml" rel="self" type="application/atom+xml"/>
  <link href="http://peppyheppy.com/" rel="alternate" type="text/html"/>
  <updated>2009-12-09T05:22:11Z</updated>
  <entry xml:base="http://peppyheppy.com/">
    <author>
      <name>Paul</name>
    </author>
    <id>tag:peppyheppy.com,2009-12-09:10281</id>
    <published>2009-12-09T04:59:00Z</published>
    <updated>2009-12-09T05:22:11Z</updated>
    <category term="Ruby"/>
    <category term="Ruby on Rails"/>
    <category term="Tips / Tutorials"/>
    <link href="http://peppyheppy.com/2009/12/9/saving-time-with-threads-the-ruby-way" rel="alternate" type="text/html"/>
    <title>Saving time with Threads the Ruby way</title>
<content type="html">
            &lt;p&gt;I have been working on some projects that require me to do multiple serial webservice calls using soap and http clients. As you might guess without concurrency its such a waste waiting for the network IO and its ends up being accumulative in times&#8212;the more service calls the slower it gets (.5s+1s+2s+1s+1s = 5.5seconds). Originally I wasn&#8217;t worried because I knew I would come back and tweak the performance by using threads and so today was the day for me to get it going. Before I got too crazy coding i wanted to run some basic benchmarks just to see if it would really end up making things faster. Here is what I did:&lt;/p&gt;


&lt;pre&gt;
Benchmark.bm { |rep| 
  rep.report(&quot;non-threading&quot;) { 
    1.upto(100) { |count|
      amount_rest = rand(4)
      # puts &quot;##{count}: sleeping for #{amount_rest}&quot; 
      sleep(amount_rest)
      # puts &quot;##{count}: woke up from a #{amount_rest} second sleep&quot; 
    }
  }

  rep.report(&quot;threading&quot;) { 
    threads = []
    1.upto(100) { |c|
      threads &amp;lt;&amp;lt; Thread.new(c) { |count| 
        amount_rest = rand(4)
        # puts &quot;##{count}: sleeping for #{amount_rest}&quot; 
        sleep(amount_rest)
        # puts &quot;##{count}: woke up from a #{amount_rest} second sleep&quot; 
      }
    }
    while !(threads.map(&#38;:status).uniq.compact.size == 1 and threads.map(&#38;:status).uniq.compact.first == false)
     # puts &quot;will check back soon&quot; 
     sleep(0.3)
    end
  }
}
&lt;/pre&gt;

&lt;pre&gt;
benchmark        user     system      total        real
non-threading  0.100000   0.290000   0.390000 (142.005792)
threading          0.010000   0.020000   0.030000 (  3.182716)
&lt;/pre&gt;

	&lt;p&gt;As you can see, the threading in Ruby works really well as long as each thread is not doing anything &lt;span class=&quot;caps&quot;&gt;CPU&lt;/span&gt; intensive. Even though ruby 1.8.7 does not support native threads, the threading, as you can see above, does work well. When all was said and done, I ended up making more than a 100% improvement and it will work a bit better if and when we have to do more requests concurrently.&lt;/p&gt;


	&lt;p&gt;I do however look forward to using ruby 1.9, but this will do the trick for me now.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://peppyheppy.com/">
    <author>
      <name>Paul</name>
    </author>
    <id>tag:peppyheppy.com,2009-11-25:10277</id>
    <published>2009-11-25T00:55:00Z</published>
    <updated>2010-05-11T17:42:26Z</updated>
    <category term="Ruby"/>
    <category term="Tips / Tutorials"/>
    <link href="http://peppyheppy.com/2009/11/25/libxml-ruby-and-xpath-with-namespaces" rel="alternate" type="text/html"/>
    <title>LibXML-Ruby and XPath with namespaces</title>
<content type="html">
            &lt;p&gt;So, have you ever wasted a half hour coding while also driving yourself absolutely insane? Was it when you were playing with libxml-ruby and xpath?&lt;/p&gt;


	&lt;p&gt;Minutes ago I was coding up a xml-rpc webservice when I realized that I was unable to get the nodes that I was looking for with xpath.&lt;/p&gt;


	&lt;p&gt;As usual I searched google looking for other people having the same issue and nothing helpful came up. I knew I had to write this post when I saw &lt;a href=&quot;http://rubyforge.org/forum/forum.php?thread_id=27168&#38;forum_id=2129&quot;&gt;this&lt;/a&gt;.&lt;/p&gt;


	&lt;p&gt;So my response xml looked somthing like this:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;response = &amp;lt;&amp;lt;-REMOTE_XML
&amp;lt;?xml ...?&amp;gt;
&amp;lt;rootNode xmlns=&quot;http://happythanksgiving.com/htgn&quot;&amp;gt;
  &amp;lt;list&amp;gt;
    &amp;lt;item&amp;gt;hey&amp;lt;/item&amp;gt;
    &amp;lt;item&amp;gt;there&amp;lt;/item&amp;gt;
  &amp;lt;/list&amp;gt;
&amp;lt;/rootNode&amp;gt;
REMOTE_XML&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;My ruby was something like this:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;document = XML::Parser.string(response).parse
namespace = 'http://happythanksgiving.com/htgn'
turkeys = document.find('/htgn:rootNode//item', namespace)&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;But &lt;code&gt;turkeys.size&lt;/code&gt;was always 0.&lt;/p&gt;


	&lt;p&gt;I the found out that I needed to add the namespace prefix to each element in the xpath find&#8230;. duhh!&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;document = XML::Parser.string(response).parse
namespace = 'http://happythanksgiving.com/htgn'
hotels = document.find('/htgn:rootNode//htgn:item', namespace)&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Note the xpath &#8221;/htgn:rootNode//item&#8221; changed to &#8221;/htgn:rootNode//htgn:item&#8221; (added the namespace prefix)&lt;/p&gt;


	&lt;p&gt;Hope this helps some poor hacker or me next July when I forget and start searching google. ;)&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://peppyheppy.com/">
    <author>
      <name>Paul</name>
    </author>
    <id>tag:peppyheppy.com,2009-11-06:10273</id>
    <published>2009-11-06T23:32:00Z</published>
    <updated>2009-11-07T00:13:12Z</updated>
    <category term="Agile"/>
    <category term="Linux / Unix"/>
    <category term="Tips / Tutorials"/>
    <link href="http://peppyheppy.com/2009/11/6/sharing-shell-with-ytalk-on-ubuntu" rel="alternate" type="text/html"/>
    <title>Sharing shell with ytalk on Ubuntu</title>
<content type="html">
            &lt;p&gt;A good friend of mine years ago used to use a command-line app called ytalk to show me around the bash shell (thanks Sione!). After a short while I stopped needing his help and so I stopped using ytalk. At work we really wanted to shell-share with remote team members who were unable to use the iChat screenshare because of OS and bandwidth limitations.&lt;/p&gt;


	&lt;p&gt;I remembered that ytalk was such a good tool for being able to see what someone else was doing in the shell and to show off your bash skills. I thought it was going to be easy to setup on Ubuntu, but as it turns out, although its still an available package, it is dead on install.&lt;/p&gt;


	&lt;p&gt;So&#8230;. here is what I ended up doing and I hope that if you do the same you will be ytalk&#8217;in in no time..&lt;/p&gt;


	&lt;p&gt;On ubuntu install ytalk:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
sudo apt-get install ytalk
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Change the default/broken inetd.comf configuration:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
talk            dgram   udp    wait    nobody.tty    /usr/sbin/in.talkd      in.talkd
ntalk           dgram   udp    wait    nobody.tty    /usr/sbin/in.ntalkd     in.ntalkd
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;to:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
talk            dgram   udp4    wait    root    /usr/sbin/in.talkd      in.talkd
ntalk           dgram   udp4    wait    root    /usr/sbin/in.ntalkd     in.ntalkd
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Note the &#8220;4&#8221; after the udp and the &#8220;nobody.tty&#8221; change to &#8220;root&#8221;&lt;/p&gt;


	&lt;p&gt;In the /etc/services file, make sure the following lines are in there:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
paul@box:~$ sudo grep talk /etc/services
talk            517/udp
ntalk           518/udp
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;I didn&#8217;t have to change anything, but its a good idea to confirm things.&lt;/p&gt;


	&lt;p&gt;Using YTalk&lt;/p&gt;


	&lt;p&gt;Initiating the chat:&lt;/p&gt;


	&lt;p&gt;You can do this in a couple of ways, the first and most obvious way is to coordinate with another person/user and ensure that the two of you are only logged in once to the same box ad then type.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
paul@box:~$ ytalk fred
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Or if your logged on more than once you can specify the tty in the request after finding out which one it is:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
paul@box:~$ who
fred      pts/0        2009-11-06 10:50 (208.X.X.X)
fred      pts/2        2009-11-06 10:48 (208.X.X.X)
paul      pts/3        2009-11-06 14:02 (208.X.X.X)
&lt;/code&gt;&lt;/pre&gt;

&lt;pre&gt;&lt;code&gt;
ytalk fred#2
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;More on that can be found here:
http://manpages.ubuntu.com/manpages/intrepid/man1/ytalk.1.html&lt;/p&gt;


	&lt;p&gt;Thanks to &lt;a href=&quot;http://ubuntuforums.org/showthread.php?t=999187&quot;&gt;euphemus&lt;/a&gt; for the breakthroughs!&lt;/p&gt;


	&lt;p&gt;Hope you find ytalk as useful and coolific as I do.&lt;/p&gt;


	&lt;p&gt;Enjoy!&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://peppyheppy.com/">
    <author>
      <name>Paul</name>
    </author>
    <id>tag:peppyheppy.com,2009-08-25:10248</id>
    <published>2009-08-25T17:18:00Z</published>
    <updated>2009-08-25T17:30:59Z</updated>
    <category term="OSX / Apple"/>
    <category term="Ruby"/>
    <link href="http://peppyheppy.com/2009/8/25/compiling-ruby-on-osx-readline-resolved" rel="alternate" type="text/html"/>
    <title>Compiling Ruby on OSX : Readline [Resolved]</title>
<content type="html">
            &lt;p&gt;An hour before our Daily Scrum this morning I decided to recompile ruby on my Mac (OS &lt;span class=&quot;caps&quot;&gt;X 10&lt;/span&gt;.5.8). I did this because I was trying to install passenger for development. More on that later (maybe).&lt;/p&gt;


	&lt;p&gt;I ran into the following issue with readline while I was building ruby with the &lt;code&gt;--enable-shared&lt;/code&gt; option.&lt;/p&gt;


&lt;pre&gt;
&lt;code&gt;
readline.c: In function ‘filename_completion_proc_call’:
readline.c:703: error: ‘filename_completion_function’ undeclared (first use in this function)
readline.c:703: error: (Each undeclared identifier is reported only once
readline.c:703: error: for each function it appears in.)
readline.c:703: warning: assignment makes pointer from integer without a cast
readline.c: In function ‘username_completion_proc_call’:
readline.c:730: error: ‘username_completion_function’ undeclared (first use in this function)
readline.c:730: warning: assignment makes pointer from integer without a cast
{standard input}:358:non-relocatable subtraction expression, &quot;_mReadline&quot; minus &quot;L00000000007$pb&quot; 
{standard input}:358:symbol: &quot;_mReadline&quot; can't be undefined in a subtraction expression
{standard input}:356:non-relocatable subtraction expression, &quot;_completion_case_fold&quot; minus &quot;L00000000007$pb&quot; 
{standard input}:356:symbol: &quot;_completion_case_fold&quot; can't be undefined in a subtraction expression
{standard input}:342:non-relocatable subtraction expression, &quot;_mReadline&quot; minus &quot;L00000000007$pb&quot; 
&lt;/code&gt;
&lt;/pre&gt;

	&lt;p&gt;After google&#8217;in and coming across some &lt;a href=&quot;http://www.question-defense.com/2008/09/09/compiling-ruby-on-os-x-105-readline/&quot;&gt;similar but different solutions&lt;/a&gt;&lt;/p&gt;


	&lt;p&gt;Then I found &lt;a href=&quot;http://wonko.com/post/how-to-compile-ruby-191&quot;&gt;this&lt;/a&gt; and realized that I was most likely not using the correct readline lib.&lt;/p&gt;


	&lt;p&gt;So, the issue was related to having two readline libraries installed, one in /usr/local/lib, which was installed by port as a dependency to postgres, and the other, located in /usr/lib came with &lt;span class=&quot;caps&quot;&gt;OSX&lt;/span&gt;.&lt;/p&gt;


	&lt;p&gt;For whatever reason ruby 1.8.6 does not like to use the port library so all I had to do to get going was specify which realine library I wanted to use.&lt;/p&gt;


&lt;pre&gt;
&lt;code&gt;
./configure --enable-shared --enable-pthread CFLAGS=-D_XOPEN_SOURCE=1 --with-readline-dir=/usr/local
&lt;/code&gt;
&lt;/pre&gt;

	&lt;p&gt;Happy compiling!&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://peppyheppy.com/">
    <author>
      <name>Paul</name>
    </author>
    <id>tag:peppyheppy.com,2009-06-15:10243</id>
    <published>2009-06-15T05:05:00Z</published>
    <updated>2009-06-15T05:15:02Z</updated>
    <category term="OSX / Apple"/>
    <category term="Ruby"/>
    <category term="Tips / Tutorials"/>
    <link href="http://peppyheppy.com/2009/6/15/fail-sudo-gem-install-mysql-fixed" rel="alternate" type="text/html"/>
    <title>FAIL: sudo gem install mysql (Fixed)</title>
<content type="html">
            &lt;p&gt;The other day I had an issue with ruby and so I went to google to fine a fix&#8230;. I laughed when the second result was my own blog. :)&lt;/p&gt;


	&lt;p&gt;I figured it wouldn&#8217;t hurt to save me some time next time I run into the &lt;span class=&quot;caps&quot;&gt;OS X&lt;/span&gt; nightmare with the mysql gem so here is what happened and what I did to fix it.&lt;/p&gt;


	&lt;p&gt;After running &#8220;sudo gem install mysql&#8221; I got the following errors:&lt;/p&gt;


&lt;pre&gt;
&lt;code class=&quot;ruby&quot;&gt;
/usr/local/bin/ruby extconf.rb
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lm... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lz... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lsocket... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lnsl... no
checking for mysql_query() in -lmysqlclient... no
&lt;/pre&gt;
&lt;/code&gt;

	&lt;p&gt;As usual I looked into the mkmf.log found in the gem directory and saw a bunch of these:&lt;/p&gt;


&lt;pre&gt;
&lt;code class=&quot;ruby&quot;&gt;
&quot;gcc -o conftest -I. -I/usr/local/lib/ruby/1.8/i686-darwin9.6.2 -I. -I/usr/local/include   -D_XOPEN_SOURCE=1  -fno-common -pipe -fno-common conftest.c  -L. -L/usr/local/lib -L/usr
/local/lib -L.      -lruby-static -lmysqlclient  -lpthread -ldl -lobjc  &quot; 
ld: library not found for -lmysqlclient
collect2: ld returned 1 exit status
checked program was:
/* begin */
1: /*top*/
2: int main() { return 0; }
3: int t() { mysql_query(); return 0; }
/* end */
&lt;/code&gt;
&lt;/pre&gt;

	&lt;p&gt;So here is what I did to fix it:&lt;/p&gt;


&lt;pre&gt;
&lt;code class=&quot;ruby&quot;&gt;
sudo ln -s /usr/local/mysql/include /usr/local/include/mysql
sudo ln -s /usr/local/mysql/lib /usr/local/lib/mysql
&lt;/code&gt;
&lt;/pre&gt;

&lt;pre&gt;
&lt;code class=&quot;ruby&quot;&gt;
[heppy /usr/local/lib/ruby/gems/1.8/gems/mysql-2.7 64]$ sudo gem install mysql
Building native extensions.  This could take a while...
Successfully installed mysql-2.7
1 gem installed
Installing ri documentation for mysql-2.7...
&lt;/code&gt;
&lt;/pre&gt;

	&lt;p&gt;Yeah!&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://peppyheppy.com/">
    <author>
      <name>Paul</name>
    </author>
    <id>tag:peppyheppy.com,2009-05-24:10242</id>
    <published>2009-05-24T06:48:00Z</published>
    <updated>2009-05-24T07:27:08Z</updated>
    <category term="Ruby"/>
    <category term="Ruby on Rails"/>
    <category term="Tips / Tutorials"/>
    <link href="http://peppyheppy.com/2009/5/24/mongrel-to-passenger-with-cpanel" rel="alternate" type="text/html"/>
    <title>Mongrel to Passenger with CPanel</title>
<content type="html">
            &lt;p&gt;I host this blog on &lt;a href=&quot;https://manage.slicehost.com/customers/new?referrer=c4604a38d6b07d7d8c699f03a04f1c64&quot;&gt;slicehost&lt;/a&gt; and used to have a couple of slices, one for rails, and one for client sites, php, email etc. Just a few hours ago I moved my blog from my Rails slice to what I call my CPanel slice using passenger and the process was smooth sailing. In the process I decided to leverage what I learned about Cpanel and Passenger and I created a gem called &lt;a href=&quot;http://github.com/peppyheppy/cpanel-passenger/tree/master&quot;&gt;cpanel-passenger which can be found on github&lt;/a&gt;.&lt;/p&gt;


	&lt;p&gt;The gem just installs a command called cpanel-passenger that takes a bunch of parameters to modify the Apache config in a way that will not make Cpanel upset.&lt;/p&gt;


	&lt;p&gt;There is a lot of work to do to make this script do all that one would want, but at least it makes setting up a rails app on passenger a simpler task with Cpanel. Feel free to fork the gem and add to it. Its just a matter of time and the Cpanel folks will bundle passenger as a supported module, but until then try this out on your &lt;span class=&quot;caps&quot;&gt;VPS&lt;/span&gt; that is running Cpanel.&lt;/p&gt;


	&lt;p&gt;Enjoy!&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://peppyheppy.com/">
    <author>
      <name>Paul</name>
    </author>
    <id>tag:peppyheppy.com,2009-03-12:6508</id>
    <published>2009-03-12T04:12:00Z</published>
    <updated>2009-09-30T18:23:14Z</updated>
    <category term="Ruby"/>
    <category term="Ruby on Rails"/>
    <category term="Tips / Tutorials"/>
    <link href="http://peppyheppy.com/2009/3/12/a-default-route-gone-404-when-it-should" rel="alternate" type="text/html"/>
    <title>A default route gone 404 when it should</title>
<content type="html">
            &lt;p&gt;&lt;strong&gt;&lt;span class=&quot;caps&quot;&gt;UPDATE&lt;/span&gt;: This worked for Rails &amp;lt; 2.0, but now you should follow something like &lt;a href=&quot;http://www.sitepoint.com/blogs/2007/11/07/preparing-for-rails-20-controller-based-exception-handling/&quot;&gt;this&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;


	&lt;p&gt;Rails routes are a critical piece of a rails application. One issue about the routes is that there isn&#8217;t a default route for the home page of an application. Typically, one would create a controller and create a route for a default controller and default action. Here is what one of mine looks like:&lt;/p&gt;


&lt;pre&gt;
map.root :controller =&amp;gt; 'main', :action =&amp;gt; 'home'
&lt;/pre&gt;

	&lt;p&gt;There is one problem with this. The url http://domain.com/blah%20blah will go to the main controller and will throw an &#8220;no action/ no id given&#8221; exception which will result in a 500 error. This is not what you want for &lt;span class=&quot;caps&quot;&gt;SEO&lt;/span&gt; or otherwise.&lt;/p&gt;


	&lt;p&gt;The solution is quite simple, all you have to do is add a method missing to the main controller and add a method missing that logs and renders a real 404 page and http status.&lt;/p&gt;


&lt;pre&gt;
  def method_missing(method, *args)
    logger.warn &quot;action #{method} dos not exist, 404&quot; 
    render :file =&amp;gt; File.join(RAILS_ROOT, 'public', '404.html'), :status =&amp;gt; 404
  end
&lt;/pre&gt;

	&lt;p&gt;There may be better ways to do this, but this is one way around the false 500 errors, especially if your likely to get old inbound links to your site.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://peppyheppy.com/">
    <author>
      <name>Paul</name>
    </author>
    <id>tag:peppyheppy.com,2009-03-10:6507</id>
    <published>2009-03-10T01:12:00Z</published>
    <updated>2009-03-10T01:47:43Z</updated>
    <category term="Ruby"/>
    <category term="Ruby on Rails"/>
    <category term="Tips / Tutorials"/>
    <link href="http://peppyheppy.com/2009/3/10/making-the-rails-request-profiler-and-kcachegrind-play" rel="alternate" type="text/html"/>
    <title>Making the Rails Request Profiler and KCacheGrind Play</title>
<content type="html">
            &lt;p&gt;I have been working on optimizing my companies site after porting over many features. I have been finding the newer rails performance tools including the request profiler to be very helpful in this effort. Ryan Bates put out a great screencast on &lt;a href=&quot;http://railscasts.com/episodes/98-request-profiling&quot;&gt;request profiling&lt;/a&gt; that will get you started, but if your app has any complexity, you will find out quickly like I did that the html file gets too large and is not very helpful when it crashes your browser. ;)&lt;/p&gt;


	&lt;p&gt;Assuming that you have already installed KCacheGrind on your Mac using &lt;a href=&quot;http://www.finkproject.org/&quot;&gt;fink&lt;/a&gt;, you can do the following:&lt;/p&gt;


# Open up the &lt;code&gt;request_profiler.rb&lt;/code&gt; in the actionpack gem (the code that is used by ./script/performance/request)
&lt;pre&gt;
mate /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/request_profiler.rb
&lt;/pre&gt;
# Add the following lines of ruby to the &lt;code&gt;show_profile_results&lt;/code&gt; method at the bottom.
&lt;pre&gt;
        File.open &quot;#{RAILS_ROOT}/tmp/profile-call-tree.kcg&quot;, 'w' do |file|
           RubyProf::CallTreePrinter.new(results).print(file)
           `kcachegrind #{file.path}` if options[:open]
        end
&lt;/pre&gt;

	&lt;p&gt;Now next time you run the request profiler you will see the KCacheGrind open up with the call tree output in it, yeah!&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://peppyheppy.com/">
    <author>
      <name>Paul</name>
    </author>
    <id>tag:peppyheppy.com,2009-03-05:6506</id>
    <published>2009-03-05T23:29:00Z</published>
    <updated>2009-03-05T23:34:39Z</updated>
    <category term="Ruby"/>
    <category term="Ruby on Rails"/>
    <category term="Tips / Tutorials"/>
    <link href="http://peppyheppy.com/2009/3/5/changing-session-store-in-rails" rel="alternate" type="text/html"/>
    <title>Changing Session Store in Rails</title>
<content type="html">
            &lt;p&gt;&lt;span class=&quot;caps&quot;&gt;TIP&lt;/span&gt;: If you change the sessions store in rails, I would recommend also changing the session_id so your app doesn&#8217;t blow up with 500 errors on every request.&lt;/p&gt;


	&lt;p&gt;I changed the store from cookie based sessions (the default) to memcached based sessions.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://peppyheppy.com/">
    <author>
      <name>Paul</name>
    </author>
    <id>tag:peppyheppy.com,2009-01-15:6505</id>
    <published>2009-01-15T02:28:00Z</published>
    <updated>2009-01-15T02:56:00Z</updated>
    <category term="Ruby"/>
    <category term="Ruby on Rails"/>
    <category term="Tips / Tutorials"/>
    <link href="http://peppyheppy.com/2009/1/15/automatic-hidden-form-fields-and-lightview" rel="alternate" type="text/html"/>
    <title>Automatic hidden form fields and lightview</title>
<content type="html">
            &lt;p&gt;Ever needed to automatically add a hidden field in a form? Here is what I did to make it happen.&lt;/p&gt;


	&lt;p&gt;Not sure if its the best solution, but it worked for me&#8230; at least until the next rails release. ;)&lt;/p&gt;


	&lt;p&gt;In the original &lt;code&gt;form_for&lt;/code&gt; code it creates a form tag which prints out the templates in the blog that is passed to it. There is a method that creates the opening form tag and it already creates &lt;code&gt;extra_tags&lt;/code&gt;. All I do it add an additional concatenated string to the fields with the result of a custom method that I created called &lt;code&gt;my_custom_extra_tags&lt;/code&gt;. Anything the method returns will be added to each form.&lt;/p&gt;


&lt;pre&gt;
module ActionView::Helpers::FormTagHelper

  # form_tag_html overridden on line 454 in actionpack-2.2.2/lib/action_view/helpers/form_tag_helper.rb

  # original
  # def form_tag_html(html_options)
  #   extra_tags = extra_tags_for_form(html_options)
  #   tag(:form, html_options, true) + extra_tags
  # end

  # modified
  def form_tag_html(html_options)
    extra_tags = extra_tags_for_form(html_options)
    tag(:form, html_options, true) + extra_tags + my_custom_extra_tags
  end

  def my_custom_extra_tags
     (params[:lightview].blank? ? '' : hidden_field_tag(:lightview, params[:lightview]))
  end

end
&lt;/pre&gt;

	&lt;p&gt;I used this to show the same controller action with different templates and in my application controller I determine which template to show from a passed in parameter that cannot be lost or the template will revert back to the default template. Now all I have to do is pass a parameter lightview to the iframe source and the correct template will show before and after the form inside the iframe is submitted.&lt;/p&gt;


	&lt;p&gt;Hope this was helpful.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://peppyheppy.com/">
    <author>
      <name>Paul</name>
    </author>
    <id>tag:peppyheppy.com,2009-01-14:6504</id>
    <published>2009-01-14T17:21:00Z</published>
    <updated>2009-01-14T17:33:13Z</updated>
    <category term="Linux / Unix"/>
    <category term="Subversion"/>
    <category term="Thoughts / Experiences"/>
    <link href="http://peppyheppy.com/2009/1/14/fail-compromised-ssh-public-key-on-ubuntu" rel="alternate" type="text/html"/>
    <title>FAIL: COMPROMISED SSH Public Key on Ubuntu</title>
<content type="html">
            &lt;p&gt;Last night I was setting up a new &lt;a href=&quot;http://simplyscrum.com&quot;&gt;application&lt;/a&gt; on my server and while I was configuring capistrano I came across this strange problem and didn&#8217;t immediately find much help on google, so I thought I would post this to help someone else along.&lt;/p&gt;


	&lt;p&gt;I had already setup my ssh keys months ago but when I tried to ssh into my subversion repository it would ask me for a password/passphrase and it just about drove me crazy.&lt;/p&gt;


	&lt;p&gt;I came across &lt;a href=&quot;http://ramblings.narrabilis.com/wp/ssh-key-problem-troubleshooting/&quot;&gt;this article&lt;/a&gt; in google and checked off each potential problem and nothing. Then I saw that my key was conprimized when I ran the &#8220;ssh-vulnkey -a&#8221; command.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
capistrano@allison:~/.ssh$  ssh-vulnkey -a
Unknown (no blacklist information): 2048 5a:b4:d6:94:10:14:e1:a0:35:35:ff:c6:08:e6:9f:10 
Not blacklisted: 2048 5f:43:c2:f0:fb:e6:52:c4:90:59:fb:d2:e0:fe:66:d0 
Unknown (no blacklist information): 2048 ab:5e:39:5c:33:f0:02:e3:cf:cd:99:84:ca:9e:f8:e1 Paul@paul-hepworths-computer.local
COMPROMISED: 2048 81:85:1d:a7:b1:c6:ff:b2:d5:3f:60:3e:2e:c0:25:5c capistrano@mislice
COMPROMISED: 1024 fa:87:13:5f:0c:01:3e:53:b9:a1:ff:4a:8a:29:b2:a1 capistrano@mislice
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;So I searched google some more to find out how to fix the problem. I regenerated keys multiple times on my  client server and no-dice.&lt;/p&gt;


	&lt;p&gt;Then after searching and searching I found &lt;a href=&quot;http://ubuntu-tutorials.com/2008/05/13/openssh-openssh-vulnerabilities-confirm-fix-instructions/&quot;&gt;this tutorial and followed it to update openssl and openssh and regenerate my private keys&lt;/a&gt; .&lt;/p&gt;


	&lt;p&gt;What a relief! (and a waste of time, but now I am secure I guess)&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://peppyheppy.com/">
    <author>
      <name>Paul</name>
    </author>
    <id>tag:peppyheppy.com,2008-07-17:6500</id>
    <published>2008-07-17T05:39:00Z</published>
    <updated>2008-07-17T05:41:25Z</updated>
    <category term="Events"/>
    <category term="Ruby on Rails"/>
    <link href="http://peppyheppy.com/2008/7/17/scaling" rel="alternate" type="text/html"/>
    <title>Scaling Anything</title>
<content type="html">
            &lt;p&gt;Tonight I attended a presentation at Google that given by Jason Hoffman (the &lt;span class=&quot;caps&quot;&gt;CTO&lt;/span&gt; at Joyent) about Ruby, and scaling web architecture. Although none of the actual information was new to me it did remind me of the basic points to scaling a web application. Here they are.&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;Scalability is language, performance, and throughput independent.&lt;/li&gt;
	&lt;/ul&gt;


	&lt;ul&gt;
	&lt;li&gt;Test each piece of your architecture and find out what the maximums of each service are.&lt;/li&gt;
	&lt;/ul&gt;


	&lt;ul&gt;
	&lt;li&gt;Find the real bottlenecks and remove them efficiently. (Use DTrace)
An example was how Apache&#8217;s proxy module will limit the number of requests per second to 140 per Apache instance, and by using virtualization you could have eight instances running Apache on the same server with the capacity of 1120 rps.&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;Overall it was worth while especially when you factor in the snacks and dinner that Google provided.&lt;/p&gt;


	&lt;p&gt;Scale away!&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://peppyheppy.com/">
    <author>
      <name>Paul</name>
    </author>
    <id>tag:peppyheppy.com,2008-05-09:5937</id>
    <published>2008-05-09T04:43:00Z</published>
    <updated>2008-05-24T03:59:29Z</updated>
    <category term="Ruby"/>
    <category term="Ruby on Rails"/>
    <category term="Tips / Tutorials"/>
    <link href="http://peppyheppy.com/2008/5/9/url-canonicalization-in-rails" rel="alternate" type="text/html"/>
    <title>Url Canonicalization in Rails</title>
<content type="html">
            &lt;p&gt;In one of my &lt;a href=&quot;/2008/5/6/really-custom-urls-in-rails&quot;&gt;last posts&lt;/a&gt; I showed how I was able to create completely custom urls for &lt;span class=&quot;caps&quot;&gt;SEO&lt;/span&gt;, but there is an issue that sometimes comes up when creating custom urls or when migrating urls, etc.&lt;/p&gt;


	&lt;p&gt;Here is a simple way to ensure that urls that are being requested are valid. Google and Yahoo! (and others) crawl your sites links and can on occasion come across an incorrect ink from someone else&#8217;s site that may be old or mistyped. There are some stiff penalties associated with having two different urls pointing to the same page. There may also be a need to retire certain urls or to change the way they are formated.&lt;/p&gt;


Here is an example, the &lt;span class=&quot;caps&quot;&gt;URL&lt;/span&gt;:
&lt;pre&gt;
http://domain.com/d-123456-mountain_viewering
&lt;/pre&gt;

	&lt;p&gt;Should be redirected to:&lt;/p&gt;


&lt;pre&gt;
http://domain.com/d-123456-mountain_view
&lt;/pre&gt;

	&lt;p&gt;Here is the simple solution:&lt;/p&gt;


	&lt;p&gt;I created a module that looked like the following in the lib directory and included it into the ActionController class.&lt;/p&gt;


&lt;pre&gt;
include ActiveRecord

module MY
  module URL

    def page_code_object_map
      { 
        'd' =&amp;gt; Destination, 'p' =&amp;gt; Photo
      }
    end

    def execute_url_post_process
      canonicalize if params[:canonicalize]
    end

    def canonicalize

      whole_url   = request.request_uri().split('?')[0].split('#')[0]
      url_pieces  = current_url.split('-')
      page_type   = url_pieces[0].gsub(/\//, '')
      type_id     = url_pieces[1]

      begin
        object = page_code_object_map[page_type].find(type_id)
        canonical_url = send &quot;custom_#{page_type}_path&quot;, object, params
      rescue RecordNotFound =&amp;gt; e
        render :file =&amp;gt; File.join(RAILS_ROOT, 'public', '404.html'), :status =&amp;gt; 404
        return
      end

      if canonical_url and canonical_url != whole_url
        headers['Status'] = '301 Moved Permanently'
        redirect_to(&quot;#{http_base}#{canonical_url}&quot;, :status =&amp;gt; 301)
      end

    end

  end
end

ActionController::Base.send :include, MY::URL
ActionView::Base.send :include, MY::URL
&lt;/pre&gt;

	&lt;p&gt;In the route below, notice that I am passing a parameter named &lt;code&gt;:canonicalize&lt;/code&gt; with the value of &lt;code&gt;true&lt;/code&gt;. This parameter is passed through to the controller as a request parameter and can be accessed in the &lt;code&gt;params&lt;/code&gt; hash.&lt;/p&gt;


&lt;pre&gt;
map.d '/d-:destination_global_id-:name*other_params', :controller =&amp;gt; 'destinations', :action =&amp;gt; 'show', :canonicalize =&amp;gt; true, :destination_global_id =&amp;gt; /\d{1,20}/, :name =&amp;gt; /[^-]+/
&lt;/pre&gt;

	&lt;p&gt;How does this all work you say? Simple. In your application controller (controllers/application.rb) you need to include something like this:&lt;/p&gt;


&lt;pre&gt;
before_filter :execute_url_post_process
&lt;/pre&gt;

	&lt;p&gt;This will start the checking process by calling the &lt;code&gt;execute_url_post_process()&lt;/code&gt; method defined above in my module. If the route that matches passes the &lt;code&gt;:cononicalize&lt;/code&gt; parameter, the &lt;code&gt;conanicalize()&lt;/code&gt; method will get the current url and certain important pieces. Then depending on the object that is mapped to the page code (d) it will reconstruct the url of the destination object that should match the existing url. If it matches then were golden, if it doesn&#8217;t then we redirect to the new/correct url ensuring that we do not loose page rank or be counted as spam (duplicate content).&lt;/p&gt;


	&lt;p&gt;There are many things that you can do within this code. Some of them include managing authorization, hiding pages, etc.&lt;/p&gt;


	&lt;p&gt;I hope you enjoyed this tip. If you have any suggestions, please post them, I am sure some genius will have something to add. :)&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://peppyheppy.com/">
    <author>
      <name>Paul</name>
    </author>
    <id>tag:peppyheppy.com,2008-05-06:5936</id>
    <published>2008-05-06T05:35:00Z</published>
    <updated>2008-05-06T05:35:56Z</updated>
    <category term="Ruby"/>
    <category term="Ruby on Rails"/>
    <category term="Tips / Tutorials"/>
    <link href="http://peppyheppy.com/2008/5/6/really-custom-urls-in-rails" rel="alternate" type="text/html"/>
    <title>Really Customized Urls for SEO in Rails</title>
<content type="html">
            &lt;p&gt;I needed to build urls that were packed with keywords for &lt;span class=&quot;caps&quot;&gt;SEO&lt;/span&gt;. I needed to make sure that the url more fully described the contents of the page.&lt;/p&gt;


	&lt;p&gt;This default rails url does not cut it.&lt;/p&gt;


&lt;pre&gt;/destinations/12345&lt;/pre&gt;  

	&lt;p&gt;This does cut it.&lt;/p&gt;


&lt;pre&gt;/d-12345-mountain_view&lt;/pre&gt;

	&lt;p&gt;So here is the hack that I did to get the desired affect. (Suggestions or insults on my approach are welcomed!)&lt;/p&gt;


	&lt;p&gt;First, I added this code into a plugin that I was using for our custom routes stuff. You can probably add this to the environment.rb file or better yet to a a file within lib and just make sure that you require the file from within environment.rb. I really needed to add the &#8217;-&#8217; as a delimiter.&lt;/p&gt;


	&lt;p&gt;This is step is important because by default rails uses slashes (/) as a dilimeter for parts of the url, but by adding a dash (-) to the array things work the way they should.&lt;/p&gt;


&lt;pre&gt;
module ActionController
  module Routing
    SEPARATORS = %w( / ; . , ? -)  
  end
end
&lt;/pre&gt;

	&lt;p&gt;Then I added a named route (config/routes.rb) that looked something like this:&lt;/p&gt;


&lt;pre&gt;
map.d '/d-:destination_global_id-:name*other_params', :controller =&amp;gt; 'destinations', :action =&amp;gt; 'show', :canonicalize =&amp;gt; true, :destination_global_id =&amp;gt; /\d{1,20}/, :name =&amp;gt; /[^-]+/
&lt;/pre&gt;

	&lt;p&gt;Now we can create helper methods that take all of these wonderful parameters.&lt;/p&gt;


&lt;pre&gt;
def custom_d_path(destination, params={})
  d_path(
    destination.global_id, 
    string_for_url(destination.name)
  ) + (params.size &amp;gt; 0 ? create_other_parameters(params) : &quot;&quot;)
end                                                
&lt;/pre&gt;

	&lt;p&gt;The method string_for_url() just replaced spaces with underscored and removed illegal characters.&lt;/p&gt;


	&lt;p&gt;The create_other_parameters() appended parameters in a subtle way that ensured that Google and Yahoo! wouldn&#8217;t get prejudice about dynamic pages with parameters. (This is another topic for another time.)&lt;/p&gt;


	&lt;p&gt;In short, now we can simply call custom_d_path(destination) from any view (or controller if we included the helper in both ActionView and ActionController classes).&lt;/p&gt;


	&lt;p&gt;I realize that there may be a better way to do this to make it simpler to code, but this is a simple example of &lt;strong&gt;a&lt;/strong&gt; way to solve this problem.&lt;/p&gt;


	&lt;p&gt;Now for a couple of caveats:&lt;/p&gt;


	&lt;ol&gt;
	&lt;li&gt;For those who have &lt;span class=&quot;caps&quot;&gt;OCRD&lt;/span&gt; (obsesive compulsive &lt;span class=&quot;caps&quot;&gt;REST&lt;/span&gt; disorder) the urls may not suite your style. I use them for the read only pages of a site.&lt;/li&gt;
		&lt;li&gt;You may not need to go to this extreme to keyword pack your urls&#8230; there are many other approaches that may be more robust and easier to implement.&lt;/li&gt;
	&lt;/ol&gt;


	&lt;p&gt;Hopefully this example helps someone. :)&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://peppyheppy.com/">
    <author>
      <name>Paul</name>
    </author>
    <id>tag:peppyheppy.com,2008-03-21:5024</id>
    <published>2008-03-21T07:52:00Z</published>
    <updated>2008-04-08T05:19:43Z</updated>
    <category term="Subversion"/>
    <category term="Tips / Tutorials"/>
    <link href="http://peppyheppy.com/2008/3/21/merging-branches-with-subversion-usind-cli-and-filemerge" rel="alternate" type="text/html"/>
    <title>Merging Branches with Subversion using CLI and FileMerge</title>
<content type="html">
            &lt;p&gt;On small projects I usually work right out of trunk to avoid the need to merge, but when working in teams to implement features that will be released separately creating a branch or two is the way to go. The only problem with working with branches is that you have to merge your code periodically in order to avoid nightmares. Here are the steps that I use to to a simple merge between a development branch and trunk. If there are better ways or if I missed something please let me know, but these is what worked for me.&lt;/p&gt;


	&lt;p&gt;1) First &lt;code&gt;svn update&lt;/code&gt; local working copy (both trunk and branches)&lt;/p&gt;


	&lt;p&gt;2) Change directory to the branch (branches/development)&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;cd /Users/Paul/Documents/test_svn/repo/&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;3)  Run a merge command similar to the one below as a dry-run to see if everything looks OK:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;svn merge --dry-run -r 4:HEAD file:///Users/Paul/Documents/test_svn/repo/trunk&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;4) Then if you are satisfied with what you see, you can run the real command which will actually update your working copy with the merged files from trunk.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;svn merge -r 4:HEAD file:///Users/Paul/Documents/test_svn/repo/trunk&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;5) If you have conflicts (lines that start with &#8220;C&#8221;,) then its time to merge the changes.
I use FileMerge and merging the right version with the working version and then I save the merged file and then&lt;/p&gt;


	&lt;p&gt;6) Checkin all of the merges files by doing a svn commit.&lt;/p&gt;


	&lt;p&gt;7) No change directories to the Trunk working copy and run the following as a dry run.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;svn merge --dry-run -r 4:HEAD file:///Users/Paul/Documents/test_svn/repo/branches/development&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;8) Then if everything checks out, you do the real merge:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;svn merge -r 4:HEAD file:///Users/Paul/Documents/test_svn/repo/branches/development&lt;/code&gt;&lt;/pre&gt; 
&lt;p&gt;&lt;span class=&quot;caps&quot;&gt;NOTE&lt;/span&gt;: when merging the branch back into trunk, you must use the same revision number as the you did when you merged trunk into the branch, or the revision number of the commit made after the last merge from trunk to your branch.&lt;/p&gt;
&lt;p&gt;If you not done any regular merges, which you should do &lt;span class=&quot;caps&quot;&gt;BTW&lt;/span&gt;, to avoid really hairy merges, then your revision numbers for both merges will be the same.&lt;/p&gt;

	&lt;p&gt;9) Resolve any conflicts.&lt;/p&gt;


	&lt;p&gt;10) Checkin all of the merges files by doing a svn commit.&lt;/p&gt;


	&lt;p&gt;Now your two branches are synced up! Yeah! Happy merging!&lt;/p&gt;


	&lt;p&gt;&lt;strong&gt;The key is making sure you keep track of revision numbers and merging, one way to do that is to create a tag with a date or sequence number. Also, you can look into the history by using the &lt;code&gt;svn log .&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;
          </content>  </entry>
</feed>
