Subscribe to XML Feed
12 Apr 2010

Toggle CSS3 Bookmarklet

If you’ve begun to use CSS3 experimental features in your sites lately such as box-shadow, border-radius or text-shadow, you know how much pain it can take away from the design process. Unfortunately, lots of people are still using Internet Explorer and can’t see all these pretty additions you’ve added.

I thought it would be useful to have a simple way to run a sanity check on my design to make sure it wasn’t going to look awful or unreadable once all of the CSS3 goodies were taken away. With that in mind, I created a bookmarklet that will toggle the display of all of that modern goodness.

Just drag this link: Toggle CSS3 into your bookmark toolbar. Then, by clicking it, you can turn off (and back on) the most common CSS3 improvements. Once installed, if you visit a page such as CSS3.info and click the bookmarklet, you should see the CSS3 effects toggle off.

Note that this is a simple, none-too-bright bookmarklet and only removes the obvious traces of CSS3. It doesn’t inspect your CSS for non-supported color values (like RGBA) or deal with many of the more advanced features of CSS3. In fact, all it does is eradicate these styles:

  • border-radius
  • box-shadow
  • text-shadow
  • border-image
  • background-origin
  • background-clip

However, it’s still a useful tool if you’re designing for the future with an eye for the past. Enjoy!

View Comments
29 Mar 2010

Ruby Quick Tip: Regular Expressions in Case Statements

Did you know that you can use regular expressions in case statements in Ruby to check for a match? For instance, if I’m implementing some method_missing functionality and I want to check for bang or question methods, I might be tempted to do something like this:

def method_missing(name, *args)
  name = name.to_s
  if name.match(/!$/)
    puts "Bang Method!"
  elsif name.match(/\?$/)
    puts "Query Method?"
  else
    super
  end
end

But it’d be much cleaner if instead it looked like this:

def method_missing(name, *args)
  case name.to_s
    when /!$/
      puts "Bang Method!"
    when /\?$/
      puts "Query Method?"
    else
      super
  end
end

This is great, but now what if we want to call out a method for bang and question methods? Thankfully Ruby has us covered there as well:

def method_missing(name, *args)
  case name.to_s
    when /^(.*)!$/
      bang_method($1)
    when /^(.*)\?$/
      question_method($1)
    else
      super
  end
end

By using the $1 global variable we can access the last regular expression match performed by ruby. This is just one of those little details that makes working with Ruby such a joy.

View Comments
05 Mar 2010

Hashie Gains a Chainable Hash

Hashie, Intridea’s Hash Toolkit, is today with version 0.2.0 gaining a new member: the Clash.

A Clash is a “Chainable Lazy Hash” that allows you to construct a hash using method syntax. It is meant to be used in a similar way to the way that Rails 2.x’s named_scope or Arel’s query building work. Let’s start with an example:

require 'hashie/clash'

c = Hashie::Clash.new
c.where(:abc => 'def').order(:created_at)

c == {:where => {:abc => 'def'}, :order => :created_at}

Pretty neat, right? But you can go beyond that. Clash also allows you to use bang method notation to create, dive into, and return from sub-hashes. Let me show you what I mean:

c = Hashie::Clash.new
c.where!.abc('def').ghi(123)._end!.order(:created_at)

c == {:where => {:abc => 'def', :ghi => 123}, :order => :created_at}

By using a bang method, you automatically create a subhash that is then the subject of the chain, allowing you to create more keys on that subhash. Then, if you want to jump back up to the top-level hash, you simply call the _end! method to return up one level in the stack (thanks to jQuery for that particular inspiration).

While Clash is a very simple tool, we hope that it could eventually make its way into some of the new ORMs that are cropping up around NoSQL systems (such as MongoMapper) to provide the same kind of effortless chaining that has made ActiveRecord so easy to work with.

View Comments
12 Feb 2010

Redfinger: A Ruby WebFinger Gem

Just yesterday, Google turned on webfinger for all GMail accounts. Today, I’m releasing a RubyGem to help you use the new protocol!

What’s a WebFinger?

WebFinger is a new protocol for extracting public information about a person via their e-mail address. It is meant to complement systems such as OpenID as well as give a simple way to get basic information about a user without having to ask them for it.

E-Mail providers can implement WebFinger by creating a special URL (specifically at /.well-known/host-meta) that is an XRD XML document telling the requester a URL at which they can find out more about e-mail addresses on their domain. Google’s, for example, is http://www.google.com/s2/webfinger/?q={uri}. When the WebFinger endpoint is requested with an e-mail address in place of {uri}, Google looks up information about that e-mail’s public profile and provides it in a standardized XRD XML format.

So why WebFinger when OpenID already exists? Users are used to associating their e-mail address with their identity. It’s natural since an e-mail address is (usually) for a specific person. By putting a protocol in place to find out more about an e-mail address without requiring additional input from the user, a host of options become available.

