I am available for freelance work! Click here to email me.

Fixing Long Key Lengths in MySQL

June 17th, 2010

While using Query Reviewer, I occasionally come across a warning along the lines of the following:

2 identical queries Table videos: Long key length (768)

With the following explanation:

The key used for the index was rather long, potentially affecting indices in memory

To fix this we need to limit the length of our index. We can do this by creating a migration with :length added to the add_index method:

add_index :videos, :cached_slug, :length => 20

If you’re indexing more than one column, you can use the following:

add_index :stories, [:title, :author_name], :length => { :title => 10, :author_name => 5 }

Hopefully this post will save someone a few minutes.

Calculating an Images Orientation using Paperclip

June 10th, 2010

If you ever need to know if an image is portrait or landscape in orientation, you can do the following (assuming you have an orientation attribute on your model:

class Image < ActiveRecord::Base
  # Paperclip
  has_attached_file :file

  # Callbacks
  before_create :set_orientation

  protected

  def set_orientation
    original_file = self.file.to_file(:original)
    dimensions = Paperclip::Geometry.from_file(original_file)
    self.orientation = (dimensions.width > dimensions.height) ? 'landscape' : 'portrait'
  end
end

How To Speed Up Textmate in Large Projects

March 25th, 2010

You know those times when Textmate beachballs for about 5 seconds when it regains focus, it’s generally caused by the fact you’ve got about 16 million folders in your public/system folder used by paperclip.

Here’s a quick tip to speed things up by ignoring those folders:

Open Textmate Preferences and goto the Advanced section. Then click on Folder References.

Picture 7

And enter the following in Folder Pattern:

!.*/(\.[^/]*|log|system|CVS|_darcs|_MTN|\{arch\}|blib|.*~\.nib|.*\.(framework|app|pbproj|pbxproj|xcode(proj)?|bundle))$

Rejoice in the fact that Textmate doesn’t make you want to cry.

« Previous Entries Next Page »

Purify - Issue Tracker

Jim Neath is a 26 year old Freelance Ruby on Rails developer from Manchester, UK.

Recommend Me

Categories