Command-tab exposé trick on Mac OS X

Quick nifty tip: To run exposé for all windows for a specific application, either “long click” an application icon in the dock, or hold down the command key, hit tab until you’re highlighting the application you want to pick a window from, and click the down cursor key. You’ll see an exposé view for the windows for that application.

Still holding command down, If you hit tab again, you’ll see exposé for the next application. The current application will be highlighted in the dock.

Neat, eh?

Rails 3.0.5 broke my routes and kicked my dog

We just upgraded AdGrok from Rails 3.0.4 to 3.0.5, which was released a couple days ago. This is a “patch release,” which according to the rules, has only backwards compatible bug fixes.

A bunch of our integration tests failed before we pushed to production, and we found out that a pretty big change was introduced: namespaced urls are now prefixed by the namespace, and before 3.0.5 (like, 3.0.4), they weren’t.

Here’s the simplest example of what’s going on:

Continue reading

HOWTO: Force https with Amazon Elastic Load Balancer and Apache

The Amazon ELB service now supports https, which is great, but how do you configure Apache such that it redirects all insecure requests to use a secure connection?

It turns out that the ELB adds a X-Forwarded-Proto header that you can capture with a mod_rewrite rule. Here’s the configuration snippet:

<VirtualHost *:80>
  ...
  RewriteEngine On
  RewriteCond %{HTTP:X-Forwarded-Proto} !https
  RewriteRule !/status https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
</VirtualHost>

(this assumes your health check is /status, which doesn’t require https)

Securely deleting files

I needed to switch cellphones, and given that my cell’s SD card had sensitive data, just formatting the card wasn’t sufficient — it’s trivial to recover files from high-level-formatted FAT file system.

I present to you the world’s most dangerous (unix) command:

 find /path/to/mounted/SDcard -type f -print0 | xargs -0 shred -z -u

(shred is part of the coreutils package, so it should be installed already)

Faster MySQL dumps and loads with –tab and –use-threads

By default, mysqldump writes a series of sql DDL and inserts to standard out, that you can then pipe to another database server to recreate a given database.

The problem is that this is all serial, and if you’re having to do this task regularly (because you’re sharing databases between different development environments, for example), it’d be nice if this could be sped up, and it certainly can with the current 5.1.x versions of MySQL.

Continue reading

HOWTO: simulate the cron environment

While banging my head on RVM + Rails 3 + crontabs, it became clear that I needed the cron environment in an interactive shell. It’s not hard:

sudo su
env -i /bin/sh

If your SHELL in your crontab is /bin/bash:

sudo su
env -i /bin/bash --noprofile --norc

Remember that the cron-invoked shell won’t have a tty, so some commands will behave differently. Also, if you’ve got a bunch of other environment variables set up in your crontab, you can do this trick from stackoverflow — create a one-off cron that writes env to a file, and load that env later.

HOWTO: Force https/SSL for Apache2, Phusion Passenger and Rails

There’s a lot of buzz right now about Firesheep and non-secure Rails applications.

This is a pretty simple problem to solve with Apache’s mod_rewrite. If the traffic isn’t on https, force it to be. This configuration only needs to be in production, of course.

Here’s /etc/apache2/sites-enabled/adgrok:

Continue reading

Switching between Rails 2 and Rails 3 on Mac OS X or Ubuntu with RVM

I’m migrating AdGrok to Rails 3 this weekend–what with the new ActiveRecord query functionality, and MongoMapper, and all our gems migrating to Rails 3, it seems like it’s time.

The Railscast (and ASCIIcast) is great, but a couple steps are now outdated. There also aren’t any instructions on how to switch between rails 2 and rails 3 gracefully.

Continue reading