Satya's blog - 2009/05/

May 09 2009 11:44 Ruby on Rails auto_link bug

In Ruby on Rails, the auto_link helper takes a string and automatically links URLs and email addresses in the string, producing output suitable for a web page. Today we had a URL that ended in a query string, with a slash in the string, like so: .../end?tag=/mom

auto_link wouldn't recognize the slash as part of the link and ended the link at the "tag=" part. After some googling, I located action_view/helpers/text_helper.rb and added the slash before the dash in the regexp for the query string. This is in a constant called AUTO_LINK_RE.

Update: Swivel blog has a better way to fix this, with an initializer.

Last updated: Jun 04 2009 15:58

Tag: rails geeky

May 15 2009 19:50 Pidgin logs archiver

I wrote a little script to archive my pidgin logs in a sepaarte directory. 4 lines, but took 45 minutes to write. Use at own risk. This should be under the Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License. But should this script do anything, or not do something, don't hold me responsible. In fact, don't use this at all.

YEAR=2008
DEST=/home/whatever/chatlogs/$YEAR

# Copy the directory structure.
find . -type d -exec mkdir -p "$DEST/{}" \;

# Copy the files starting with the year.
find . -name $YEAR*.txt -exec mv "{}" $DEST/{} \;

# For the rmdirs, we could use -exec command + instead of -exec command ; but we don't because
# this script simply doesn't run very often.

# Remove any extra directories we made, go depth-first
find $DEST -depth -type d -exec rmdir --ignore-fail-on-non-empty {} \;

# Remove any empty directories in case we took away all the files, go depth-first
find . -depth -type d -exec rmdir --ignore-fail-on-non-empty {} \;

It should not be run from the .purple/logs directory, or wherever. After that's done, you can not go tar cz (create, compress with gzip) the directory.

Tag: geeky shell howto