Mac as a Development platform

I sometimes feel as if I spend half my time making fixes caused by Apple upgrades.

This morning I found my previously hand-crafted php.ini had been removed.

So, each time Apple does an upgrade I have to go back in and update php.ini with various customizations (like max post size, etc).

This also happened to Apache. Apple did an upgrade and I lost my virtualhosts.

And other things change too – like I now have to use mysql.server start rather than using mysqld. I can understand that things need to change but why not provide a graphic tool and just change things under the hood.

Now I try restarting MySQL and I get:

Starting MySQL
. ERROR! The server quit without updating PID file (/usr/local/var/mysql/

So clearly another update has happened that I’ll need to fix.

My experience on Linux has always been much smoother. I’m starting to wonder if I should try using it again as a development platform.

Ubuntu: start/stop mysqld

If you use the init.d script on Ubuntu, e.g. 

sudo /etc/init.d/mysql restart

you may get this message:

Rather than invoking init scripts through /etc/init.d, use the service(8)

utility, e.g. service mysql restart

Since the script you are attempting to invoke has been converted to an

Upstart job, you may also use the stop(8) and then start(8) utilities,

e.g. stop mysql ; start mysql. The restart(8) utility is also available.

mysql stop/waiting

mysql start/running, process 25974

Latin vs UTF-8

Latin is a single-byte encoding.

So, non-Latin characters will break if you try to display them using a Latin encoding.

UTF-8 is potentially a 3 byte encoding and can encode a great deal more. 

Here’s a Unicode/UTF-8 character table:

If you’re using MySQL, here’s how to ALTER the table to convert to the UTF-8 character set. Note there’s a slight subtlety here in that, because of the extra bytes used by UTF-8, unless you specify the column type it might roll over to the next larger column type size. E.g. for VARCHAR:

ALTER TABLE table_name MODIFY column_name VARCHAR(255) CHARACTER SET utf8;

ActiveRecord without Rails

Say you want ORM with a console script.

Here’s how you could do it using ActiveRecord without Rails.

1. create a database YAML file (a la Rails) 

2. Use the ActiveRecord::Base.establish_connection

Super simple. E.g. 

require ‘rubygems’

require ‘active_record’

require ‘yaml’

require ‘mysql2’

require ‘logger’

dbconfig = YAML::load(‘database.yml’))


class People < ActiveRecord::Base


puts People.count

(assuming you had a MySQL database table called ‘people’) with a database.yml like this:

adapter:  mysql2

database: your_database

username: user

password: your_pass

host:     localhost

and you could log it using:

ActiveRecord::Base.logger =

See also:

Bundler Groups

From Katz’ great post:

Specifying groups allows you to do two things. First, you can install the gems in your Gemfile, minus specific groups. For instance, Rails puts mysql and pg in a database group so that if you’re just working on ActionPack, you can bundle install –without db and run the ActionPack tests without having to worry about getting the gems installed.

Second, you can list specific groups to autorequire using Bundler.require. By default, Bundler.require requires all the gems in the default group (which is all the gems that have no explicit group). You can also say Bundler.require(:default, :another_group) to require specific groups.


Ruby on Rails with Apache and MySQL on Mac OS X Snow Leopard

Snow Leopard is a gnarly old beast.

However, I left my Mountain Lion laptop with someone when visiting and needed to use my old backup Mac running Snow Leopard.

Some hints on how to get stuff (MySQL / Rails) working: