<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <title>Kopongo - Home</title>
  <id>tag:kopongo.com,2008:mephisto/</id>
  <generator version="0.7.0" uri="http://mephistoblog.com">Mephisto Noh-Varr</generator>
  <link href="http://kopongo.com/feed/atom.xml" rel="self" type="application/atom+xml"/>
  <link href="http://kopongo.com/" rel="alternate" type="text/html"/>
  <updated>2008-08-08T09:14:09Z</updated>
  <entry xml:base="http://kopongo.com/">
    <author>
      <name>daniel</name>
    </author>
    <id>tag:kopongo.com,2008-08-08:9384</id>
    <published>2008-08-08T09:06:00Z</published>
    <updated>2008-08-08T09:14:09Z</updated>
    <link href="http://kopongo.com/2008/8/8/accessing-trac-with-ruby-s-http-library" rel="alternate" type="text/html"/>
    <title>Accessing Trac with Ruby's HTTP  Library</title>
<content type="html">
            &lt;p&gt;I needed to access a Trac repository which was password-protected with &lt;a href='http://en.wikipedia.org/wiki/Basic_authentication'&gt;basic authentication&lt;/a&gt;.
Using ruby's standard &lt;a href='http://www.ruby-doc.org/stdlib/libdoc/net/http/rdoc/index.html'&gt;standard http&lt;/a&gt; libraries, my first try did not work.&lt;/p&gt;

&lt;p&gt;This is what does not work:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;def trac_scraper_that_not_work
    http = Net::HTTP.new('some_trac_hoster.com', 443)
    http.use_ssl = true
    http.start do |http|

      login_location = '/trac/&amp;lt;something&amp;gt;/login'
      req = Net::HTTP::Get.new(login_location)
      req.basic_auth 'username', 'secret'
      response = http.request(req)    
      return nil if response.class == Net::HTTPUnauthorized

      actual_page_to_fetch_url = 'reports/or/whatever...'   
      req = Net::HTTP::Get.new(actual_page_to_fetch_url)
      response = http.request(req)
      #puts &quot;response is #{response.body}&quot;
      response.body
    end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Turns out that Trac uses cookies, so you need to provide the cookie you are given.
First you to provide the authentication using the &lt;code&gt;basic_auth&lt;/code&gt; method, then you copy the cookie
you are given when provide it in the next request. Like this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;def trac_scraper_that_works
    http = Net::HTTP.new('some_trac_hoster.com', 443)
    http.use_ssl = true
    http.start do |http|

      login_location = '/trac/&amp;lt;something&amp;gt;/login'
      req = Net::HTTP::Get.new(login_location)
      req.basic_auth 'username', 'secret'
      response = http.request(req)

      return nil if response.class == Net::HTTPUnauthorized

      cookie = response.response['set-cookie']      
      headers = {
        'Cookie' =&amp;gt; cookie
      }
      actual_page_to_fetch_url = 'reports/or/whatever...'   
      req = Net::HTTP::Get.new(actual_page_to_fetch_url, headers)
      response = http.request(req)
      #puts &quot;response is #{response.body}&quot;
      response.body
    end
end
&lt;/code&gt;&lt;/pre&gt;
          </content>  </entry>
  <entry xml:base="http://kopongo.com/">
    <author>
      <name>daniel</name>
    </author>
    <id>tag:kopongo.com,2008-07-25:7074</id>
    <published>2008-07-25T13:12:00Z</published>
    <updated>2008-07-25T13:24:09Z</updated>
    <link href="http://kopongo.com/2008/7/25/postgres-ri_constrainttrigger-error" rel="alternate" type="text/html"/>
    <title>postgres RI_ConstraintTrigger Error</title>
<content type="html">
            &lt;p&gt;A problem that I recently started running into is a strange Postgres FK constraints error, which
only shows up when running tests. The error looks something like this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;PGError: ERROR:  permission denied: &quot;RI_ConstraintTrigger_XXXXX&quot; is a system trigger
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This is something that came in with FoxyFixtures, and there's a discussion about this problem
and a patch in the &lt;a href='http://dev.rubyonrails.org/ticket/9981'&gt;rails trac&lt;/a&gt;. So what's this about?&lt;/p&gt;

&lt;p&gt;When loading fixtures, rails tries to disable all foreign keys so that there are no problems 
inserting the data in whatever order. 
The calls work like this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;ALTER TABLE table_name DISABLE TRIGGER ALL
insert a bunch of fixtures 
ALTER TABLE table_name ENABLE TRIGGER ALL
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;However, postgres keeps some kind of metadata regarding the FKs to be enforced called 
&lt;code&gt;RI_Constraint_something&lt;/code&gt;. Disabling the triggers on a table causes these to be deleted as well.
The problems is that these other triggers belong to the superuser and not you. So, you got this 
permissions problem. &lt;/p&gt;

&lt;p&gt;You may not have superuser permissions for your postgres instance, but it's probably best that the
database you work with does not have superuser permissions, since that's the way it's going to be in
production.&lt;/p&gt;

&lt;p&gt;One workaround for to disable the foreign key checking in a different way. Instead of running the
DISABLE TRIGGER, you can make the constraints DEFERRED &lt;a href='http://www.postgresql.org/docs/8.2/static/sql-set-constraints.html'&gt;postgres docs&lt;/a&gt;. This way, you run like this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;SET CONSTRAINTS ALL DEFERRED
insert a bunch of fixtures 
SET CONSTRAINTS ALL IMMEDIATE
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This allows you to load your fixtures, but keep all contraint-checking.&lt;/p&gt;

