// A skewed take on the consulting business.
 

Are My Gems Compatible with Ruby 1.9?
Posted by Kevin on March 30, 2009 23:37

I was recently wondering out loud to Patrick over IM about there being an easy way to check if my installed Gems are supported by Ruby 1.9. A quick Google search didn't turn anything up so after a little prompting I wrote Am I Ruby 1.9?.

Am I Ruby 1.9? looks at the 5 most recent comments on Is it Ruby 1.9 for each gem you have installed and then guesses whether it works. Hopefully this will help spark some interest in people updating gems to support Ruby 1.9. I know there are a few I'm going to take a look at!

Is It Ruby 1.9 is a great project, but like all social constructs, it only works if people participate.

Proper Trimming on Save with TextMate
Posted by Kevin on February 19, 2009 16:27

I previously blogged about a method to make TextMate trim trailing spaces when it is saved. However, it had the unfortunate side effect of forcing you to save your file again after the trimming -- even if you hadn't made any changes. I've since implemented Sven Axelsson's comment on how to do it with a macro.

Prior to the previous blog post, my attempt at trimming and saving via a macro didn't work. Sven's suggestion solves that problem. Here it is, outlined a bit more verbosely:

  • Create a new bundle with a command having the following features:
    • Delete the default command text.
    • Save: Current file
    • Input: None
    • Output: Discard
  • Don't give the new bundle an Activation key.
  • Record your macro:
    • Bundles -> Macros -> Start Recording
    • Select Bundles -> Text -> Converting / Stripping -> Remove Trailing Spaces in Document.
    • Select Bundles ->
    • Bundles -> Macros -> Stop Recording
  • Save your new macro
    • Bundles -> Macros -> Save Last Recording...
    • Edit the name
    • Click in the Activation (Key Equivalent) text field and hit Command-S.

I find it strange that Sven's is the only comment out there in Google search land explaining how to do this. So, either it is intuitively obvious to everyone but me, or I just have a Monkish fascination with trimming those pesky trailing spaces.

Trimming Trailing Spaces With Text Mate
Posted by Kevin on February 01, 2009 21:32

NOTICE: This method has a major drawback that is corrected in a the new post: Proper Trimming on Save with TextMate

One thing Text Mate doesn't do by default, and lacks an easy preference setting for, is trim trailing spaces when saving. Luckily, there is an easy way to implement this feature.

  1. Select Bundles->Bundles Editor->Show Bundle Editor
  2. Find Text->Remove Trailing Spaces in Document
  3. Make it look as follows:

Text Mate Bundle Editor

Now, whenever you save your document the trailing spaces will be eliminated.

A slightly faster way is to replace the perl script with:

  sed -e "s/ {1,}$//"

[Update 1] I just noticed that every blue moon multiple copies of the file will get appended instead of replacing. Not sure exactly the cause, but I can host C-s down repeatedly and not force the problem to occur, so YMMV.

First Professional Website Design Deployed!
Posted by Kevin on January 31, 2009 17:28

I made it clear in a previous post that I am not a designer, but I can make do when push comes to shove (and a little bit of feedback from friends!)

A few weeks ago, I released Anthony Grant's artist website. To quote Thanny Le, "It's not as bad as I expected!", which is probably a compliment. I'm pretty happy with the result, though I do want to spice it up a bit at some point.

anthony grant home page

anthony grant about page

Regardless of my design skills, Tony's artwork is amazing.

Caching Rails Pages with Passenger and a Sub-URI
Posted by Kevin on January 21, 2009 03:06

Ever since I started using blurt for my blog, I have wanted to add page caching. Patrick, the author, thinks it is premature optimization -- especially since no one reads our blogs anyway (or at least mine). My view is that performance really stinks on a 256 MB shared slice. By implementing page caching, pages that used to take between a few hundred ms and a few seconds, are now instantaneous. About as digg safe as a single, puny, server can be!

Getting it working wasn't that easy, though. I followed the usual suspects for page caching, but kept running into weird issues with the sweepers. We were originally frozen at Rails 2.1.1, and I think most of the obvious problems were fixed by upgrading to 2.2.2. Once things appeared working, I deployed to production only to be greeted with new issues. Seems I forgot to configure my developer Passenger instance to use a sub URI like I'm doing in production.

The first bit of Google-delivered help was Paul Gross's article on using Mephisto with Phusion Passenger with a custom cache directory. Of course, that's for a website without a sub-URI. Before I could address that issue, I needed to fix a Rails 2.2.2 problem. It pays to read the release notes, and luckily for me someone else had.

First, add the following to your appropriate environment. If you are doing things right, it should be in config/environment.rb and not config/environments/production.rb:

  config.action_controller.relative_url_root = "<sub-uri>"

Next, remove "config.action_view.cache_template_loading = true" from config/environments/production.rb.

Now you are ready to engage in mod_rewrite hacking! A useful trick is to actually log what mod_rewrite is doing. Add the following lines to your apache config (virtual host or other):

        RewriteLog /var/log/apache2/<domain>-rewrite.log
        RewriteLogLevel 3

After playing around for a bit, Paul's rewrite code turned into:

        RailsAllowModRewrite on
        RewriteEngine on
        RewriteRule ^/<sub-uri>/?$ /<sub-uri>/cache/index.html [QSA]
        RewriteRule ^/<sub-uri>/([^.]+?)/?$ /<sub-uri>/cache/$1.html [QSA]
        RewriteCond %{DOCUMENT_ROOT}/<sub-uri>/cache/%{REQUEST_FILENAME} -f
        RewriteRule ^/<sub-uri>/(.*)$ /<sub-uri>/cache/$1 [L]

Hopefully this helps prevent someone from futzing around in circles for a few hours.

 
 
© 2010 Concepts Ahead :: Logo Design by Peyton Crump :: Powered by Blurt