Posted 4 days ago at A Fresh Cup

I'm about ready for a weekend. Fortunately, I can see one coming.

back to top

David added a very cool feature to Rails recently – Signed cookies and permanent cookies This lets you set permanent and/or signed cookies very easily.

Before this, you’d have to write :

1
2
3
4
cookies[:user_preference] = {
  :value => @current_user.preferences,
  :expires => 20.years.from_now.utc
}

Now just becomes :


cookies.permanent[:user_preference] = @current_user.preferences

In case you happen to have seen my Railssummit presentation I had talked about using ActiveSupport::MessageVerifier for implementing “Remember me” functionality. The above commit makes that a whole lot easier.

In your model User.rb :

1
2
3
4
5
# User.rb
def self.authenticated_with_token(id, stored_salt)
  u = find_by_id(user_id)
  u && u.salt == stored_salt ? u : nil
end

And when the user checks “Remember me” box, make sure the following gets run :


cookies.permanent.signed[:remember_me] = [current_user.id, current_user.salt]

This will set a permanent and signed cookie using the secret specified in ActionController::Base.cookie_verifier_secret. If you don’t have the cookie_verifier_secret defined, you might want to do that in one of the initializers.

Now when you want to login using the cookie :


user = User.authenticated_with_token(*cookies.signed[:remember_me])

In this specific case, it’s very important to use the salt in the cookie value. That makes sure the cookie gets invalidated if the user changes his password.

back to top
Posted 4 days ago at Riding Rails - home

You thought we were never going to get to this day, didn’t you? Ye of little faith. Because here is the first real, public release of Rails 3.0 in the form of a beta package that we’ve toiled long and hard over.

It’s surely not perfect yet, but we were out of blockers on the list, so here we go. Please give it a run around the block, try to update some old applications, try to start some new ones, and report back all the issues you find.

I’m really proud of this moment, actually. We’ve had more than 250 people help with the release and we’ve been through almost 4,000 commits since 2.3 to get here. Yet still the new version feels lighter, more agile, and easier to understand. It’s a great day to be a Rails developer.

There’s plenty to get excited about here. A few of the headliner features are:

  • Brand new router with an emphasis on RESTful declarations
  • New Action Mailer API modelled after Action Controller (now without the agonizing pain of sending multipart messages!)
  • New Active Record chainable query language built on top of relational algebra
  • Unobtrusive JavaScript helpers with drivers for Prototype, jQuery, and more coming (end of inline JS)
  • Explicit dependency management with Bundler

But please take a look at the full release notes and enjoy the latest!

To install:

gem install tzinfo builder memcache-client rack rack-test rack-mount erubis mail text-format thor bundler i18n
gem install rails --pre

Notes: The first line is required because RubyGems currently can’t mix prerelease and regular release gems (someone please fix that!).

back to top
Posted 5 days ago at The GitHub Blog

Following three months of near 100% uptime, we’ve just been through three major outages in as many days. I wanted to take some time to detail the problems and what we intend to do to prevent similar downtime in the future.

Outage #1 (02/02/2010 9:55:09AM PST) was initiated by a load spike on one of our file servers (fs1a). When a file server stops responding to heartbeat, the slave server in the pair kills the master and takes over. In this case, the master was not killed quickly enough and the storage partitions did not migrate cleanly to the slave. Cleanup on the split-blain file server pair was delayed due to some inefficient DRBD configuration that we’ve been meaning to update. By rolling out improvements to the DRBD configuration, this type of problem should be prevented from happening in the future.

Outage #2 (02/03/2010 6:10:08PM PST) looked like a power outage at first, since so many machines were affected, but the root cause was the deployment of a faulty DRBD configuration update that propagated to all machines (courtesy of Puppet) and started causing pairs of machines to halt replication to prevent corruption caused by an invalid configuration file. Eventually the load balancer pair was affected and we could no longer even serve the Angry Unicorn page. The way that the servers went down, the number of servers that went down, and the length of time it takes to resync downed pairs resulted in a lengthy outage. There are several steps to preventing this kind of outage in the future. First and most obvious is to maintain tighter control and testing of proposed system-wide configuration changes. We also plan to deploy (well-tested) changes to the DRBD configuration that will reduce cleanup times and automate the startup process for downed machines. These changes will result in shorter recovery times in the event of single failovers and wider machine-level restarts.

