How to fix "extconf.rb:8:in `require': no such file to load -- mkmf (LoadError)"

Ruby gem installation can fail with LoadError for mkmf when Ruby header files are missing, often resolved by installing the platform’s Ruby development package.

Setting up Tomcat to use an existing OpenSSL certificate

Convert an existing OpenSSL certificate and private key into a Java keystore for Tomcat HTTPS, avoiding JSSE configuration errors and alias mismatches.

Restrict Apache access to your local computer

Apache development servers can accept connections from other machines on the network. Binding Listen to 127.0.0.1 limits access to the local computer.

Styling and scaling for mobile devices

Mobile pages need a dedicated stylesheet and viewport settings so iPhone, iPad, and Android layouts fit small screens without awkward scaling.

Shell script to clean up a project directory

Remove unused and unnecessary files from a project root with geordi clean, a cleanup command in the Geordi gem.

Speed up RSpec by deferring garbage collection

Deferred Ruby garbage collection can speed up RSpec examples by reducing GC overhead, though gains vary and may be negligible in newer Ruby versions.

Computational cost of SSL connections

In January this year (2010), Gmail switched to using HTTPS for everything by default. Previously it had been introduced as an option, but now all of our users use HTTPS to secure their email between their browsers and Google, all the time. In order to do this we had to deploy no additional machines and no special hardware. On our production frontend machines, SSL/TLS accounts for less than 1% of the CPU load, less than 10KB of memory per connection and less than 2% of network overhead. Many people believe that SSL takes a lot of CPU time and...

Silencing Deprecation Warnings in Rspec

Deprecated Ruby tests can flood RSpec output with warning noise. A narrower way to quiet them avoids hiding warnings from dependencies.

Iterate over every n-th element of a Range in Ruby

Use Range#step to visit every n-th value in a Ruby range, useful for date sequences such as weekly Mondays. Rails and ActiveSupport return an array when no block is given.

Upgrade from Rails 2.3.8 to Rails 2.3.10

Rails 2.3.8 to 2.3.10 upgrades can reduce bugs and security risk in older applications.

Apache: Log the original client IP when your site sits behind a reverse proxy

Apache logs behind a reverse proxy show the proxy IP instead of the original client IP, complicating troubleshooting and traffic statistics.

Test a download's filename with Cucumber

Verify that a server response suggests the expected download name in a Cucumber scenario, using Capybara or Webrat to check the Content-Disposition header.

Test the content-type of a response in Cucumber

Check a download or page response by its MIME type in Cucumber, using Webrat or Capybara; the Selenium webdriver does not support this approach.

Cucumber steps to test input fields for equality (with wildcard support)

Exact form-field matching in Cucumber prevents false positives from partial values, while wildcards allow flexible contains-style checks.

Default block arguments for Ruby 1.8.7

Ruby 1.8.6 and 1.8.7 do not support default block arguments; a lambda workaround uses *args and assigns missing values manually.

Git: See all unpushed commits or commits that are not in another branch

Local commits missing from a remote or upstream branch are easy to identify with git cherry -v, which lists the commits not shared by both branches.

Creating Liquid Layouts with Negative Margins

I was recently confronted with the task of creating a two-column liquid layout with a header and footer in which the content needed to come before the sidebar in the source code. I took opportunity to demonstrate an under-used aspect of CSS: negative margins. Negative margins allow us to push the content area away from the sides of the browser, leaving room for the sidebar.

Git: Define a custom merge driver

The ‘merge.*.driver` variable’s value is used to construct a command to run to merge ancestor’s version, current version and the other branches’ version. The merge driver is expected to leave the result of the merge in the file named with %A by overwriting it, and exit with zero status if it managed to merge them cleanly, or non-zero if there were conflicts.

Overriding unary operators in Ruby

This must be one of the coolest, yet quite unknown, technique in Ruby. For certain types of problems (e.g. when you have a set of rules) this gives you such an elegant way of describing the solution. There’s no meta programming or monkey patching involved, it’s short and sweet and best of all: it’s very intuitive.

Apache: Redirect all requests from one host to another

Redirecting all requests from one host to another preserves path and query string while avoiding duplicate hosts and broken links.

Word boundaries in MySQL regular expressions

MySQL lacks \b word boundaries in regular expressions, so word-start and word-end matching requires MySQL-specific markers instead.

Apache: Require username/password authentication except from a single IP, host or network

Apache Basic auth can stay enabled while a specific IP, host, or network bypasses login by combining access rules with Satisfy any.

Parametrized shared example groups in RSpec

Parameterized shared examples make reusable RSpec behavior checks accept arguments and blocks, avoiding duplicated expectations across similar specs.

Rails for Zombies

Learning Rails for the first time should be fun, and Rails for Zombies allows you to get your feet wet without having to worry about configuration. You'll watch five videos, each followed by exercises where you'll be programming Rails in your browser.