Open the on-screen keyboard on an iPhone or iPad with Javascript

There is no way to do it. This behavior is by design. You lose.

Opera 11: Show full address, including GET parameters

By default, Opera 11 hides any passed params and the URL's protocol until you focus the address bar.

To disable hiding URL parameters, open up Tools → Preferences (Ctrl+F12) → Advanced → Browsing and check "Show full web address in address field". No need to touch opera:config.

The badge that displays the page's "zone" (Web, Secure, Opera, …) will be shrinked so you can still see a yellow lock for proper SSL connections, etc.

Cast an ActiveRecord to a subclass or superclass

ActiveRecord models have with a method becomes(klass) which you can use to cast the record into an instance of its subclasses or superclass. This is useful because some parts of Rails reflect on the class of an instance, e.g. to decide which partial to render:

Returns an instance of the specified klass with the attributes of the current record. This is mostly useful in relation to single-table inheritance structures where you want a subclass to appear as the superclass. This can be u…

Safely chain scopes with hash conditions

There is a nasty bug in all version of Rails 2 and some versions of Rails 3.x where two chained scopes with hash conditions on the same attribute would overwrite each other. We are trying to get this patched for a future 2.3.x maintenance release. Until then this note provides a crude workaround.

Copy the attached initializer into your project. You …

Making IE 9 happy

If you're using jQuery, you need to update to 1.5.1 to get Internet Explorer 9 to work.

Apart from that there seem to be surprisingly few problems. Many CSS3 attributes work and no major layout problems at first glance.

I only recommend to take a look at your box shadows, since IE does render those a bit differently (generally lighter and offset by what looks to be half a pixel).

Test that a hash contains a partial hash with RSpec

Our rspec_candy gem has a matcher that lets you test whether a hash includes an expected sub-hash:

user.attributes.should include_hash(:name => 'Bruce Wayne')

Note that RSpec also comes with a matcher hash_including, but that is only for matching arguments in should_receive expectations:

User.should_receive(:create!).with(hash_including(:name => 'Bruce Wayne'))

We have a note on where to put custom RSpec matchers.

Installing RMagick on Ubuntu

When installing RMagick you may get an error message like this:

checking for Ruby version >= 1.8.5... yes
checking for gcc... yes
checking for Magick-config... no
Can't install RMagick 2.13.1. Can't find Magick-config in /home/arne/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/var/lib/gems/1.8/bin

*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for ...
External content

Default views in Rails 3.0 with custom resolvers

It is common in Rails 3.0 applications that you want to provide default views for a group of controllers. Let’s say you have a bunch of controllers inside the Admin namespace and you would like each action to fallback to a default template. So if you are rendering the index action for Admin::PostsController and “app/views/admin/posts/index.html.*” is not available, it should then render “app/views/admin/defaults/index.html”.

Since Rails 3.0, we have a new abstraction called resolvers that holds the logic to find a template.

External content


Artifice allows you to replace the Net::HTTP subsystem of Ruby with an equivalent that routes all requests to a Rack application.

You can use Sinatra, raw Rack, or even Rails as your application, allowing you to build up an equivalent to the remote service you are mocking out using familiar and convenient tools to route requests and build up responses.

Weird margin at top of page

If there is some weird margin at the top of your page for no apparent reason, chances are one of your views contains a BOM (Byte Order Mark).

To remove it, open the file with VIM, and type

:set nobomb
External content

Download all Google Web Fonts as a single tarball

Google’s Font Directory and API for web fonts could have a transformative effect on how we read the web. The only problem is, Google has made it very difficult to download all of the actual font files.

Web designers must be free to experiment with these new fonts, to sketch, comp and get to know these typefaces in browser and non-browser applications. This is why I’m providing this archive.

Different CSS for IE using Sass

At times, it might be unavoidable to have different CSS rules for Internet Explorer than for sane browsers. Using Sass, this can be achieved in a relatively non-hackish way without CSS hacks.

Step 1

Move your current Sass file into a partial. Let's assume it was called screen.sass. Rename it _screen.sass.

Step 2

Create two new Sass files:

Call this one screen.sass:

$ie = false
@import screen

Call this one screen_for_ie.sass:

$ie = true
@import screen

Step 3

Change y…

Opera: How to use outlining for better layout debugging

I prefer using Opera's "User mode" to toggle an outlining of HTML elements quickly. This helps greatly when you want to see the actual dimensions of elements, e.g. for floating elements inside containers, instead of opening up the Dragonfly inspector every time.

Navigate to View → Style → "Manage Modes…" and tick the checkboxes like in the attached image. Then, switch to the User Mode by pressing the shortcut (Shift+G for the 9.2-compatible layout or for the default layout with enabled "single-key shortcuts") and select "Outline" from…

How to send a test e-mail from shell

If you want to manually check if e-mail delivery works on a machine by sending an e-mail you can run the following:

mail -s Test < /dev/null

This will send an empty e-mail with "Test" as its subject to

If you want it to contain a message body, call mail -s Test only; the mail application will then read your input from stdin. Finish your message by sending EOT with Ctrl-D – if you are asked for anything else …

External content


mitmproxy is an SSL-capable, intercepting HTTP proxy. It provides a console interface that allows traffic flows to be inspected and edited on the fly.

External content

Imperative vs Declarative Scenarios in User Stories

Bryan talked about the differences between imperative and declarative scenarios. In my opinion, both styles have benefits and should be used appropriately based on the situation. The majority of examples on rspec's story runner currently on the web, including mine, are of the imperative type. Since the declarative type has many advantages I thought it would be worth while to present some examples and contrast the differences between the two styles.

Where to put custom RSpec matchers

When you write a custom RSpec matcher a good place to store them is to create one file per matcher in spec/support/matchers:


You can include all matchers in the support directory by adding the following line to your spec_helper.rb:


Do not deliver mails when there are no recipients set

When using ActionMailer, you can set an array of email addresses as recipients. If this array is generated by e.g. collecting email addresses from the database, it might sometimes be empty.

To prevent ActionMailer to deliver mails to nobody, simply overwrite the deliver! method like this:

# In your mailer.rb
def deliver!(mail = @mail)
  return false if (recipients.nil? || recipients.empty?) && (cc.nil? || cc.empty?) && (bcc.nil? || bcc.empty?)
2391 cards