&lt;p&gt;The easiest way to patch this is to override the behavior of the &lt;code&gt;disable_referential_integrity&lt;/code&gt; method.
I created a new file, &lt;code&gt;active_record_fk_hack.rb&lt;/code&gt;, stuck this in there:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;module ActiveRecord
  module ConnectionAdapters
    class PostgreSQLAdapter &amp;lt; AbstractAdapter
      def disable_referential_integrity(&amp;amp;block)
         transaction {
           begin
             execute &quot;SET CONSTRAINTS ALL DEFERRED&quot;
             yield
           ensure
             execute &quot;SET CONSTRAINTS ALL IMMEDIATE&quot;
           end
         }
      end
    end
  end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;then, in your environment.rb, add this at the end:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;require 'active_record_fk_hack'
&lt;/code&gt;&lt;/pre&gt;
          </content>  </entry>
  <entry xml:base="http://kopongo.com/">
    <author>
      <name>daniel</name>
    </author>
    <id>tag:kopongo.com,2008-04-16:434</id>
    <published>2008-04-16T11:11:00Z</published>
    <updated>2008-04-16T11:37:26Z</updated>
    <link href="http://kopongo.com/2008/4/16/query-for-postgres-database-sizes" rel="alternate" type="text/html"/>
    <title>Query for Postgres database sizes</title>
<content type="html">
            &lt;p&gt;If you need to figure out how big your postgres databases are, this query can come
in pretty useful.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;SELECT 
   pg_database.datname,
   pg_size_pretty(pg_database_size(pg_database.datname)) AS size
FROM 
  pg_database                                                                                                                                       
JOIN 
  pg_shadow ON pg_database.datdba = pg_shadow.usesysid                                                                                                     
ORDER BY 
  pg_database_size(pg_database.datname) desc;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;You may need to log in as postgres to get the privilege to look at the pg_shadow tables.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://kopongo.com/">
    <author>
      <name>daniel</name>
    </author>
    <id>tag:kopongo.com,2007-12-09:22</id>
    <published>2007-12-09T21:00:33Z</published>
    <updated>2007-12-09T21:28:32Z</updated>
    <category term="Projects"/>
    <link href="http://kopongo.com/2007/12/9/google-charts-api-rails-plugin" rel="alternate" type="text/html"/>
    <title>Google Charts API rails plugin</title>
<content type="html">
            &lt;p&gt;I bundled the code from the previous post into a plugin, called Chartr. This makes it easy to 
create graphs within rails. &lt;/p&gt;

&lt;p&gt;Here's how to use it.&lt;/p&gt;

&lt;p&gt;First, install the plugin. (It's probably a good idea to install it with '-x' since it's likely
to be updated. Also, I should mention that this is my first plugin.)&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;    ruby script/plugin install -x svn://syvera.com/plugins/chartr
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Right, so now we need to graph something. You can put a graph into any page, but let's create a 
page that definitely deserves a graph: &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;    ruby script/generate controller graphs index
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This gives you an index.html.erb page where you can put your graph. In that page, we're going to use
Chartr to give us a random graph. This is the code:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;    &amp;lt;%= Chartr.make_simple_line_chart Array.new(5) {|i| rand(10)}, 
                                      ['one', 'two', 'three', 'four', 'five'],
                                      'stuff to graph' %&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;So that's going to give you a graph like this:&lt;/p&gt;

&lt;p&gt;&lt;img src='http://chart.apis.google.com/chart?chs=200x100&amp;amp;chd=s:AR0a9&amp;amp;cht=lc&amp;amp;chxt=x,y&amp;amp;chxl=0:|one|two|three|four|five|1:||7' alt='stuff to graph' /&gt;&lt;/p&gt;

&lt;p&gt;Sure, that's cool. But what the heck were those arguments?&lt;/p&gt;

&lt;p&gt;The first one is for your values:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;    Array.new(5) {|i| rand(10)}  # returns an array of 5 random values between 0 and 9
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The second, also an array, is for the legend. No explanation needed for that.
The last is for the html 'alt' tag.&lt;/p&gt;

&lt;p&gt;You could provide a fourth one for the size of the graph. If not, the default is 200x100.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://kopongo.com/">
    <author>
      <name>daniel</name>
    </author>
    <id>tag:kopongo.com,2007-12-07:21</id>
    <published>2007-12-07T22:48:00Z</published>
    <updated>2007-12-09T12:24:22Z</updated>
    <link href="http://kopongo.com/2007/12/7/google-chart-api" rel="alternate" type="text/html"/>
    <title>Google Charts API</title>
<content type="html">
            &lt;p&gt;I just noticed that google has published another cool API, this time for 
&lt;a href='http://code.google.com/apis/chart/'&gt;charts&lt;/a&gt;.
It makes very fine looking charts, and has a simple API. Getting the values into the
chart is very strange at first, but the constraints that you have on the values actually
help in that your chart ends up looking better.&lt;/p&gt;

&lt;p&gt;Here's how to use it. First we need some values to chart. A couple of weeks ago I wrote about
how to extract some data out of subversion and put in into postgres. I still have those values around,
so I for values I can use the number of commits per month in the rails project since it began. 
If you want to know more about that, read &lt;a href='http://kopongo.com/2007/11/25/svn-tricks-and-rails-on-sundays'&gt;svn tricks&lt;/a&gt;.
The strange part, as I mentioned before, is that you don't pass numbers to the chart. 
You pass some kind of encoding which has either 62, 1000, or 4096 values. For many uses,
the first one is good enough. &lt;/p&gt;

