Howto Expire ActiveRecordStore Sessions 2

Posted by ryan
at 10:17 AM on Wednesday, December 21, 2005



Here’s a little tid bit that most will already know, yet is somewhat elusive on a Google search: How to expire old sessions in Rails when you’re using the CGI::Session::ActiveRecordStore session manager?

Doing so is as easy as setting up the following command to run in crontab using the rails provided script/runner:

/usr/bin/ruby /path/to/rails/proj/script/runner
  -e production
  "CGI::Session::ActiveRecordStore::Session.find(:all,
      :conditions => \"updated_at <
        (current_timestamp - interval '1 week')\" 
   ).each do |session|
     session.destroy
   end" 

The above code will find all session overs a week old and delete them. Rails’ script/runner utility loads your whole environment for you, so you have access to all your models if you need to do more complex logic that what I’ve shown above. You can also string that whole command on the same line, I’ve just formatted it to make it easy to follow for you dense folks out there (of which I consider myself one). One other note, the above is for postgresql – I believe to do the same for mysql you will need to use this command:

/usr/bin/ruby /path/to/rails/proj/script/runner
  -e production
  "CGI::Session::ActiveRecordStore::Session.find(:all,
      :conditions => \"date_sub(curdate(), interval 7 day)
        > updated_at\" 
   ).each do |session|
     session.destroy
   end" 

Useful command to find conflicting Java classes

Posted by ryan
at 9:19 PM on Thursday, December 08, 2005



I had the need awhile ago to find if any jar files in my app included the same class files. On *nix you can do it using this command (which will recursively search all jars in the current directory and compare them to jars in the otherDir directory:

find ./ -name "*.jar" -type f -print | xargs -i -t jar -tf {} |
   grep .class | xargs -i -t grep {} ../<i>otherDir</i>/*.jar |
   grep matches > matches.txt

I’m sure there’s a slicker way of doing it, but it worked for me…

CDBaby Firefox search engine extension 1

Posted by ryan
at 12:04 PM on Thursday, December 08, 2005



Reading about CDBaby’s impending conversion to Rails jogged my memory of something I’ve been meaning to do for awhile, make a CDBaby Firefox search extension. So, here it is:

My CDBaby Firefox search engine extension

Whenever I hear about new music I want to try I always do a search on CDBaby.com first, then go onto more commercial ways of acquiring the music if CDBaby doesn’t have it. Hopefully this will make that process one step cleaner.

Let me know if you have comments, problems or feedback.