Outage #3 (02/04/2010 2:37:08AM PST) was caused by massive load spikes across all five file servers. To prevent extended downtime we marked all file servers as offline (preventing them from going into failover) and looking for the cause of the load. After inspecting the HTTP logs, we identified a Yahoo! spider that was making thousands of requests but never waiting for responses. After banning the spider, the load returned to normal and we were able to bring the file servers back online. We are looking at our rate limiting strategy and will be making improvements over time to get the best performance for legitimate users and the best protection from anomalous behavior.

In order to execute the improvements to various infrastructure elements, we will be having scheduled maintenance windows at 10PM PST over the next week. Most of these changes will not require any downtime, but some of them may result in temporary unavailability of file server partitions. As we perform the maintenance, we’ll keep you updated via the GitHub Twitter account, so make sure to check there for the latest maintenance news.

We sincerely apologize for the recent problems and are working very hard to address each flaw. Stability is one of our biggest goals this year, and I look forward to making your GitHub experience as flawless as possible.

back to top
Posted 5 days ago at A Fresh Cup

Sleep seems overrated until you have to skip it for a while.

  • gMap - jQuery plugin for Google Maps. Looks way easier than the last way I've done it.
  • webtranslateit - Gem to integrate a Rails app with Web Translate It, a web service to help provide localization.
  • Why use HAML (and SASS)? I already know HTML. - Another argument in favor of switching to HAML/SASS. This is rapidly becoming the vi vs. emacs of templating languages.
  • toto - Blog engine built atop rack and aimed at heroku deployment.
  • Ubiquitous Analytics and Tableau Public - This looks nice; the Tableau data visualization app is one of the things I remember from Windows days, and now they're bringing it to the web.
  • DTerm - Popup command line for OS X.

back to top
Posted 6 days ago at A Fresh Cup

Sometimes it seems that tomorrow is a long time in coming.

back to top
Posted 7 days ago at A Fresh Cup

Early morning coding is the most peaceful time of day.

back to top
Posted 8 days ago at A Fresh Cup

Yesterday, I needed test coverage numbers for an application using Rails 2.3 and plain old Test::Unit (still my test framework of choice). This proved to be a good deal more difficult than I expected: there are so many forks of the original rcov code, and so much disparate advice on how to get it hooked up, that I spent a great deal of unprofitable time reading before I got the right combination. Hopefully this short list will save you from doing the same:

  1. Install the relevance-rcov gem. This is the stable and maintained fork.
  2. Install the commondream rcov_plugin. This has the best set of working rake tasks I've found.
  3. Add coverage/* and test/coverage/* to your .gitignore.
  4. Run rake test:coverage to generate coverage results.
  5. Open /coverage/index.html in your project to view the results.

back to top
Posted 8 days ago at A Fresh Cup

It's February, and I've got a team of devs coming available for new work. Happy to chat about any prospective projects you might want done.

back to top
Posted 8 days ago at The GitHub Blog

As I’ll be speaking at the Symfony Live Conference in Paris in a few weeks, GitHub and Sensio Labs are co-hosting a GitHub meetup in Paris on Wednesday, February 17th at 8pm.

We’ll be joined by a bunch of PHP people from the Symfony Live Conference hopefully, so if you’re a GitHubber not going to that, please join us for some cross-language nerd chatter. I’m also giving a short Git talk at 8:30p if you want to see that.

We hope to see you there!

Patricks Irish Pub
33, rue de Montreuil
75011 Paris


View Larger Map

back to top
Posted 8 days ago at Railscasts

Change the look and behavior of a Rails app on mobile devices. Also use jQTouch to build a native-looking interface.

back to top

I’m happy to announce that this blog is now sponsored by an exclusive ad network run by James Avery called Ruby Row. While I could have just slapped google adsense all over the blog, Ruby Row provides much more value to the visitors as the ads are primarily targeted at Ruby/Rails developers.

I still have a spot open for per post text advertising. So if you’re interested, drop me an email on pratiknaik gmail

back to top
Posted 11 days ago at A Fresh Cup

And somehow, I have survived another week.

back to top
Posted 12 days ago at A Fresh Cup

And no, running HTML 5 does not make a closed proprietary device magically open.

back to top
Posted 13 days ago at The GitHub Blog

NV has ported his Diff for Gist Greasemonkey script to a Chrome Extension.

Pretty cool – I’ve been using it since I first saw it. And if you’re looking for more UserScripts, NV has also released a github-live-preview.

back to top