<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"><channel><description>ramblings, musing and code snippets</description><title>veader, the codemonky</title><generator>Tumblr (3.0; @veader)</generator><link>http://codemonky.com/</link><item><title>Google does Atlanta</title><description>&lt;img src="http://media.tumblr.com/LdzHTkOYNagm53fyLP1PFryP_500.jpg"/&gt;&lt;br/&gt;&lt;br/&gt;Google does Atlanta</description><link>http://codemonky.com/post/39185058</link><guid>http://codemonky.com/post/39185058</guid><pubDate>Fri, 20 Jun 2008 13:36:39 -0400</pubDate></item><item><title>Endless Pages</title><description>&lt;p&gt;Having heard a blurb on an endless page plugin on the &lt;a href="http://railsenvy.com"&gt;RailsEnvy&lt;/a&gt; podcast, I decided to check it out. I wasn’t happy with how the plugin worked, so I whipped up something similar.&lt;/p&gt;
&lt;p&gt;(Original post mentioned on RailsEnvy: &lt;a href="http://bewhite.blogspot.com/2008/05/rails-endless-page-plugin.html"&gt;link&lt;/a&gt;)&lt;/p&gt;
&lt;p&gt;I decided most of what was needed was a mix of the wonderful will_paginate plugin and some Javascript. Thus &lt;b&gt;endlesspage.js&lt;/b&gt; was born.&lt;/p&gt;
&lt;p&gt;After including endlesspage.js in your layout, you should be able to do follow along below on how to set it up.&lt;/p&gt;
&lt;p&gt;In the &lt;strong&gt;Controller&lt;/strong&gt;: &lt;a href="http://pastie.org/197801"&gt;pastie&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;In the &lt;strong&gt;Views&lt;/strong&gt;: &lt;a href="http://pastie.org/197803"&gt;pastie&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Here is the file: &lt;a href="http://pastie.org/197806"&gt;endlesspage.js&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;(Sorry, but I couldn’t get Tumblr to cooperate with dumping in code.) &lt;/p&gt;
&lt;p&gt;Let me know if you find this helpful… &lt;/p&gt; 
&lt;p&gt;&lt;strong&gt;UPDATE:&lt;/strong&gt; I was informed (and confirmed myself) that the gem version of will_paginate doesn’t have the page_count method. The substitute method is total_pages.&lt;/p&gt;</description><link>http://codemonky.com/post/34940898</link><guid>http://codemonky.com/post/34940898</guid><pubDate>Thu, 15 May 2008 16:19:00 -0400</pubDate></item><item><title>Video</title><description>&lt;object width="400" height="336"&gt;&lt;param name="movie" value="http://www.youtube.com/v/Tbxq0IDqD04"&gt;&lt;/param&gt;&lt;param name="wmode" value="transparent"&gt;&lt;/param&gt;&lt;embed src="http://www.youtube.com/v/Tbxq0IDqD04" type="application/x-shockwave-flash" width="400" height="336" wmode="transparent"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;br/&gt;&lt;br/&gt;</description><link>http://codemonky.com/post/32181874</link><guid>http://codemonky.com/post/32181874</guid><pubDate>Fri, 18 Apr 2008 16:28:49 -0400</pubDate></item><item><title>silencing deprecations</title><description>&lt;p&gt;OK, so if you’re stuck in Rails 1.2.X land like I am, you’re probably tired of seeing all the deprecation warnings when you run your test suite. (Yes, I know pagination is going away but someone might severly punish me for will_paginate at the moment.)&lt;/p&gt;
&lt;p&gt; Add this to your test/test_helper.rb&lt;/p&gt;
&lt;pre&gt; &lt;p&gt; ActiveSupport::Deprecation.silenced= true &lt;br/&gt;&lt;/p&gt;&lt;/pre&gt; </description><link>http://codemonky.com/post/31491014</link><guid>http://codemonky.com/post/31491014</guid><pubDate>Fri, 11 Apr 2008 14:34:57 -0400</pubDate></item><item><title>Git on OSX</title><description>&lt;p&gt;Hit a roadblock compiling git tonight. Thanks to jnewland for the last piece of the puzzle.&lt;/p&gt; &lt;pre&gt;curl -O &lt;a href="http://kernel.org/pub/software/scm/git/git-1.5.4.5.tar.bz2"&gt;http://kernel.org/pub/software/scm/git/git-1.5.4.5.tar.bz2&lt;/a&gt; &lt;br/&gt;tar ixf git-1.5.4.5.tar.bz2 &lt;br/&gt;cd git-1.5.4.5 &lt;br/&gt;./configure --prefix=/usr/local &lt;br/&gt;make NO_MSGFMT=1 &lt;br/&gt;sudo make install  &lt;/pre&gt;</description><link>http://codemonky.com/post/31414966</link><guid>http://codemonky.com/post/31414966</guid><pubDate>Thu, 10 Apr 2008 23:00:24 -0400</pubDate></item><item><title>Apple goodness</title><description>&lt;img src="http://media.tumblr.com/LdzHTkOYN7bnicyuiZxTBGyA_500.jpg"/&gt;&lt;br/&gt;&lt;br/&gt;Apple goodness</description><link>http://codemonky.com/post/30581804</link><guid>http://codemonky.com/post/30581804</guid><pubDate>Wed, 02 Apr 2008 12:20:17 -0400</pubDate></item><item><title>establish_connection may harm you</title><description>&lt;p&gt;So I have a reporting Rails application that is looking at the databases of two other Rails apps. I import the models using an svn:external link. I then have initializers that do a bit of “magic” switching which databases the models use and what their table names are based on the schema. We use Postgres so the “databases” are actually schemas in the same physical database.&lt;/p&gt; &lt;code&gt;&lt;/code&gt;&lt;pre&gt;unless RAILS_ENV.downcase == 'test'&lt;br/&gt;  # point all of the vanguard models to the champion_#{RAILS_ENV} database&lt;br/&gt;  Dir[File.expand_path('app/models/vanguard/*.rb',RAILS_ROOT)].each do |file|&lt;br/&gt;    model_str = $1.classify if file =~ /\/vanguard\/(.*?)\.rb$/&lt;br/&gt;&lt;br/&gt;    next unless model_str&lt;br/&gt;    # skip the models that aren't active record models&lt;br/&gt;    next if %w(...).include?(model_str)&lt;br/&gt;&lt;br/&gt;    eval("#{model_str}.instance_eval('establish_connection \"champion_#{RAILS_ENV}\"')")&lt;br/&gt;    table_name = eval("#{model_str}.table_name")&lt;br/&gt;    eval("#{model_str}.instance_eval('set_table_name \"vanguard.#{table_name}\"')") &lt;br/&gt;  end&lt;br/&gt;end &lt;/pre&gt; &lt;p&gt;I kept running into a problem where the maximum number of connections to this database was being exceeded. After poking around some I believe establish_connection isn’t doing the smart thing. It seems to blindly establish a connection each time it is called disregarding the fact that the connection might already be open.&lt;/p&gt;
&lt;p&gt; I switched the logic such that the “primary” database is now this external connection and sub-class all of my internal models to use an abstract ActiveRecord class that points to a different database. The number of connections has dropped significantly. &lt;/p&gt;</description><link>http://codemonky.com/post/29190425</link><guid>http://codemonky.com/post/29190425</guid><pubDate>Tue, 18 Mar 2008 10:46:00 -0400</pubDate></item><item><title>Ordering Matters</title><description>&lt;p&gt;So I found another interesting gotcha in Rails today.&lt;/p&gt;
&lt;p&gt;Some background: I have a reporting application that uses models from a running application that I can’t touch the code for for fear of the FDA overlords. In doing some of the reports, I want to “fix” things that were left out of the original application. For instance the office model should be associated with the patients that belong to it; however, this is not the case.&lt;/p&gt;
&lt;p&gt; Knowing the fun of “monkey patching”, I can easily add this association in my action on the reporting app with something like:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Office.class_eval("has_many :patients")&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt; Now office.patients works.&lt;/p&gt;
&lt;p&gt; Then I wanted to have the count of patients for each office so I used the same trick to have a variable to stuff the count in, ala:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Office.class_eval("attr_accessor :patient_count")&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt; Now office.patient_count = office.patients.count works like a charm.&lt;/p&gt;
&lt;p&gt; Here’s where the gotcha occurred. I was actually putting a condition on the count.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;offices.each do |o|&lt;br/&gt;   o.patient_count = o.patients.count(1, :conditions =&gt; {:var =&gt; 'blah'})&lt;br/&gt;end &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt; I noticed later that the conditions were being ignored. Odd…&lt;/p&gt;
&lt;p&gt; Here was the problem. I had the attr_accessor class_eval statement before the has_many class_eval. For some reason the order matters. Switching the two made things happy. &lt;/p&gt;</description><link>http://codemonky.com/post/27430234</link><guid>http://codemonky.com/post/27430234</guid><pubDate>Wed, 27 Feb 2008 10:26:00 -0500</pubDate></item><item><title>the original, just for comparison to get some of the scenes from...</title><description>&lt;object width="400" height="336"&gt;&lt;param name="movie" value="http://www.youtube.com/v/jjXyqcx-mYY"&gt;&lt;/param&gt;&lt;param name="wmode" value="transparent"&gt;&lt;/param&gt;&lt;embed src="http://www.youtube.com/v/jjXyqcx-mYY" type="application/x-shockwave-flash" width="400" height="336" wmode="transparent"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;br/&gt;&lt;br/&gt;the original, just for comparison to get some of the scenes from the spoof</description><link>http://codemonky.com/post/26160136</link><guid>http://codemonky.com/post/26160136</guid><pubDate>Tue, 12 Feb 2008 11:30:34 -0500</pubDate></item><item><title>not taking sides and i’m sure most of this is out of...</title><description>&lt;object width="400" height="336"&gt;&lt;param name="movie" value="http://www.youtube.com/v/3gwqEneBKUs"&gt;&lt;/param&gt;&lt;param name="wmode" value="transparent"&gt;&lt;/param&gt;&lt;embed src="http://www.youtube.com/v/3gwqEneBKUs" type="application/x-shockwave-flash" width="400" height="336" wmode="transparent"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;br/&gt;&lt;br/&gt;not taking sides and i’m sure most of this is out of context, but this is pretty funny.</description><link>http://codemonky.com/post/26159354</link><guid>http://codemonky.com/post/26159354</guid><pubDate>Tue, 12 Feb 2008 11:20:10 -0500</pubDate></item><item><title>Why can’t all card readers work this way?</title><description>&lt;img src="http://media.tumblr.com/LdzHTkOYN4oe0gvbviNVHDuR_500.jpg"/&gt;&lt;br/&gt;&lt;br/&gt;Why can’t all card readers work this way?</description><link>http://codemonky.com/post/24742633</link><guid>http://codemonky.com/post/24742633</guid><pubDate>Sat, 26 Jan 2008 18:17:34 -0500</pubDate></item><item><title>what gives? the ical doc icon is a day behind. it updates...</title><description>&lt;img src="http://media.tumblr.com/LdzHTkOYN41949kepPRLKQ58_500.jpg"/&gt;&lt;br/&gt;&lt;br/&gt;what gives? the ical doc icon is a day behind. it updates properly if started. hmmm…</description><link>http://codemonky.com/post/23465773</link><guid>http://codemonky.com/post/23465773</guid><pubDate>Thu, 10 Jan 2008 13:41:51 -0500</pubDate></item><item><title>This makes me feel better about my inability to spell.</title><description>&lt;img src="http://media.tumblr.com/LdzHTkOYN3qyuplr507Q1m6O_500.png"/&gt;&lt;br/&gt;&lt;br/&gt;This makes me feel better about my inability to spell.</description><link>http://codemonky.com/post/22906178</link><guid>http://codemonky.com/post/22906178</guid><pubDate>Thu, 03 Jan 2008 08:56:45 -0500</pubDate></item><item><title>"people who use straws are suckers"</title><description>“people who use straws are suckers”&lt;br/&gt;&lt;br/&gt; - &lt;em&gt;brian&lt;/em&gt;</description><link>http://codemonky.com/post/21052319</link><guid>http://codemonky.com/post/21052319</guid><pubDate>Fri, 07 Dec 2007 11:19:56 -0500</pubDate></item><item><title>in the boss’ office</title><description>&lt;img src="http://media.tumblr.com/LdzHTkOYN2liwxp9feWU7BkD_500.jpg"/&gt;&lt;br/&gt;&lt;br/&gt;in the boss’ office</description><link>http://codemonky.com/post/20889849</link><guid>http://codemonky.com/post/20889849</guid><pubDate>Wed, 05 Dec 2007 08:52:04 -0500</pubDate></item><item><title>Leopard Inconsistent Wireless Speeds</title><description>&lt;a href="http://discussions.apple.com/message.jspa?messageID=5717377#5748265"&gt;Leopard Inconsistent Wireless Speeds&lt;/a&gt;: remove /Library/Preferences/SystemConfiguration/com.apple.airport.preferences.plist and reboot</description><link>http://codemonky.com/post/20784631</link><guid>http://codemonky.com/post/20784631</guid><pubDate>Mon, 03 Dec 2007 23:50:24 -0500</pubDate></item><item><title>Money tree</title><description>&lt;img src="http://media.tumblr.com/LdzHTkOYN2f0afkxKe4qb3bN_500.jpg"/&gt;&lt;br/&gt;&lt;br/&gt;Money tree</description><link>http://codemonky.com/post/20577776</link><guid>http://codemonky.com/post/20577776</guid><pubDate>Fri, 30 Nov 2007 19:24:04 -0500</pubDate></item><item><title>Quicklook and Textmate</title><description>&lt;a href="http://ciaranwal.sh/2007/11/15/quicklook-and-textmate"&gt;Quicklook and Textmate&lt;/a&gt;</description><link>http://codemonky.com/post/20547641</link><guid>http://codemonky.com/post/20547641</guid><pubDate>Fri, 30 Nov 2007 10:18:46 -0500</pubDate></item><item><title>rm_install</title><description>&lt;a href="http://rubyforge.org/frs/?group_id=12"&gt;rm_install&lt;/a&gt;: rumored to work on leopard too. adding here for me to find later if needed.</description><link>http://codemonky.com/post/17549160</link><guid>http://codemonky.com/post/17549160</guid><pubDate>Sun, 28 Oct 2007 15:28:46 -0400</pubDate></item><item><title>Google 411</title><description>&lt;a href="http://www.google.com/goog411/index.html"&gt;Google 411&lt;/a&gt;</description><link>http://codemonky.com/post/16831869</link><guid>http://codemonky.com/post/16831869</guid><pubDate>Tue, 23 Oct 2007 14:51:49 -0400</pubDate></item></channel></rss>