For instance, if I’m an application looking to authenticate using OpenID, I can ask a user for their e-mail address instead of their OpenID URL (something that will confuse mainstream users to no end). Or, if I want to automatcially fill in basic profile information, I can check to see if a parseable profile page is available in a format such as hCard.

Enter Redfinger

Redfinger is a library built to easily consume the WebFinger protocol. Installing it is simple:

gem install redfinger

Using it is just as simple:

require 'rubygems'
require 'redfinger'

finger = Redfinger.finger('youraccount@gmail.com')
finger.open_id.first.to_s # => "http://www.google.com/profiles/youraccount"

Redfinger will query the host of the e-mail domain specified, and, if the Webfinger protocol is supported, retrieve information about that e-mail address including such links as OpenID Provider, hCard URL, and more.

How can you use this today? Well, if you’re an OpenID consumer you can use the above code to try to “intelligently find” an OpenID endpoint from an e-mail address. Of course, it will just about only work with Google at the moment (this is an alpha protocol, after all). Or, you could install the mofo gem (a gem for parsing microformats for web pages) and do some neat things with microformats:

require 'rubygems'
require 'mofo'
require 'redfinger'

finger = Redfinger.finger('account@gmai.com')
card = hCard.find(finger.hcard.first.to_s)
card.fn # => "That GMail user's full name"
card.title # => "The title he/she entered on Google Profile"

Here Redfinger determines a URL that will have hCard information about the e-mail address specified, and the Mofo gem goes out and fetches that address, parsing out the information.

WebFinger is still brand new (Google calls it “alpha”) but it shows some promise for being a great way to make the open web more seamless for users. As always, the Redfinger source code is available on GitHub and RDoc Documentation is available. Check it out!

View Comments

Older Posts

Simple Mustache JSON Serialization 21 Jan 2010 Comments
Compiling Mustache Views for Mustache.js 18 Nov 2009 Comments
Hashie: The Hash Toolkit 12 Nov 2009 Comments
Rails Quick Tip: Readable Conditional Validation 03 Nov 2009 Comments
TweetStream: Ruby Access to the Twitter Streaming API 22 Sep 2009 Comments
CouchDB-Lucene, CouchDBX, and CouchRest 21 Sep 2009 Comments
A Fresh Coat of Paint 20 Sep 2009 Comments
Good Idea, Bad Idea: Rails Rumble Post-Mortem 24 Aug 2009 Comments
Quick Tip: Railsy Array Checks in jQuery 19 Jun 2009 Comments
Make it so with RSpec Macros 15 May 2009 Comments
TwitterAuth Supports 'Sign in with Twitter' 17 Apr 2009 Comments
Present.ly Nominated for the WebWare 100 31 Mar 2009 Comments
Using Git Submodules for Shared Application Components 25 Mar 2009 Comments
TwitterAuth: For Near-Instant Twitter Apps 23 Mar 2009 Comments
Yet Another Twitter Monetization Strategy: 'Claimed' Hashtags 18 Mar 2009 Comments
The Case For GitHub Canonization 03 Mar 2009 Comments
Quick Tip: Rails URL Validation 18 Feb 2009 Comments
Utilize Canonical URLs in Your Rails Apps 13 Feb 2009 Comments
Outsource Your Blog 11 Feb 2009 Comments
Open Source Is Amazing 11 Feb 2009 Comments
Moving to Jekyll 10 Feb 2009 Comments
It's No Joke - Real-Time Search is a Big Deal 09 Feb 2009 Comments
SASS: The Better, More Powerful CSS 04 Feb 2009 Comments
Use MacFUSE to Make a Boxee Torrent Dropbox 02 Feb 2009 Comments
The Case For Web Applications 02 Feb 2009 Comments
HasAvatar: Defining an Application Vocabulary 28 Jan 2009 Comments
Twitter Search Plus: Find Replies Inline With Twitter Search 22 Jan 2009 Comments
Sort Your Files By Date 04 Dec 2008 Comments
The Importance of External Downtime Resources 28 Nov 2008 Comments
Hacking the Mid-End (Great Lakes Ruby Bash Edition) 11 Oct 2008 Comments
Colorist: Color Manipulation for Web Heads 18 Aug 2008 Comments
Fetches: Bringing Your ActionController Its Slippers 28 Jul 2008 Comments
Using HTTP Status Codes for Rails AJAX Error Handling 23 Jul 2008 Comments
UberKit Update: UberForms to Ease Form Building 14 Jul 2008 Comments
UberKit: Building a Rails UI Swiss-Army Knife 07 Jul 2008 Comments
What the World Needs Now is CSS3 02 Jul 2008 Comments
Using RSpec and Autotest While Writing Rails Plugins 25 Jun 2008 Comments
SubdomainFu: A New Way To Tame The Subdomain 23 Jun 2008 Comments
GemPlugins: A Brief Introduction to the Future of Rails Plugins 11 Jun 2008 Comments
ActsAsTaggableOn Grows Up 09 Jun 2008 Comments