Simple 301 or 302 redirects with Apache & PHP

It behooves you to make sure you’ve only got one URL that serves a given piece of content–so says google. But what if you’ve got a bunch of domains that go to your page?

For this blog, for example, matthew.mceachen.org, and mrm.mceachen.org all go to the same place. That was done with an apache redirect in /etc/apache2/sites-enabled/matthew:

Continue reading

Posted in Technical HOWTOs | Tagged , , | Leave a comment

HOWTO: Configure an Amazon RDS instance to use UTF-8

RDS has been working out pretty well for AdGrok — it’s a one-click MySQL 5.1 instance that seems pretty promising:

  • Automatic replication and failover to another deployment zone (colo)
  • Easy to set up firewall configuration
  • Easy to scale up (but not down) for CPU and disk space

If you’re just starting out, it’s a whole lot simpler than, say, a DRBD/Heartbeat/MySQL configuration running on EC2 instances.

There’s just one catch. It doesn’t use UTF-8 encoding by default, it uses latin1_swedish. If you’re going to do business outside the US, utf8 is a must.

The second catch — the Amazon web UI for managing RDS “parameter groups” is read-only. If you know the magick incantations, though, it’s not that bad. Here’s how to make it all go:

Continue reading

Posted in Technical HOWTOs | Tagged , , , | Leave a comment

HOWTO: Mount your USB hard drives at boot time on Ubuntu

I’ve got a number of external USB hard drives connected to my ubuntu server that need to mount to a predictable directory.

When you log into Gnome, the desktop environment does it’s nifty thing and mounts any drive you’ve got plugged in — but if the box reboots, the drives won’t be mounted until the next person logs into the computer.

I needed something that happens at boot time to do this task.

Continue reading

Posted in Technical HOWTOs | Tagged , , , , , | Leave a comment

Dailed-in Rails script/console with pretty printing and history

Edit (as root) your /etc/irbrc:

# Some default enhancements/settings for IRB, based on
# http://wiki.rubygarden.org/Ruby/page/show/Irb/TipsAndTricks
 
unless defined? ETC_IRBRC_LOADED
 
  # Require RubyGems by default.
  require 'rubygems'
 
  begin
    require "ap"
    IRB::Irb.class_eval do
      def output_value
        ap @context.last_value
      end
    end
  rescue LoadError => e
    puts "ap gem not found.  Try typing 'gem install awesome_print' to get super-fancy output."
  end
 
  # Activate auto-completion.
  require 'irb/completion'
 
  # Use the simple prompt if possible.
  IRB.conf[:PROMPT_MODE] = :SIMPLE if IRB.conf[:PROMPT_MODE] == :DEFAULT
 
  # Setup permanent history.
  HISTFILE = "~/.irb_history"
  MAXHISTSIZE = 100
  begin
    histfile = File::expand_path(HISTFILE)
    if File::exists?(histfile)
      lines = IO::readlines(histfile).collect { |line| line.chomp }
      puts "Read #{lines.nitems} saved history commands from '#{histfile}'." if $VERBOSE
      Readline::HISTORY.push(* lines)
    else
      puts "History file '#{histfile}' was empty or non-existant." if $VERBOSE
    end
    Kernel::at_exit do
      lines = Readline::HISTORY.to_a.reverse.uniq.reverse
      lines = lines[-MAXHISTSIZE, MAXHISTSIZE] if lines.nitems > MAXHISTSIZE
      puts "Saving #{lines.length} history lines to '#{histfile}'." if $VERBOSE
      File::open(histfile, File::WRONLY|File::CREAT|File::TRUNC) { |io| io.puts lines.join("\n") }
    end
  rescue => e
    puts "Error when configuring permanent history: #{e}" if $VERBOSE
  end
 
  ETC_IRBRC_LOADED=true
end

Thanks to Nick Sieger and Jared Haworth for sharing.

Posted in Technical HOWTOs | Tagged | 2 Comments

Simple MySQL backup to gmail on Ubuntu/Debian

Backing up your MySQL database (if it’s a reasonable size, like < 100s of MB) can be done with a cronjob that runs mysqldump, gzip, and mpack.

Continue reading

Posted in Technical HOWTOs | Tagged , , | Leave a comment

HOWTO enable the query log on MySQL on Mac OS X

Tailing the MySQL query log in real time can be a lifesaver for any developer, and it’s pretty easy to do:

Make a file for the mysqld process to write to:

sudo touch /var/log/mysql-query.log
sudo chown _mysql /var/log/mysql-query.log

If you’ve installed MySQL 5.1.x from the Mac .pkg, you won’t have an /etc/my.cnf, but it just needs to have these two lines:

[mysqld]
log=/var/log/mysql-query.log

Restart MySQL by opening the MySQL preference pane, click stop, then start, then tail -f /var/log/mysql-query.log. It turns out that when the preference pane is open, it pings the database every 2 seconds, so it can detect if the db is alive. If you mangle the my.cnf, you’ll find the start button seems to not respond to clicks.

(I found this link only after I found out what I needed to do…)

Posted in Technical HOWTOs | Tagged , | Leave a comment

How to view only unread gmail conversations

Gmail doesn’t have an obvious way to only look at conversations that are unread. If you don’t “archive” conversations out of your inbox, it can get pretty crufty.

It’s easy add a bookmark to just view unread conversations, however:

Continue reading

Posted in Technical HOWTOs | Tagged | Leave a comment

Installing Phusion Passenger on Ruby 1.9.1, Nginx, & Ubuntu 10.04

Getting ruby 1.9.1 and nginx and passenger and ubuntu to all play nicely is fairly straightforward, but it’s not just “apt-get” and “gem install” lovin’.

Making ruby 1.9.1 the default ruby is OK. Follow these steps:

Continue reading

Posted in Technical HOWTOs | Tagged , , , , | Leave a comment

Set up JAVA_HOME to track Java Preferences.app on Mac OS X

/Applications/Utilities/Java Preferences.appMac OS X’s Java Preferences.app has a pane for switching between versions of the JDK, but I just found out from a coworker (thanks, Mike!) that you can make your shell match that preference easily — just add this to your ~.bashrc:

export JAVA_HOME=$(/usr/libexec/java_home)

If you change your JDK priority preference, you’ll need to re-source your ~/.bashrc or just open a new terminal window.

Posted in Technical HOWTOs | Tagged , , , , , | 2 Comments

Deliberate Change Management

Software engineering can be described as the orchestration of a quasi-denumerable set of moving parts.

With so many moving parts, breakages occur. One main goal as a “software craftsperson” is to never expose customers to the affects of these breakages. Test-driven development rose from this desire. Accepting that systems break, even in production, motivated loosely coupled and shared-nothing system architectures.

Continue reading

Posted in Software Development Mantras | Tagged , , | Leave a comment