So far, it\’s RoR

Ruby on Rails, PostgreSQL, SVN, etc….

Archive for the ‘Uncategorized’ Category

Moved to http://www.question-defense.com

Posted by Chirag Patel on February 11, 2009

I’ve deciced to join forces with http://www.question-defense.com but will keep this blog up so I don’t break any links. All the posts in this blog have been copied to http://www.question-defense.com

Advertisements

Posted in Uncategorized | Leave a Comment »

Rails log analyzers

Posted by Chirag Patel on October 15, 2008

Here are the ones I tried. Hope the comments aren’t too confusing

  1. Simple Rails Log Query Analyzer
    • Ran ruby bin/query_log_analyzer.rb ../log/production.log
      • production.log.1 (small log file ~25MB) Just printed the “Totals” heading with no results
      • production.log (large log file ~400MB) Ran for a long time and nothing happened
  2. The Action Profiler lets you profile actions to determine points of optimization.
    • See attachment for the error when running action_profiler ChartController#index
    • Madhu thinks it requires Production Log Analyzer (which requires SyslogLogger)
  3. rawk.rb
    (recommended by Railscast.com)

    • production.log.1 (small log file ~25MB) shows 21,300 requests

    • production.log (large log file ~400MB) —shows only 27,200 requests
    • Both took about a miute to scan and since only 7,000 difference in requests, we think Rawk is not working
    • 07/23/08: Tried ruby rawk.rb ../log/production.log on sdev but hung for long time and never returned
  4. Hodel3000CompliantLogger
    • Looks like it’s working but requires mongrel_rails start instead of ruby script/server. Cannot use it easily with Litespeed probably.
    • Uses Production Log Analyzer but circumvents SyslogLogger (unlke Action Profiler above)
  5. Railscast.com’s Request Profiling

Posted in Uncategorized | 2 Comments »

View for version numbers, host names, IPs, etc

Posted by Chirag Patel on July 26, 2008

Here’s some code (and rendered view) for various version numbers, host names, IPs for Ruby, Rails, PostgreSQL, SMTP.


<b>Network</b><br>
UNIX hostname: <code><%= `hostname` %></code><br>
SERVER_ADDR: <code><%= request.env[“SERVER_ADDR”].to_s %></code> <br>
HOST_NAME : <code><%= request.host %></code> <br>
REMOTE_ADDR: <code><%= request.env[“REMOTE_ADDR”].to_s %></code> <br>
<br>
<b>Software</b><br>
Database: <code><%= ActiveRecord::Base.connection.select_value(“SELECT  VERSION()”) %></code><br>
Email delivery method: <code><%= ActionMailer::Base.delivery_method %></code><br>
SMTP server: <code> <%= ActionMailer::Base.smtp_settings[:address] %></code><br>
Ruby: <code> <%= “#{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) on #{RUBY_PLATFORM}” %> </code><br>
Rails: <code> <%= “#{Rails::VERSION::STRING}” %> </code><br>

Network
UNIX hostname: server1.mydomain.com
SERVER_ADDR: 10.2.128.100
HOST_NAME : http://www.mydomain.com
REMOTE_ADDR: 12.207.103.224

Software
Database: PostgreSQL 8.3.3 on x86_64-redhat-linux-gnu, compiled by GCC gcc (GCC) 4.1.2 20070626 (Red Hat 4.1.2-14)
Email delivery method: activerecord
SMTP server: localhost
Ruby: 1.8.6 (2007-03-13) on x86_64-linux
Rails: 2.1.0

Posted in Uncategorized | Leave a Comment »

Using helpers in models, views, and controllers

Posted by Chirag Patel on July 8, 2008

Using this as a guide JLHPBv2: Using Helpers in Models in Rails, you can make a single Module that can be accessed from models, views, and controllers. The helpers automatically created in app/helpers/*_helpers.rb   might also be available anywhere as long as you include them.

I decided to make the methods in the helper class-scoped (using self below) so that the origin of the helper method is explicitly obvious in the call (eg. to_s below)

app/lib/utility_helper.rb
module UtilityHelper
  def self.camelcase_to_spaced(word)
    word.gsub(/([A-Z])/, " \\1").strip
  end
end

app/models/event.rb
class Event < ActiveRecord::Base
  include UtilityHelper
 
  def to_s
    UtilityHelper.camelcase_to_spaced("This an Event object")
  end
end

app/helpers/events_helper.rb
module EventsHelper
  include UtilityHelper
end

app/controllers/event_controller.rb
class EventController < ApplicationController
  include UtilityHelper
end


app/views/events/index.html.erb
<%=UtilityHelper.camelcase_to_spaced(event[:event_type])%&rt;

Posted in Ruby on Rails, Uncategorized | 2 Comments »