&lt;p&gt;Ok, so first we need to generate the encoding for the values.
The Google maps API webpage shows a sample javascript function to generate that. I translated that to ruby. 
I think it's more or less correct, and goes like this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;    def simpleEncode(values, maxValue)
      simpleEncoding = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';

      chartData = ['s:'];
      values.each do |v|
        val = Float(v)
        if (!val.nan? &amp;amp;&amp;amp; v &amp;gt;= 0)   
          chartData.push(simpleEncoding[( (simpleEncoding.length-1) * val / maxValue).round, 1]);
        else
          chartData.push('_');
        end
      end
      return chartData.join('');
    end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Right, so now how do we get our values to this function. As mentioned before, our values would come out of the database like this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;    % psql -d work_activity -t -c &quot;select date_trunc('month', date), count(*) from svn_activity group by 1 order by 1;&quot;
     2004-11-01 00:00:00 |    30
     2004-12-01 00:00:00 |   259
     2005-01-01 00:00:00 |   218
     etc
     ...
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;In order to generate the graph, we need to stuff those values into the funny URL google wants. So we hack a little
chunk of code to parse the stuff.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;    a = STDIN.read
    values = []
    dates = []
    a.each do |line|
      next if line.chomp.length &amp;lt; 1
      date, value = line.split('|')
      value.chomp!; date.chomp! #get rid of all the chars
      values &amp;lt;&amp;lt; value.to_i 
      dates &amp;lt;&amp;lt; date.split[0].split('-')[1] # just take month, legend too busy otherwise
    end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;That gives us two arrays, one with the values, and one with the dates. Notice that I chopped off the year and the day off the dates. Before I did that, the labels on the X axis were so busy with text that you
could not even make sense out of any of them.&lt;/p&gt;

&lt;p&gt;Now that we have our values, we make the img tag with all the funny values in it. We also decide the size of the chart and the 'alt' value here. There are plenty of other things that you can modify, but this does most of what you want:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;    image_str =&amp;lt;&amp;lt;-START
    &amp;lt;img src=&quot;http://chart.apis.google.com/chart?
    chs=500x225
    &amp;amp;amp;chd=#{simpleEncode(values, values.max)}
    &amp;amp;amp;cht=lc
    &amp;amp;amp;chxt=x,y
    &amp;amp;amp;chxl=0:|#{dates.join('|')}|1:||#{values.max}&quot;
    alt=&quot;Rails Subversion Commits&quot; /&amp;gt;
    START
    puts image_str
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now we put all those bits of code above into a single file, and call it make&lt;em&gt;google&lt;/em&gt;url.rb. We run the query as before, and pipe it to our nifty new program like this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;    psql -d work_activity -t -c &quot;select date_trunc('month', date), count(*) from svn_activity group by 1 order by 1&quot;| ruby make_google_url.rb
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This is our result:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;    &amp;lt;img src=&quot;http://chart.apis.google.com/chart?
    chs=500x225
    &amp;amp;amp;chd=s:FummojRe1Lu2vQOd9cLURcmXYRbQSLiUHIxpS
    &amp;amp;amp;cht=lc
    &amp;amp;amp;chxt=x,y
    &amp;amp;amp;chxl=0:|11|12|01|02|03|04|05|06|07|08|09|10|11|12|01|02|03|04|05|06|07|08|09|10|11|12|01|02|03|04|05|06|07|08|09|10|11|1:||347&quot;
    alt=&quot;Rails Subversion Commits&quot; /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And if you put that in your page, it looks like:&lt;/p&gt;

&lt;p&gt;&lt;img src='http://chart.apis.google.com/chart?
chs=500x225
&amp;amp;chd=s:FummojRe1Lu2vQOd9cLURcmXYRbQSLiUHIxpS
&amp;amp;cht=lc
&amp;amp;chxt=x,y
&amp;amp;chxl=0:|11|12|01|02|03|04|05|06|07|08|09|10|11|12|01|02|03|04|05|06|07|08|09|10|11|12|01|02|03|04|05|06|07|08|09|10|11|1:||347' alt='Rails Subversion Commits' /&gt;&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://kopongo.com/">
    <author>
      <name>daniel</name>
    </author>
    <id>tag:kopongo.com,2007-12-02:20</id>
    <published>2007-12-02T13:00:00Z</published>
    <updated>2007-12-02T13:16:00Z</updated>
    <link href="http://kopongo.com/2007/12/2/deploying-with-google-maps-api-keys" rel="alternate" type="text/html"/>
    <title>deploying with google maps API keys</title>
<content type="html">
            &lt;p&gt;If you are using google maps in your apps, you get special key from them that works
for the URL where you want to use the maps (ie www.yoursite.com). Since you
probably test your code on localhost before you deploy it, you have a problem. The key 
they give you only works at that URL. 
What you need to do is get another key that works with your testing on your localhost, 
for example for localhost:3000. &lt;/p&gt;

&lt;p&gt;What this means that when you deploy, you have to switch them. Of course, you do not want
to do this by hand.&lt;/p&gt;

