Welcome to the final Weekly Digest of 2008. I hope the holidays have found you well :)
Trevor
Towards Rack 1.0 / Introducing the Rack Core Team
Rack has become an important part of the Ruby infrastructure and should be managed as such. Thus I have founded the Rack Core Team, which consists of…
You Got your Merb in my Rails
Forcing Rails to acknowledge the needs of a community of people by proving those ideas out in code worked here, and it will work again.
Work on what you use and share the rest
It seems that we thoroughly caught the interwebs with surprise by announcing that Merb is being merged into Rails 3. 96% of the feedback seems to be very positive. People incredibly excited about us closing the rift and emerging as a stronger community.
Dispatch from the Front Lines
It’s been a very busy few days, but I’m glad to say that the work on the Rails/Merb merge is going quite smoothly. Some things that have already happened…
Bringing Merb’s provides/display into Rails 3
The flow of Merb ideas into Rails 3 is already under way. Let me walk you through one of the first examples that I’ve been working on the design for. Merb has a feature related to Rails’ respond_to structure that works for the generic cases where you have a single object or collection that you want to respond with in different formats.
The Merbist » Blog Archive » Merb/Rails merge, or Why should merbists be happy? | merb news – consulting – training
Why merge when we are about to win?! What does Merb win by being merged into Rails? Why not merge Rails into Merb? You are killing innovation by killing the competition. You screwed us over and now I have to go “back” to Rails. Rails 3.0 won’t even be as good as Merb 1.x. The Rails team won’t let you do what you have to do to merge Merb into Rails. DHH is a jerk.
Analemma Over the Porch of Maidens
If you took a picture of the Sun at the same time each day, would it remain in the same position? The answer is no, and the shape traced out by the Sun over the course of a year is called an analemma.
Riding Rails: Merb gets merged into Rails 3!
It’s christmas, baby, and do we have a present for you. We’re ending the bickering between Merb and Rails with a this bombshell: Merb is being merged into Rails 3!
Posterous launches dead simple group sites
Each site can now have multiple contributers. You can add your friends or family’s email addresses to any Posterous site you control, and they can then email stuff in too. All they have to do is email post@sitename.posterous.com. They don’t even need to register.
UserNameCheck.com
This site is a quick and dirty solution to a question that I often lay awake at night worrying about. Do I have my username registered across every site that I should? What if the next internet humiliation meme just happens to share the username I’ve been using for years…
Chief Of The Year: Amazon CTO Werner Vogels
Amazon offers a few metrics as proof points. There are 440,000 registered AWS developers, 29 billion objects stored in S3, and, earlier this year, the amount of network bandwidth consumed by AWS surpassed that required for Amazon’s retail site.
Useful OS X hidden features
So, especially for those of you using computers, instead of Windows, here’s some key combos and other built-in helper applications you might not already know about.
Timothy
Y.P.R.: 11 Words That Sound Offensive, But Aren’t
You will laugh. You will laugh /out loud/.
Extended life battery for those experience less than desired G1 battery life | Android Community
I wouldn’t go so far as some have gone and say that the G1 has a worse battery life than the first gen iPhones, but I can confirm that if you like auto-location intensive softs like loopt or are using the phone to navigate and plan on having it find your location more than a few times while navigating, you will beat the stock G1 battery to within an inch of its life in a matter of two or three hours. Odds are good that I’m going to order one of these.
Debian Package of the Day » Blog Archive » watch (from procps): execute a program at regular intervals, and show the output
watch is one of my favorite programs of all time. You can always tell when my OCD is getting the better of me by how many tabs on my tab bar in konsole are just doing watch -d whatever
Please find the attached installment of interesting links. Don’t forget to check in with greyscalegorilla for more. We’ve also inspired another weekly link collection from a Chicago Rubyist: This week’s highlights.
Trevor
Sinatra Book
Sinatra is a Domain Specific Language(DSL) for quickly creating web-applications in ruby. It keeps a minimal feature set, leaving the developer to use the tools that best suit them and their application.
?+?+L and other useful OS X hidden features
So, especially for those of you using computers, instead of Windows, here’s some key combos and other built-in helper applications you might not already know about.
Videos from Paris on Rails ’08
Most of these sessions are in French, but Michael Koziarski did a great session on Rails Performance that’s in English and so was my iChat Q&A session.
Performance of Rails Metal
In my benchmarks, speed increase I get when using Metal is about 1 millisecond. It’s very important to understand that it’s a constant speed increase. For example, if my Rails action takes 12ms, when I reimplement it all in Metal, it will take about 11 ms and not 4 ms.
Agile git and the story branch pattern
I’ve been using the story branch pattern for development for most of the last year, and have found it useful, convenient and a lifesaver when things get weird. I’ve also watched teammates that do their work in the master branch, and it is more work for them to deal with issues and avoid making unintended messes. Like all useful practices it takes a little bit of effort up front, but it saves a lot more effort when it really matters.
A peek at Extra Extra, an internal 37signals app
One of the things we wanted to do with the new site was to have a place where we could display current comments, ideas, and conversations going on around the web about Highrise.
A Journey Through Five Years of WordPress Interface
With the recently launched WordPress 2.7, bloggers now marvel at how clean, beautiful and usable is the new interface. But do you remember what it used to be a couple of months ago? For those who started using WordPress years ago, can you remember what your admin area looked like?
Rule of thirds
The rule of thirds is a compositional rule of thumb in visual arts such as painting, photography and design. The rule states that an image should be imagined as divided into nine equal parts by two equally-spaced horizontal lines and two equally-spaced vertical lines, and that important compositional elements should be placed along these lines or their intersections. Proponents of this technique claim that aligning an image with these points creates more tension, energy and interest in the photo than simply centering the feature would.
Why you (and I) are not designers
You are a not a designer. A designer is someone with training and experience in design. You may convince yourself otherwise, but your customers will not be fooled.
Amazon S3 Firefox Organizer (S3Fox)
S3Fox Organizer helps you organize/manage/store your files on Amazon S3. It is easy to install and use as it is integrated into the browser.
Machinist for your Test Data Factory
Using fixtures for test data sucks. Concept of factories have emerged as a recommended alternative for fixtures. There were several plugins to help creating factories such as Object Daddy and Factory Girl. Recently I got to use another factory plugin called Machinist, which is written by Pete Yandell which looked far more impressive from the rest.
Introducing Rails Metal
Think of Rails Metal as a subset of middleware intended for application-specific end points that need the extra speed (“write to the metal”, hence the name). Thanks to recent adoption of Rack sessions, these pieces of metal even have access to the same session as Rails. You can either run them as part of the Rails process or run them as individual services through rackup.
Cache-Control Header for Amazon S3
Or “How to set a far future Expires header in S3 to appease the YSlow gods”.
Hosting Ruby on Rails with Passenger
…if you do not already have an investment in an alternative solution, or if you’re feeling pain with that solution, you should definitely consider Passenger to be the default choice for Rails.
Amazon releases CloudFront
CloudFront is a content distribution service that caches S3 content at 14 locations on three continents based on the access patterns to the individual S3 objects. As far as I can tell, it’s a service that is quite distinct from S3, except that it currently uses S3 as the origin server (i.e. the original objects to be cached must reside on S3).
The Fork Queue at GitHub
This tool allows you to do a lot of repository collaboration maintenance entirely from the website. You can setup an integration branch that you ask everyone to make sure their commits apply cleanly to and pull them in one by one, entirely online. It also gives you great visibility to what is out there in your forked network and what you have or have not brought in yet.
A Collection of Rack middlewares
Some of this stuff use to be Rails only. But now that it’s a Rack middleware, any framework (that is based on Rack) can use it. For example, Rack::MailExceptions can now replace Rails exception_notification and merb_exceptions. So next time you build a framework plugin, think about building a middleware instead and contribute it to Ryan Tomayko’s project.
Performance on Rails
RailsConf Europe 08: Jeremy Kemper (37signals), Performance on Rails.
Deploying Sinatra on Dreamhost With Passenger
Sinatra is a DSL for quickly creating web-applications in Ruby with minimal effort, as quoted from the Sinatra website. It is great for really simple, really fast services and in general is fun to make apps with. Since I showed how to deploy your Rails apps on Dreamhost, I thought I would also cover how to deploy your Sinatra apps as well.
Tim
"cupcake" development branch ?(Android Open Source Project?)
This isn’t so much a "development branch" as it is a service pack. And I don’t mean a Microsoft-style service pack (i.e. collected bug and security fixes), but a literal pack of services. There are bug fixes (and they pretty much address all of my initial issues with my G1), but there are a number of significant new features. Android = living up to its promise.
Textkit – Greek and Latin Learning Tools
If, like me, you’ve fallen out of the habit of practicing your Latin (or Greek) and have become a little bit rusty, this might be just the thing: PDF versions of elementary textbooks are here and free for the downloading. The only caveat, of course, is that you now, officially, have no excuse for your shitty Latin.
Android G1 (aka HTC Dream) Service Manual (PDF)
I don’t know how this leaked to the Interwebs, but here it is; everything from battery-changing to running the on-board diagnostics.
Landon Fuller: DNS dead drop
A "dead drop" is the thing in spy movies where the contact anxiously deposits his purloined documents and then shuffles nervously away. The secret agent shows up at a later time, when he won’t be observed, and receives the purloined documents. If you can follow the details on how dude in this article is "stashing" messages in DNS caches, it’s a very cool read (warn: hacker knowledge required).
Debian Dependency Map « Gnowgi
This is a cool little project that dynamically maps package dependencies in Debian. Not of much interest to the non-sysadmin crowd, but very cool if that’s your deal.
My Maps Editor by Google puts your custom maps in your pocket | Android Community
Customizing and saving your own maps /probably/ should have been built into the integrated Google Maps function on the G1 when it was launched. I know I bitched about it. And if I bitched about it, at least a dozen people /thought/ about bitching about it. Oh well, now that it’s here, all’s forgiven.
How to Install GRUB Splash Screen Image on Debian Linux | Kushal Koolwal’s Linux Blogs
Until just moments ago, I had no idea that there was an easy way to configure the background for the grub boot loader. Having booted numerous RedHat/CentOS machines, I knew that it could be done; I just never knew how.
Cambridge University Engineering Department – Text Processing using LaTeX
I am /really/ into LaTeX lately; ever since I discovered that you could generate really nice-looking PDF’s from the command-line without dicking around with a big, clunky "write" or "abiword" type program I’ve been hooked, lined and sinkered.
Debian Package of the Day » Blog Archive » ferm: a straightforward firewall configuration tool
dnsmasq is to DNS/DHCP what ferm is to firewalls. If you find bind to be daunting, you can set something up lickety-split with dnsmasq and, if you’re feeling ambitious later on, go back to it and dig in deeper at your leisure; similarly, ferm allows for real quick firewall setup and gives you the option to shitcan that setup at a moment’s notice and implement another solution.
Here’s the latest installment of super sweet links from yours truly, Trevor and Tim. Also, don’t forget about our good friend Nick, who is also doing a weekly link digest over on his blog.
Introducing Cache Money
A version of this code is in production use at Twitter and is one part of the reason Twitter’s uptime has improved so much over the last several months. This is real, pragmatic, unmagical, production-ready code that can be a big part of your Rails scaling strategy. It is designed with massive datasets and real-world operational challenges in mind. And it’s almost effortless to use, since it requires no changes to how you use ActiveRecord.
jeremymcanally’s context
A super tight library to add contexts to tests. If you’ve ever wanted contexts in your Test::Unit tests, then context is for you. Your tests will be easier to read and write without all the magic and extra code smell!
Hacker News: I don’t want to work very hard
"The thought of having to expend my creative energy on things that make practical everyday life more refined, with a bleak capital gain as the goal, was unbearable to me." – Einstein
McDonald’s New Packaging
The new packaging takes on another major area of criticism – the content of its food. So, for example, in the new design the box for a Big Mac is adorned with clean photographs of the fresh ingredients inside – a mound of ‘100% pure beef’ sits atop scales. There’s a real onion and a real lettuce. This is packaging as advertising in a very explicit form, campaigning heavily to convince the customer that this stuff is made from real things.
10 things you could be doing to your code right now
Upgrade Test::Unit. Try out some TDD. Upgrade your fixtures. Install (and learn and use) a SCM. Investigate Continuous Integration. Know your code. Automate your deployments. Collect some statistics. Read other people’s code. Blog about it.
Learn Merb
[Another interesting comment feed on Rails/Merb...]
Writing My Twitter Etiquette Article: 14 Ways to Use Twitter Politely
With the usual exceptions, people on Twitter tend to fall into two main camps. There are responders, who use Twitter as a channel to interact heavily with other users, and broadcasters, who use it primarily as a micro-blogging platform.
Bang
After that moment of conception, what it is, however nascent, however raw, becomes part of the process. You’re adding to it. Changing it. Removing parts of it. But there is an it, where before there was not. There’s something magic and magnificent and frightening about that part in the creative process before there is an it, when you decide just what it should be.
HTTP Client – Mac Developer Tool for HTTP Debugging
A Mac OS X Leopard developer tool for debugging HTTP services by graphically creating & inspecting complex HTTP messages. [Fun fact: "http://google.com" returns a 301 Moved redirect!!!]
WordPress 2.7 “Coltrane”
The first thing you’ll notice about 2.7 is its new interface. From the top down, we’ve listened to your feedback and thought deeply about the design and the result is a WordPress that’s just plain faster. Nearly every task you do on your blog will take fewer clicks and be faster in 2.7 than it did in a previous version.
Yehuda Katz explains Merb
In this interview from RubyFringe, Yehuda Katz talks about Merb, its design principles, and how it differs from Rails. Yehuda also mentions Yard, an RDoc replacement.
How to reset postgres’ primary key sequence when it falls out of sync?
SELECT MAX(id) FROM your_table; SELECT nextval(‘your_table_id_seq’); SELECT setval(‘your_table_id_seq’, (SELECT MAX(id) FROM your_table)+1);
Grow Then Cull
Good product leaders have the vision and balls to be bold with experimentation, and equally bold with cutting all but the very best features and functions. A mature product is a phoenix which has burned to the ground and reformed hundreds of times. Each time it grows a bit closer to being the ideal solution to a real problem that users need solved.
Ray Ozzie Wants to Push Microsoft Back Into Startup Mode
To Ozzie, software’s soul does not lie in the accumulation of features. Instead, it lies in his dream of connectivity. "Live Mesh is very Ray," Mitch Kapor says. "It’s the son of Groove, which is the son of Notes." Which was, of course, the son of Ozzie’s beloved Plato. Thirty-three years later, Ozzie is still trying to build on what he saw in sophomore year. But it’s no longer the Ray Ozzie vision. It’s Microsoft’s.
Not My Gorilla
There are a lot of people who’d be a lot happier if they stopped worrying about other people’s 800 pound gorillas.
HTTParty Divorces ActiveSupport (and more updates)
…removed ActiveSupport as a dependency and added the JSON gem. Proxy Support. Format Detection Based on Content Type. Automatically Follow Redirects. HTML format. HTTParty.get/post/put/delete.
Hacking Billy Mouth Bass in Linux
Yeah, I know it’s old. But it’s Friday night and I’ve been drunk-WP-hacking. php makes me whimsical.
Motivation: Forty Inspirational Speeches from the Movies in Two Minutes
I have seen all of these movies. And yet it is so rarely the case that I triumph gloriously over adversity in the face of overwhelming odds. Strange.
Should Coffeehouses Do Something About Drink Loopholes? | coffee …
This article about Starbucks "loopholes" is exactly the type of knowledge that does /not/ need to be spread so far and so wide that it makes it back to Corporate. If, for example, the cornflower blue crew realizes that you can get a grande Americano (two shots) for under $3.00 at most locations while those two shots by themselves cost $4.00 or more, then those of us who occasionally have to drink Starbucks (on account of not acting like the pinkos we secretly are whenever the client wants to dip out of the office to speak candidly or the vendor wants to meet up in a totally neutral location bereft of anything that might cause anything to think even for a moment about anything other than the business at hand) will have no way to do so without dropping an unacceptable amount of paper on the worst McCoffee-house in the game. Basically, these hacks/exploits/whatever need to stay unexposed.
Giz Explains: Everything You Need to Know About Hard Drives
On the eve of the rise of solid state storage media, Gizmodo publishes a nice love letter to the HDD. Worth reading on a slow day; informative and casual.
16 Useful .htaccess Tricks and Hacks For Web Developers : Online Marketing Blog – Website Development & Website Marketing tips and Strategies
This is helpful is 1.) you find yourself working on someone else’s computer and can’t modify your own apache conf or 2.) you are setting up a home dir for someone who you can’t allow to access his own apache conf.
Is your subway system a platform? (Scripting News)
This isn’t a particularly great article, but it is worth reading if only for the fact that it suggests a future in which municipalities provide public access to some kind of API that allows people to develop applications based on their data (a la your favorite Web2.0 products).
Tools for your Slice // Slicehost – VPS Hosting
Slicehost is basically awesome. This is the first thing I’ve seen on the Internets–and I see a lot of things on these ‘ere Internets–that ever made me wish I had an iPhone. Perhaps I need to start the Android project for using the slicehost API…
Best options for coffee drinkers who like it "light and sweet"
Full disclosure: I don’t put any dairy in my coffee (seriously–why even drink coffee? if creaminess is what you’re after, may I recommend chocolate milk? seriously: you should try it) and I’m too old and poor to fuck around with lattes anymore (except on special occasions). That said, what you’ve got here is a nice summary of sweetener options: you’ve got mentions of setiva and turbinado and a quick nod in the direction of nutrition mythology (if you’re into that sort of thing). Mostly valuable as a primer on sweeteners.
NoFo: Proposition Hate
This is probably the best get-fly-off-the-handle-mad-about-prop-8 blog post. I’ve added it to my del queue because it seems like it’s going to be the genre-closer: it’s short and it goes back and forth between cloyingly maudlin (complete with developmental disabilities and child abuse) and threateningly vituperative in a way that I think represents the spectrum of acceptable responses to the passage of the proposition.
Gmail Labs’ New Task Manager Can Add Email to Your To-Do List
I’ve only added this to my del.icio.us queue on account of the fact that I was recently told by a friend that, contrary to what you might expect, not everyone subscribes to LifeHacker. And while I find this almost impossible to believe, they got the scoop on the integrated Gmail to do list manager (as far as my RSS queue was concerned) and therefore get the credit.
Google Offering Unlocked G1’s to Developers | AndroidGuys
On the one hand, basic ethics dictate that this probably should have happened (or at least been announced) at launch; on the other hand, even a child can tell you that basic ethics have no place in Corporate Media it’s hard to hold T-Mobile accountable for having been less than forthcoming with this news when the phone was launched. Still: this is an awesome loophole for people who aren’t ready to get into bet with T-Mobile but really want a G1.
Graffiti Wall Distillation: Tourist Scams, 2005
I generally wouldn’t ever recommend a list of common tourist scams to anyone who wasn’t my mother; it’s patronizing and, basically, if you’re an adult and you haven’t got the wherewithal to seek out this information on your own before doing your recreational thrill-seeking in the tourist traps of the First and Third worlds, then you deserve whatever happens to you. I would, however, recommend a list of common tourist scams to aspiring writers, creative and otherwise. Such a list as this one is exactly the kind of invaluable resource to which writing teachers and professional novelists often refer as their "secret weapons". Very interesting and inspiring stuff.
I’ve been using Paperclip to handle file uploads lately, and I wanted to be able to accept file “uploads” with a URL. We already knew how to accomplish this with attachment_fu, and getting it working in Paperclip wasn’t too difficult.
This example shows a Photo model that has an Image attachment.
The technique we’re using requires adding a *_remote_url (string) column for your attachment, which is used to store the original URL. So, in this case, we need to add a column named image_remote_url the photos table.
# db/migrate/20081210200032_add_image_remote_url_to_photos.rb
class AddImageRemoteUrlToPhotos < ActiveRecord::Migration
def self.up
add_column :photos, :image_remote_url, :string
end
def self.down
remove_column :photos, :image_remote_url
end
end
Nothing special is required for the controller...
# app/controllers/photos_controller.rb
class PhotosController < ApplicationController
def create
@photo = Photo.new(params[:photo])
if @photo.save
redirect_to photos_path
else
render :action => 'new'
end
end
end
In the form, we a add a text_field called :image_url, so people can upload a file or provide a URL...
# app/views/photos/new.html.erb
<%= error_messages_for :photo %>
<% form_for :photo, :html => { :multipart => true } do |f| %>
Upload a photo: <%= f.file_field :image %>
...or provide a URL: <%= f.text_field :image_url %>
<%= f.submit 'Submit' %>
<% end %>
The meaty stuff is in the Photo model. We need to require open-uri, add an attr_accessor :image_url, and do the normal has_attached_file stuff. Then, we add a before_validation callback to download the file in the image_url attribute (if provided) and save the original URL as image_remote_url. Finally, we do a validates_presence_of :image_remote_url, which allows us to rescue from the many exceptions that can be raised when attempting to download the file.
# app/models/photo.rb
require 'open-uri'
class Photo < ActiveRecord::Base
attr_accessor :image_url
has_attached_file :image # etc...
before_validation :download_remote_image, :if => :image_url_provided?
validates_presence_of :image_remote_url, :if => :image_url_provided?, :message => 'is invalid or inaccessible'
private
def image_url_provided?
!self.image_url.blank?
end
def download_remote_image
self.image = do_download_remote_image
self.image_remote_url = image_url
end
def do_download_remote_image
io = open(URI.parse(image_url))
def io.original_filename; base_uri.path.split('/').last; end
io.original_filename.blank? ? nil : io
rescue # catch url errors with validations instead of exceptions (Errno::ENOENT, OpenURI::HTTPError, etc...)
end
end
Everything will work as normal, including the creation of thumbnails, etc. Plus, since we're doing all of the hard stuff in the model, "uploading" a file via URL works from within script/console as well:
$ script/console
Loading development environment (Rails 2.2.2)
>> Photo.new(:image_url => 'http://www.google.com/intl/en_ALL/images/logo.gif')
=> #
Sweet.
Update: The example code has been updated to reflect thew suggestions left in the comments. The original_filename method is now defined on the fly. Thanks for the feedback! I've also split out a new method called do_download_remote_image, which can be used for stubbing out in tests with mocha:
Photo.any_instance.expects(:do_download_remote_image).returns(File.open("#{Rails.root}/testhttp://s3.amazonaws.com/almosteffortless/rails.png"))