Truncating URLs w/PermalinkFu
I use PermalinkFu for generating nice slugs for URLs here, at Artlog and in the Backlight CMS that runs a number of websites for friends like Marlene Marino and A Crime So Monstrous.
In any case, it’s a great plugin, but it’s begun to bother me that it can generate some massively long permalinks if left unchecked. So for the new Artlog site I am going to truncate the permalinks into some limited number of words.
For example, I’ve set the note model to generate the permalinks (saved in a “permalink” column in the DB) this way:
class Note < ActiveRecord::Base
def to_param
"#{id}-#{permalink}"
end
before_save :create_or_modify_permalink
def create_or_modify_permalink
self.permalink = PermalinkFu.escape(("#{name}").to_s)
end
end
That’s fine in most situations, but if the note’s name is long you run into issues.
>> n = Note.new => #<Note id: nil, name: nil, permalink: nil, created_at: nil, updated_at: nil> >> n.name = "I just flew back from Chicago and boy are my arms tired" => "I just flew back from Chicago and boy are my arms tired" >> n.save! => true >> n.permalink = "I-just-flew-back-from-Chicago-and-boy-are-my-arms-tired"
That’s awkward – particularly if you are RESTing it up and your edit URL ends up looking like
/notes/1-I-just-flew-back-from-Chicago-and-boy-are-my-arms-tired/edit
So I am going to go ahead and create an evil twin plugin to generate more sane slugs and have the new method available across all models (rather than having the fix only available in the note model).
In vendor/plugins create a directory called “permalink_fu_hacks” or something and create an init.rb file in that directory (/vendor/plugins/permalink_fu_hacks/init.rb) that looks like the following:
PermalinkFu.module_eval do
class << self
# truncate the permalinks to x number of words (specified in length below)
def truncated_escape(str)
length = 6
PermalinkFu.escape(("#{str.split()[0..(length-1)].join(' ')}").to_s)
end
end
end
You can change the length we specify to whatever you’d like. Six may seem like to many or too few words to you, but it doesn’t really matter; you’re largely just setting an upper limit to prevent URLs from getting way too long.
You can now change your create_or_modify_permalink callback in the note model to this
def create_or_modify_permalink
self.permalink = PermalinkFu.truncated_escape(("#{name}").to_s)
end
and you’ll end up with a better permalink:
>> n.save! => true >> n.permalink = "I-just-flew-back-from-Chicago"
→ ‘More about deleting features’ @inessential.com
Brent Simmons, developer of NetNewsWire, writes about his approach to re-factoring applications.
When working on a new version of the app, before I think about the features I want to add, I take a look at what I can get rid of first. It’s a quality-of-app thing. I think of it as making space for the new stuff — but first I have to take the wrecking ball to some old stuff. (If I don’t, you get feature sprawl. Yuck.)
But, the thing is, these are features that some people somewhere use and like. And they’ll be sad to see them go. It’s worse than skunks-in-the-fridge, it’s exploding skunks in bed.
I’ve been thinking a lot about this as I re-work Artlog. It’s super tough making decisions about what should stay and what would make everything else better by getting dropped (no, not you, honey; you are fine right where you are). Always good to see other developers (especially really, really good ones) successfully working through the same issues. [via Dan]
→ Apple Device Security: Big Temptation to Dumb-Down @43 Folders
But my entirely anecdotal opinion is that the iPhone, the iPod Touch, and the AppleTV each tempts their users to slide back to dumbing-down their passwords in exchange for better ease-of-use. The most annoying device in your chain ends up driving the passwords you use for everything. Right now, it’s such a pain to enter a secure password on a device like the iPhone or the AppleTV, that I’m betting a few of you have already fallen back on your ferret. Or “pencil.” Or your ATM PIN.
Another good observation by Merlin. I’ve actually been resisting the urge to simplify passwords for iTunes and various web apps since I’ve started using the new iPhone for more non-telephone activities and also set up an auto-lock for the first time. But assuredly the temptation to simplify passwords given somewhat tedious touch keypads is strong.
Amazon S3 outages
Amazon S3 went down for about 8 hours yesterday, effecting a number of our in-house projects including this site, Artlog, and all sites powered by Backlight. Considerably larger sites that also use S3 for media storage like Twitter and Tumblr were similarly hamstrung.
S3 is an amazing service despite this and other recent outages. Fortunately, Amazon recently setup a page providing status updates for their web services which went a long ways toward effectively keeping customers informed of progress. It’s an example other companies providing web-services should strive toward.