&lt;p&gt;Here's a simple way to do this with capistrano:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;    task :after_update_code, :roles =&amp;gt; [:app, :db, :web] do

       layout_file = File.read('app/views/layouts/standard.rhtml')
       google_map_key = File.read(&quot;config/google_map_key.txt&quot;)
       layout_file.sub!(/file=api&amp;amp;amp;v=2&amp;amp;amp;key=(\w+)/, &quot;file=api&amp;amp;amp;v=2&amp;amp;amp;key=#{google_map_key}&quot;)
       put(layout_file,
           &quot;#{release_path}/app/views/layouts/standard.rhtml&quot;,
           :mode =&amp;gt; 0444)
    end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;So, what's going on?&lt;/p&gt;

&lt;p&gt;First, save the production key on some file, like config/google&lt;em&gt;map&lt;/em&gt;key.txt. Don't think
that is is like saving database passwords in SVN, since this key appears on all your 
webpages anyway.&lt;/p&gt;

&lt;p&gt;I put my key in the site layout I use, standard.rhtml. By default, you want to keep development 
version of the key in there. When we deploy, we read the key from google&lt;em&gt;map&lt;/em&gt;key.txt, use a 
regexp to switch the development key with the production key. Then we send that file over
with the put command.&lt;/p&gt;

&lt;p&gt;You could be more clever by changing the file that's already on the server, instead of changing
the local file and sending it over, but this works well enough.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://kopongo.com/">
    <author>
      <name>daniel</name>
    </author>
    <id>tag:kopongo.com,2007-11-25:19</id>
    <published>2007-11-25T16:00:27Z</published>
    <updated>2007-11-25T16:34:27Z</updated>
    <link href="http://kopongo.com/2007/11/25/svn-tricks-and-rails-on-sundays" rel="alternate" type="text/html"/>
    <title>svn tricks and rails on sundays</title>
<content type="html">
            &lt;p&gt;I've got a few projects that I work on when I get the time. Since I usually work
on all of them at the same time, it seems none of them moves forward very fast. I got
curious to see how much work I am actually doing over time, and came up with a few 
little SVN hacks.&lt;/p&gt;

&lt;p&gt;First, get the svn logs, pipe into a file:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;% cd &amp;lt;head_of_the_svn_tree&amp;gt;
% svn log -q | egrep '^r' &amp;gt; activity.csv
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Right, that gives us a file with all of the project checkins. The 'egrep' part strips out
all of the annoying dashes that come with the svn log. 
The data looks like of like this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;r2 | danielw | 2006-12-20 00:38:13 +0200 (Wed, 20 Dec 2006)
r1 | danielw | 2006-12-20 00:33:41 +0200 (Wed, 20 Dec 2006)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now, with some command-line tricks I can break down the activity a little more:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;% svn log -q | egrep '^r' | cut -d '|' -f 2 | sort | uniq -c | sort -n
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This breaks down the log and counts the number of checkins per person. You can point it
to a URL as well. Results on one of my SVN trees gives something like this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;6  carl 
123  danielw
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;What I am really interested in is how this activity progresses over time. I don't know how
to do this on the command line, but SQL could do this in no time.
We need to create a database and a table to hold the data. In postgres, like this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt; % createdb work_activity
 % psql -d work_activity
 work_activity =&amp;gt; create table svn_activity (revision varchar, who varchar, date timestamp);
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now we need to populate this with data. Since the end of that SVN line has got some funny 
timestamps, we'll get AWK to strip that out for us. Also, since the standard postgres column
delimiter is the tab (\t), we'll delimit our records like that. Also, let's use the rails project to 
get more interesting stats. &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;% svn log -q http://svn.rubyonrails.org/rails/trunk &amp;gt; activity_rails.txt
% cat activity_rails.txt | egrep '^r' | awk '{print $1&quot;\t&quot;$3&quot;\t&quot;$5}' &amp;gt; activity_rails.data
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This puts all of the data into a file, which we can  now load into the DB in a single easy command:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;% psql -d work_activity -c 'COPY svn_activity FROM STDIN' &amp;lt; activity_rails.data
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now it's all in the database, and we can do loads of fancy queries on it:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;% psql -d work_activity -c &quot;select date_trunc('month', date), count(*) from svn_activity group by 1 order by 1;&quot;

     date_trunc      | count 
---------------------+-------
 2004-11-01 00:00:00 |    30
 2004-12-01 00:00:00 |   259
 2005-01-01 00:00:00 |   218
 2005-02-01 00:00:00 |   219
 2005-03-01 00:00:00 |   227
 2005-04-01 00:00:00 |   199
 2005-05-01 00:00:00 |    99
 2005-06-01 00:00:00 |   172
 2005-07-01 00:00:00 |   304
 2005-08-01 00:00:00 |    63
 2005-09-01 00:00:00 |   263
 2005-10-01 00:00:00 |   306
 2005-11-01 00:00:00 |   265
 2005-12-01 00:00:00 |    93
 2006-01-01 00:00:00 |    79
 2006-02-01 00:00:00 |   163
 2006-03-01 00:00:00 |   347
 2006-04-01 00:00:00 |   162
 2006-05-01 00:00:00 |    60
 2006-06-01 00:00:00 |   116
 2006-07-01 00:00:00 |    96
 2006-08-01 00:00:00 |   162
 2006-09-01 00:00:00 |   216
 2006-10-01 00:00:00 |   130
 2006-11-01 00:00:00 |   139
 2006-12-01 00:00:00 |    97
 2007-01-01 00:00:00 |   155
 2007-02-01 00:00:00 |    92
 2007-03-01 00:00:00 |   101
 2007-04-01 00:00:00 |    65
 2007-05-01 00:00:00 |   192
 2007-06-01 00:00:00 |   115
 2007-07-01 00:00:00 |    39
 2007-08-01 00:00:00 |    43
 2007-09-01 00:00:00 |   278
 2007-10-01 00:00:00 |   236
 2007-11-01 00:00:00 |   105
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Looks like a very healthy project. Ok, let's find out on what day of the week rails developers have been most prolific:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;psql -d work_activity -c &quot;select extract(dow from date) as day, count(*) from svn_activity group by 1 order by 1;&quot;  

 day | count 
-----+-------
   0 |  1040
   1 |   969
   2 |   874
   3 |   755
   4 |   790
   5 |   688
   6 |   789
(7 rows)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Day 0 is sunday! Thanks for the hard work, guys.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://kopongo.com/">
    <author>
      <name>daniel</name>
    </author>
    <id>tag:kopongo.com,2007-11-13:17</id>
    <published>2007-11-13T13:23:00Z</published>
    <updated>2007-11-13T13:22:48Z</updated>
    <link href="http://kopongo.com/2007/11/13/useful-capistrano-trick" rel="alternate" type="text/html"/>
    <title>Useful Capistrano tricks</title>
<content type="html">
            &lt;p&gt;I just ran into a neat little capistrano trick. 
I have been making some changes to an app, and knew it had been a while since I had made a
release to one of the apps I am working on. But which version do I have installed?&lt;/p&gt;

&lt;p&gt;I tried the &lt;code&gt;cap diff_from_last_deploy&lt;/code&gt;, but it was a little too much information.
I ran into capistrano's stream command, and that proved to be just right:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;    desc &quot;Find out svn version on server&quot;
    task :what_version, :roles =&amp;gt; [:app] do
        stream &amp;lt;&amp;lt;-CMD
            svn info #{current_path}/app
        CMD
    end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;It's also useful for those one-off commands you might want to run on your server, like seeing
how many users registered at your site:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;    desc &quot;Find out how many users are registered&quot;
    task :how_many_users, :roles =&amp;gt; [:app] do
        stream &amp;lt;&amp;lt;-CMD
            psql -U user -d yourapp_production -c 'select count(login) from users'
        CMD
    end
&lt;/code&gt;&lt;/pre&gt;
          </content>  </entry>
  <entry xml:base="http://kopongo.com/">
    <author>
      <name>daniel</name>
    </author>
    <id>tag:kopongo.com,2007-11-04:16</id>
    <published>2007-11-04T16:23:21Z</published>
    <updated>2007-11-04T16:27:08Z</updated>
    <link href="http://kopongo.com/2007/11/4/inflector_problems" rel="alternate" type="text/html"/>
    <title>Rails Inflector problems</title>
<content type="html">
            &lt;p&gt;I knew that the rails pluralization did some cool fancy stuff, but never really had to mess with it until today. I was trying to duplicate some bug I ran into, so I created a brand new rails app to recreate the bug in there. I had to create some model, so created  &quot;Dive&quot;, and did the whole scaffold thing that goes along with it.&lt;/p&gt;

&lt;p&gt;I ran the tests, and they then started to complain about &quot;Dife&quot; not being found.&lt;/p&gt;

&lt;p&gt;Curious, I went to the console:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;    % &quot;dives&quot;.singularize   # =&amp;gt; dife
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Huh? What's a 'dife'? Even dictionary.com does not even know what a 'dife' is! No matter, I knew that you could fix this up in the environment.rb file. I went in there and uncommented that default block in there, and added my little contribution to rails' knowledge of the english language.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;     Inflector.inflections do |inflect|
        inflect.singular /dives/i, 'dive'
     end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;I then ran the console again, just to make sure. First thing I see are all these errors on the command line:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;    ./script/../config/../config/environment.rb:55:NameError: uninitialized constant Inflector
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.5/lib/action_controller/assertions/selector_assertions.rb:525:NoMethodError:      undefined method `camelize' for &quot;top&quot;:String
    ..../app/controllers/application.rb:4:NameError: uninitialized constant ActionController::Base
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;On the prompt, I try the 'dives'.singularize again, but only get an error.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;    &amp;gt;&amp;gt; &quot;dives&quot;.singularize
    NoMethod Error: undefined method `singularize' for &quot;dives&quot;:String
      from (irb):2
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;I look in the awdwr book and some other places, and find that what I added really does seem to be correct. 
A little googling on the error finally takes me to &lt;a href='http://net3x.blogspot.com/2007/10/inflectorenvironmentrb-bug-in-rails.html' title='someone else'&gt;someone else&lt;/a&gt; that ran into the same problem. &lt;/p&gt;

&lt;p&gt;It's really simple. The Inflector block needs to be &lt;em&gt;outside&lt;/em&gt; the whole 'Rails::Initializer.run' block, 
not inside. Once you move it to the right place, you get what you expect:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;    &amp;gt;&amp;gt; &quot;dive&quot;.pluralize
    =&amp;gt; &quot;dives&quot;
    &amp;gt;&amp;gt; &quot;dives&quot;.singularize
    =&amp;gt; &quot;dive&quot;
&lt;/code&gt;&lt;/pre&gt;
          </content>  </entry>
  <entry xml:base="http://kopongo.com/">
    <author>
      <name>daniel</name>
    </author>
    <id>tag:kopongo.com,2007-10-30:15</id>
    <published>2007-10-30T15:25:00Z</published>
    <updated>2007-10-30T15:34:08Z</updated>
    <link href="http://kopongo.com/2007/10/30/rails-2-0-0_pr-and-globalize-breakage" rel="alternate" type="text/html"/>
    <title>Rails 2.0.0_PR and Globalize breakage</title>
<content type="html">
            &lt;p&gt;My functional tests broke when I went to Rails 2.0. It took a while to grok the
stack trace:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;ArgumentError: wrong number of arguments (2 for 1)
..../vendor/rails/activerecord/lib/active_record/base.rb:1965:in `attributes_with_quotes'
    ..../vendor/rails/activerecord/lib/active_record/base.rb:1965:in `update_without_lock'
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Turns out the problem was that in Rails 2.0, ActiveRecord's 'attributes&lt;em&gt;with&lt;/em&gt;quotes' method now takes 
2 arguments instead of a single one. 
The problem is that globalize overrides this method in the db_translate.rb, so things break.  &lt;/p&gt;

&lt;p&gt;It's easy to fix, though. Adding the extra argument to globalize's db_translate.rb seems to do fix what hurts.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://kopongo.com/">
    <author>
      <name>daniel</name>
    </author>
    <id>tag:kopongo.com,2007-10-18:14</id>
    <published>2007-10-18T14:45:00Z</published>
    <updated>2007-10-18T15:06:21Z</updated>
    <link href="http://kopongo.com/2007/10/18/basic-plugins" rel="alternate" type="text/html"/>
    <title>basic plugins</title>
<content type="html">
            &lt;p&gt;Some plugins are plain good. I tend to forget where they are, and then have to go around hunting for
them again.
Here's so that I don't have to hunt around for these next time.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;    ruby script/plugin install exception_notification
    ruby script/plugin install tztime
    ruby script/plugin install tzinfo_timezone
    ruby script/plugin install http://svn.techno-weenie.net/projects/plugins/restful_authentication/
    ruby script/plugin install http://svn.pragprog.com/Public/plugins/annotate_models
    ruby script/plugin install svn://errtheblog.com/svn/plugins/will_paginate
    ruby script/plugin install svn://caboo.se/plugins/court3nay/spider_test
    ruby script/plugin install http://terralien.com/svn/projects/plugins/query_trace/
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Also&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;    svn propset svn:ignore &quot;*.log&quot; log/
    svn propset svn:ignore &quot;ruby_sess*&quot; tmp/sessions/   
    svn propset svn:ignore &quot;*&quot; tmp/pids/
    svn propset svn:ignore &quot;*&quot; tmp/cache/
    svn propset svn:ignore &quot;*&quot; tmp/sockets/
&lt;/code&gt;&lt;/pre&gt;
          </content>  </entry>
  <entry xml:base="http://kopongo.com/">
    <author>
      <name>daniel</name>
    </author>
    <id>tag:kopongo.com,2007-07-17:13</id>
    <published>2007-07-17T15:07:00Z</published>
    <updated>2007-07-17T17:54:51Z</updated>
    <link href="http://kopongo.com/2007/7/17/learning-javascript" rel="alternate" type="text/html"/>
    <title>Learning Javascript</title>
<content type="html">
            &lt;p&gt;I have avoided javascript for a while, but finally decided to find out a little more about it.
A few videos out there made the process painless.&lt;/p&gt;

&lt;p&gt;First, Douglas Crockford's excellent &lt;a href='http://video.yahoo.com/?t=t&amp;amp;p=douglascrockford'&gt;presentations&lt;/a&gt;.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Basic Javascript Part (split into 4 parts)&lt;/li&gt;
&lt;li&gt;Theory of the DOM (split into 3)&lt;/li&gt;
&lt;li&gt;Advanced Javascripts (split into 3)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;After this, I felt I had inkling of what the language was about. Still
not sure how I would write a large chunk of code with it, but it's good to know what's going
on. He's got some more videos which I will try to come back to, but at this point I want to 
move on to apply some of this stuff.&lt;/p&gt;

&lt;p&gt;What I really wanted was to be able to use some of these new javascript libraries like
Prototype, but I did not want to start blindly using then without knowing a little about
what was going on in the background.&lt;/p&gt;

&lt;p&gt;A good introduction to those libraries is Peepcode's Prototype &lt;a href='http://peepcode.com/products/javascript-with-prototypejs'&gt;video&lt;/a&gt;. It costs money, but
it's certainly worth it.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://kopongo.com/">
    <author>
      <name>daniel</name>
    </author>
    <id>tag:kopongo.com,2007-07-11:12</id>
    <published>2007-07-11T16:22:00Z</published>
    <updated>2007-07-17T14:56:55Z</updated>
    <link href="http://kopongo.com/2007/7/11/moving-to-rails-edge" rel="alternate" type="text/html"/>
    <title>Moving from rails 1.2.3 to rails edge</title>
<content type="html">
            &lt;p&gt;Moving to edge broke a bunch of stuff, especially a bunch of that code that I had managed
to completely forget about.&lt;/p&gt;

&lt;p&gt;It's like this. You've been rolling along fine on 1.2.3, and, for some reason, you go to the edge release.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;       % rake rails:freeze:edge
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Some stuff will break. So, here's what's going out, and how to replace it:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Un-initialized active_resource&lt;/p&gt;

&lt;p&gt;This one might  happen early. The symptom:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;% ruby script/server
   Exiting
   /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/servers/mongrel.rb:15: warning: already initialized constant OPTIONS
   /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/servers/mongrel.rb:18: undefined method `options' for []:Array (NoMethodError)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Weird. Something with mongrel? Let's try webrick:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;% ruby script/server webrick
  =&amp;gt; Booting WEBrick...
   /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/servers/webrick.rb:11: warning: already initialized constant OPTIONS
   /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require': no such file to load -- active_resource (MissingSourceFile)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This seems to be because the original &lt;code&gt;rake rails:freeze:edge&lt;/code&gt; done forgot to bring the activeresource library into the mix. The fix is quick:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;  % svn export http://dev.rubyonrails.org/svn/rails/trunk/activeresource vendor/rails/activeresource
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Cookies needed some new password. &lt;/p&gt;

&lt;p&gt;What is this? Turns out all you need to do for this is to add a little &lt;a href='http://caboo.se/doc/classes/CGI/Session/CookieStore.html'&gt;config&lt;/a&gt; item to 
the environment.rb
Like this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;config.action_controller.session = {:session_key =&amp;gt; &quot;_myapp_session&quot;, :secret =&amp;gt; 'this_can_be_long'}
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;pagination&lt;/p&gt;

&lt;p&gt;Remember all that code the scaffolding used to spit out. Some of it, including the pagination,
is still sitting around in a lot of places. It seems that pagination got a &lt;a href='http://glu.ttono.us/articles/2006/08/30/guide-things-you-shouldnt-be-doing-in-rails'&gt;bad rap&lt;/a&gt; in the 
meantime, and it has now been taken out of edge.
So, how do you replace them? The &lt;a href='http://rubyonrails.org/deprecation'&gt;rails deprecations&lt;/a&gt; page is not exactly very helpful. &lt;/p&gt;

&lt;p&gt;Well, quite a few choices are around. Quite a few people seem to have stepped in to provide this 
lost functionality, and it's a matter of choosing the plugin.
One is &lt;code&gt;[will_paginate]&lt;/code&gt;[will&lt;em&gt;paginate], another is &lt;a href='http://svn.cardboardrocket.com/paginating_find'&gt;paginating&lt;/em&gt;find&lt;/a&gt;, and yet another is the &lt;a href='http://codefluency.com/2006/10/24/paginator-released' title='Paginator'&gt;paginator&lt;/a&gt; gem.&lt;/p&gt;

&lt;p&gt;I did not have the time to test them all out (trying to move on, you know?), so I looked through 
a couple &lt;a href='http://www.igvita.com/blog/2006/09/10/faster-pagination-in-rails/'&gt;articles&lt;/a&gt; and &lt;a href='http://groups.google.com/group/rubyonrails-core/browse_thread/thread/464421adcc6e96/bba4cf81315657c8'&gt;discussions&lt;/a&gt;, and picked the will_paginate. Hardly any changes needed, and 
seems to work fine. Nice work. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Webservices&lt;/p&gt;

&lt;p&gt;Yep, webservices are still around, but edge is not all that interested in loading them.
The initialization failed. Looking in the code, the webservices were not even in the rake:freeze list .&lt;/p&gt;

&lt;p&gt;Ok, so do it manually: &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;svn export http://dev.rubyonrails.org/svn/rails/trunk/actionwebservice/ vendor/rails/actionwebservice -r7144
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Try again: nothing.
Fine, google the thing. Looks like someone &lt;a href='http://fiatdev.com/2007/5/31/making-actionwebservice-work-with-edge-rails'&gt;ran into this problem&lt;/a&gt;. He's got the fix all documented there.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;push_with_attributes&lt;/code&gt; changes&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;push_with_attributes&lt;/code&gt; call is out. If you have a join table with any extra non-joining columns in it (and therefore not a 'pure' join), you cannot use the &lt;code&gt;push_with_attributes&lt;/code&gt; call to save those values anymore. &lt;/p&gt;

&lt;p&gt;saving objects:&lt;/p&gt;

&lt;p&gt;Something that used to work in 1.2.3 was this:
let's say you have you have some golf website, where you are keeping track of how far a
player hits a ball with a given club.&lt;/p&gt;

&lt;p&gt;Your database would be setup something like this: table &lt;code&gt;player&lt;/code&gt; (id, name), table &lt;code&gt;clubs&lt;/code&gt; (id, name), and finally table &lt;code&gt;player_club_performance&lt;/code&gt; (id, player&lt;em&gt;id, club&lt;/em&gt;id, distance) to tie them together.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;player = Player.new(:name =&amp;gt; 'Tiger')
player.club_performance.create(:club_id =&amp;gt; 7, :distance =&amp;gt; 190)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This seems to save the record (the &lt;code&gt;player_club_performance&lt;/code&gt; row) immediately. Since player has not yet been saved, it 
does not have an id, assigned to it. Therefore, if you have any db constraints on that table, something like &lt;code&gt;club_id not null&lt;/code&gt; (you should, it's safer that way), this will crash.&lt;/p&gt;

&lt;p&gt;If you use method &lt;code&gt;build&lt;/code&gt; instead, it just creates the object. When you call &lt;code&gt;p.save&lt;/code&gt; (the player), it will save the other associated objects as well.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;player = Player.new(:name =&amp;gt; 'Me')
player.club_performace.build(:club_id =&amp;gt; 7, :distance =&amp;gt; 300)
player.save # saves player and club_performance
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Sessions&lt;/p&gt;

&lt;p&gt;Don't know what happened to this one. I have always used the default file session, but this broke.
First, I never noticed any files getting generated in the tmp/sessions directory. Second, on some
actions where a bunch of stuff is saved in the session, I would get this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;[2007-07-06 16:50:13] FATAL  DISPATCHER FAILSAFE RESPONSE (has cgi) Fri Jul 06 16:50:13 +0000 2007
Status: 500 Internal Server Error
     CGI::Session::CookieStore::CookieOverflow             
       .../vendor/rails/actionpack/lib/action_controller/session/cookie_store.rb:91:in 'close'
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This one might be a bug in the edge. I tried setting it to &lt;code&gt;CGI::Session::PStore&lt;/code&gt; (as per AWDWR 2, pg 440), but it seemed
not to know what that was. It seems defined in the vendor/rails/actionpack/lib/action&lt;em&gt;controller/cgi&lt;/em&gt;ext/session.rb,
but did not pick it up. I looked around at the loading/initialization of this for a bit, the just switched to 
the database session, which worked fine the first time.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Other random stuff&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;assert_invalid_column_on_record&lt;/code&gt;
Let's say that your Person model validates age, and says it's got to be a number or less than 1000 or something.
It used to be okay to do something like this in a test&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;  post :create, :person =&amp;gt; { :name =&amp;gt; &quot;elvis&quot;, age: =&amp;gt; &quot;10000&quot;}
  assert_invalid_column_on_record &quot;person&quot;, &quot;age&quot;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;That assert is out. The new way to do it is:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt; post :create, :person =&amp;gt; { :name =&amp;gt; &quot;elvis&quot;, age: =&amp;gt; &quot;asdfg&quot;}
 assert(assigns(:person).errors.invalid?('age'))
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;/ol&gt;
          </content>  </entry>
  <entry xml:base="http://kopongo.com/">
    <author>
      <name>daniel</name>
    </author>
    <id>tag:kopongo.com,2007-03-16:10</id>
    <published>2007-03-16T20:35:00Z</published>
    <updated>2007-07-01T23:13:09Z</updated>
    <link href="http://kopongo.com/2007/3/16/cleaning-up-postgres" rel="alternate" type="text/html"/>
    <title>Cleaning up postgres</title>
<content type="html">
            &lt;p&gt;When you use postgres, every now and then, you need to clean out your database.
Of course, as the project moves on, the tables that you need to clean change as well: some
get added, some dropped. And then there's the indexes.&lt;/p&gt;

&lt;p&gt;I usually do not get around to updating the cleaning scripts unless I notice something
is wrong with the database, and then I have to deal with figuring out all the new
tables and such.&lt;/p&gt;

&lt;p&gt;This can be a lot simpler if you use the postgres metadata tables.
The 'information_schema.tables' table has the list of all tables for a specific database. You can therefore
get a list of tables with a simple:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;    select
        table_name 
    from 
        INFORMATION_SCHEMA.TABLES 
    where 
         table_schema = 'public'
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This gives you the list of tables, like this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;      table_name           
      -------------------------------
      first_table
      second_table 
      (2 rows)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;So how do you get the VACUUM?&lt;/p&gt;

&lt;p&gt;Change the select to this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;    select 
         'VACUUM ANALYZE VERBOSE ' || table_name || ';' 
    from 
         INFORMATION_SCHEMA.TABLES 
    where 
        table_schema = 'public'
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The '||' does string concatenation in SQL. Not the quite the most obvious thing, but what are you gonna do?&lt;/p&gt;

&lt;p&gt;So this that last command gives you this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;    ?column?                        
    -------------------------------------------------------
    VACUUM ANALYZE VERBOSE first_table;
    VACUUM ANALYZE VERBOSE second_table;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;So now you can try this one by hand, or put it in a cron job somewhere...&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;    % psql -d mydb_production -f sql_script.sql -o vacuuum_tables.sql
    % psql -d mydb_production -f vacuum_tables.sql
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;I also like to recompute my indexes after I vacuum. I add this to the first cleaning script,
a simple thing like so:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;     select 
         'REINDEX INDEX ' || indexname || ';' 
     from 
         pg_indexes 
     where 
         schemaname ='public';
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now you get freshly computed indexes every time you run this. Nice! &lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://kopongo.com/">
    <author>
      <name>daniel</name>
    </author>
    <id>tag:kopongo.com,2006-12-30:7</id>
    <published>2006-12-30T12:36:00Z</published>
    <updated>2007-01-01T12:41:15Z</updated>
    <link href="http://kopongo.com/2006/12/30/imagemagick-rmagick-bus-error" rel="alternate" type="text/html"/>
    <title>ImageMagick RMagick Bus Error</title>
<content type="html">
            &lt;p&gt;Installing software on the mac again. This one was not fun, but it did work out fine.&lt;/p&gt;

&lt;p&gt;One of my projects uses the very cool RMagick gem, which requires ImageMagick or GraphMagick to be installed.  This has always been a step I dread, ever since I unsuccessfully tried to install that whose thing on cygwin a year ago despite much effort.
I have since installed all this on various linux boxes, and it&#8217;s usually quite simple. &lt;/p&gt;

&lt;p&gt;Not on the Mac.&lt;/p&gt;

&lt;p&gt;I first followed the very clear instructions I found at Hivelogic  http://hivelogic.com/articles/2006/06/10/rmagick_os_x. &lt;/p&gt;

&lt;p&gt;Unfortunately, that did not work. The RMagick gem did not install properly, and I got the now infamous bus error. Something about misc.rb, line 317.&lt;/p&gt;

&lt;p&gt;I found some hints here http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/216875, 
and tried to install RMagick from source. No good. Same issue.&lt;/p&gt;

&lt;p&gt;Then I tried looking around the web, and found many people asking the same questions. 
Going down further on the google list of issues for this, I started finding articles telling me to use GraphicsMagick.
http://poocs.net/2005/7/6/making-rmagick-suck-less-with-tiger&lt;/p&gt;

&lt;p&gt;Often the solution was something like &#8216;use graphmagick instead&#8217;. Fine, I am sure that would work, but my Linux production servers are setup with ImageMagick. Do I want to use different  software in development than I use in production? No way.  This &lt;em&gt;has&lt;/em&gt; to compile.&lt;/p&gt;

&lt;p&gt;I tried to figure out exactly what was going on in this line 317 which was such a problem. Who was not cooperating? &lt;/p&gt;

&lt;p&gt;I wondered why hivelogic&#8217;s instruction did not quite match up with the compilation instructions at the RMagick site. Finally, I found this: http://blog.labratz.net/articles/2006/10/10/really-truly-getting-imagemagick-rmagick-working-on-osx-from-source-without-using-macports-darwinports-or-fink
I
t&#8217;s basically the hivelogic instruction plus the wmf and lcms libraries, and ImageMagick compiled with the instructions at the RMagick site. I added the ghostscript and the fonts as well.&lt;/p&gt;

&lt;p&gt;And it works great!&lt;/p&gt;
          </content>  </entry>
</feed>
