bitfluent

Kamal Fariz Mahyuddin on Ruby, Rails, Git, Chef and other web development geekery.

I'm available for hire for Ruby and Rails development and training, and infrastructure automation with Chef worldwide.

Email me today.

You should follow me on twitter here.
Mar
18th
Wed
permalink

Solving “This website has not registered with Google to establish a secure connection for authorization requests”

I recently ran into an ominous warning on the Google Contacts Access Request landing page.

This website has not registered with Google to establish a secure connection for authorization requests.

After some googling, the solution is to register the requesting domain and upload a self-signed X.509 certificate.

Once completed, I retried the request and got a slightly less threatening warning.

This website is registered with Google to make authorization requests, but has not been configured to send requests securely.

The solution was to add two additional parameters to the request: secure=1 and a signature. Fortunately, I found how to generate the signature in the google-authsub gem. A few minutes later, I added support for signing AuthSub requests to Mislav’s contacts library and got the results I wanted. Commit.

Yay!

Update: I got it wrong about appending the signature to the parameter. I posted a follow up on how to correctly perform signed AuthSub requests in Ruby.

Jan
22nd
Thu
permalink

#rubinius

  • evan: i'm curious, how do you know the JVM is deopt'ing in certain cases?
  • headius: it tells us
  • evan: twitter?
  • evan: us post?
  • evan: collect call?
  • headius: reaches out of the screen and slaps us sideways
  • evan: hah
  • headius: there's a bunch of debug options for hotspot
  • evan: NOT SO FAST BUCKO
  • headius: some in the released jdk, some require a debug build
  • headius: LogCompilation, PrintInlining, PrintAssembly
  • evan: -XXSlapRatio=1persecond
Dec
23rd
Tue
permalink

Sharing Contracts

I love it when companies that provide professional services share the contracts they use when dealing with clients. Many people consider contracts to be part of their secret sauce and competitive advantage over their competition so it’s understandable that these documents are not discussed much (plus they also cost money having to go through legal counsel).

However, Obie Fernandez of HashRocket and Andy Clarke of Stuff and Nonsense have been awesome by sharing the contracts they use in their daily business:

I’d love to collect more of these kinds of write-ups. Do you have some? Twitter me!

Dec
20th
Sat
permalink

Test autoposting from Posterous

I never knew posterous could autopost to other services as well. That’s pretty rad.

Posted via email from kamal’s posterous | Comment »

Oct
31st
Fri
permalink

Full List of 1,339 Rails Contributors

One of the biggest plus points of using git for open source projects is the preservation of the original author of the patch. Here’s how it looks like when displayed in GitHub:

Committer sign-off

In the Subversion days, patches into Rails were attributed by adding an arbitrary combination of the author’s name/email/nick at the end of the commit messages. Makes it kind of hard to keep track of the number of distinct contributors over the lifetime of the project.

Fortunately, Xavier Noria whipped up a script to parse the legacy commit messages to extract the number of commits per author using these rules:

  1. First extract authors from commit message
  2. If empty, check changelogs via git show id
  3. If empty, author is the committer

The full list is can be found on the Rails Contributors page.

Aug
9th
Sat
permalink

Tumblr Client On The iPhone

Would having a tumblr client on my iPhone see me posting more frequently? Obligatory test post.

Posted with LifeCast

Jun
2nd
Mon
permalink

On the Beauty of Rubinius’ Design (I Wish I Had Rails.new)

In Rubinius, you can spawn off a brand new complete VM by simply calling Rubinius.new. It’ll behave exactly as though it was invoked directly from an rbx binary sitting in your $PATH, complete with STDIN/STDOUT (which you can override). I believe this is one of the basis of how Rubinius’ multi-VM architecture works.

Anyway, I bring this up because I really, really wish Rails was architected in a similar fashion. I am building a CMS on top of Rails and would love to get my hands on a Rails.new if there ever was one. Here’s why.

In a CMS setting, very little of what Rails offers out of the box is usable. You don’t have access to Rails routes so from the very beginning, you don’t have Rails automatically invoking the right controller, the right action and rendering the right view. This doesn’t make sense anyway - you don’t expect your CMS users to start writing controller code in your web editor, do you? (Unless you are Heroku.)

On a slight tangent, the assumption when writing a CMS is that when you ship, you would have written every conceivable controller and model there is (views don’t fall into this because users are generally familiar with the concept of customizable templates). One strategy to extend your “frozen code base” is via the use of widgets and third-party apps (like Facebook) so that you can create seemingly new pages served by custom controllers.

So how do you design a CMS? I’ve been prototyping something for the past week and came up for a breather to check out how other people have solved it. I am delightfully surprised to find out that Radiant does it very close to what I have. In particular, Radiant has one single controller that accepts all requests (lets ignore the entire admin portion for the time being). Based on the path array (provided by the globbed route), it decides what to do / where to dispatch. It takes care of locating the page that corresponds to the URL (it uses a Page model), rendering it and returning the result to the user. It is interesting to note that Radiant directly manipulates the request and response objects, something that Rails developers almost never had to reach for in a regular app. On the other hand, I am exploring the use of serializing the templates to disk and simply calling render :template on it.

Wait a minute. Holy cow, we just built (a simplified) Rails on top of Rails!

What I’d love to see here instead is a Rails.new method just like Rubinius. Boom, a full blown MVC at your fingertips. Configure it right and there you have your very own CMS with minimal work. Or maybe there is. Lazyweb?

May
2nd
Fri
permalink

An update in a really long while

Woah, one month with no updates.

I started contracting for a startup in Seattle, WA since beginning of April and have been neglecting to update stuff. It’s pretty nice here plus I get to access things that people here take for granted like attending Seattle.rb hack nights, Pandora, Hulu and this weekend, Barcamp Portland!

See you guys in a bit.

Apr
1st
Tue
permalink
Mar
30th
Sun
permalink

Updating Counter Cache in Migrations

I’m nearly complete with an app I’ve been working on, so I thought I’d dedicate some time for optimization. One of the first things I did to my models was to add counter caches so that performing counts on my association were fast.

First try,

class AddCommentCounterCacheOnTopics < ActiveRecord::Migration
  def self.up
    add_column :topics, :comments_count, :integer, :default => 0
  end

  def self.down
    remove_column :topics, :comments_count
  end
end

Very standard. However, it initializes the column to 0, effectively “losing” all my comments (they’re there in the DB, but Rails adds an additional optimization whereby it won’t fetch the association if the counter cache is 0). Looks like I need to update the comments_count column to whatever it was at the time of migration.

Second try,

class AddCommentCounterCacheOnTopics < ActiveRecord::Migration
  def self.up
    add_column :topics, :comments_count, :integer, :default => 0

    Topic.find(:all).each do |t|
      t.comments_count = t.comments.count
      t.save!
    end
  end

  def self.down
    remove_column :topics, :comments_count
  end
end

Two things to note: First, I’m using the #count method in t.comments.count because calling #size will use the value in t.comment_count which is 0. #count on the other hand will perform a SQL count(). Second, this won’t work! Why? Because counter cache columns are set to attr_readonly.

To work around this, a little hack. Final result,

class AddCommentCounterCacheOnTopics < ActiveRecord::Migration
  def self.up
    add_column :topics, :comments_count, :integer, :default => 0

    def Topic.readonly_attributes; nil end # A little evil hack

    Topic.find(:all).each do |t|
      t.comments_count = t.comments.count
      t.save!
    end
  end

  def self.down
    remove_column :topics, :comments_count
  end
end
Fork me on GitHub