Feed on
Posts
Comments

Category Archive for 'ruby'

nested error_messages_for

I think lots of folks have run into this problem of using error_messages_for to display errors of nested or subordinate objects. The current Rails method doesn't handle it well. In addition, there's the problem of not being able to specify the full message. So... I tackled this problem today and came up [...]

Read Full Post »

Extending ActiveRecord with count_since

I just implemented a statistics page for an application and found that I was using this pattern over and over again:

User.count(:conditions => ['created_at> ?', 30.days.ago])

Here's a simple extension I made to ActiveRecord to DRY it up:

module ActiveRecord
  class Base
      def self.count_since(time_ago)
        count(:conditions => ['created_at> ?', time_ago])
      end
  end
end

Put [...]

Read Full Post »

Autotest CPU Fix

Update 1/15/2008
Autotest and rspec both posted updates today. Now, the way to fix this issue is slightly different:

Autotest.add_hook :run do |autotest|
  autotest.add_exception(/^\.\/vendor/)
  autotest.add_exception(/\.svn/)
end

Thanks Ryan and David for the updates!

I've been noticing in my current project that running autotest was constantly consuming about 25-30% of my cpu and causing my macbook pro to run really [...]

Read Full Post »

acts_as_amazon_product

Today we released a new Ruby Gem that makes integrating with Amazon E-Commerce Service (ECS) a snap. It's called acts_as_amazon_product and you can find it on RubyForge.
All that's necessary to integrate any of your existing models with Amazon is to add a require line to the top of your model file and then an [...]

Read Full Post »

Apache Log Quick Summary

Sometimes I set up a quick site for a client and want to summarize hits without setting up awstats. So, I wrote a quick and dirty script to sum up the hits per day in Apache's access_log file.
Example:
$ cklog access_log
04-15-2007: 21
04-16-2007: 2134
04-17-2007: 304
04-18-2007: 6960
04-19-2007: 951
04-20-2007: 412
Here's the script:

require 'date'
daily = Hash.new
File.open(ARGV[0] || "access_log", "r") [...]

Read Full Post »

Ruby Web Crawler

Here's a web crawler I wrote awhile back. It's pretty simple, but does the job. If you need something more, you might try rdig or Nutch.
You can run this as a stand-alone script and just pass in the URL to crawl as an argument.

require 'net/http'
require 'uri'
class SiteCrawler
  def initialize(url)
    @site_uri = URI.parse(url)
  [...]

Read Full Post »

I've been working with soap4r in Ruby to access some Java web services which use AXIS 1.1. The particular api I'm accessing requires an initial authentication call which returns a token that must be passed in all subsequent SOAP headers. This is a pretty common scenario, but it took me awhile to get [...]

Read Full Post »

Geocoding webservice with Ruby and Perl

A year or so ago I was trying out the Google Maps API. At the time, Google did not provide a means to geocode your own locations (although now they do), so I set out to create my own geocoder. There was a good overview on how to create your own database of [...]

Read Full Post »