I reinstalled Mac OS X Lion in Golden Week. 

Clean install by Bootable USB Memory at first.

System Preferences

System Preferences

  • Keyboard
    • Keyboard
      • Delay Until Repeat
        • Shortest
      • Use all F1, F2, etc. keys as standard functions keys [X]
      • Modifier Kyes
        • Caps Lock
          • Control
    • Keyboard Shortcuts
      • Application Shortcuts
        • +
          • Application: All Applications
          • Menu Title: Zoom
          • Cmd-Enter
        • +
          • Application: Terminal
          • Menu Title: Select Next Tab
          • Cmd-]
        • +
          • Application: Terminal
          • Menu Title: Select Previous Tab
          • Cmd-[
        • Full Keyboard Access:In windows and dialogs, press Tab to move keyboard focus between:
          • All controls
      • Mouse
        • Point & Click
          • Scroll direction: natulal [ ]
      • Dock
        • Automatically hide and show the Dock [X]
      • Energy Saver
        • Power Adapter
          • Computer sleep
            • 3 hrs
          • Display sleep
            • 3 hrs
      • Spotlight
        • Search Results
          • Spotlight menu keyboard shortcut: [ ]
          • Spotlight window keyboard shortcut: [ ]
      • Date & Time
        • Clock
          • Use a 24-hour clock [X]
          • Show date [X]
      • Desktop & Screen Saver
        • Screen Saver
          • Start screen saver: Never
      • Software

        Applications

        Software from App Store

        Purchases

        • Keynote
        • Xcode
        • Echofon Lite for Twitter
        • iShowU
        • Skitch
        • The Unarchiver
        • MPlayerX

        Other

        • Software Update
        • Remove all icons from Dock

        Auto start movies on QuickTime X

        $ defaults write com.apple.QuickTimePlayerX MGPlayMovieOnOpen 1

        Accelarate a keyrepeat

        $ defaults write NSGlobalDomain KeyRepeat -int 1

        And reboot.

        Show dot files in Finder

        $ defaults write com.apple.finder AppleShowAllFiles TRUE
        $ killall Finder

        Disable the “Is An Application Downloaded from the internet” Warning

        $ xattr -d -r com.apple.quarantine ~/Downloads

        Disable Dashboard

        $ defaults write com.apple.dashboard mcx-disabled -boolean YES
        $ killall Finder

        Hide a last login date

        $ touch ~/.hushlogin

        Terminal

        Terminal — zsh — 80×24

        • Preferences
          • Settings
            • Text
              • Monaco 14 pt
            • Window
              • Scrollback
                • Limit number of rows to: 10000
          • Shell
            • When the shell exits:
              • Close if the shell exitd cleanly

        Development Environment

        Xcode

        • Preferences
          • Downloads
            • Components
              • Command Line Tools
                • Install

        Android

        Download and Install Android SDK

        ssh

        $ cp -r /BACKUP_DIR/.ssh ~/

        zsh

        $ chsh -s /bin/zsh

        dotfile

        komagata / dotfile / source — Bitbucket

        bitbucket is pretty good for dotfile repos. because private repos is free.

        $ git clone git@bitbucket.org:komagata/dotfile.git ~/code/dotfile
        $ cd ~/code/dotfile
        $ ruby symlink.rb
        $ source ~/.zshrc

        vim

        Terminal — vim — 80×24

        .vimrc and plugins is contained dotfiles directory.

        Plugins:

        Bundle ‘The-NERD-tree’
        Bundle ‘quickrun’
        Bundle ‘fakeclip’
        Bundle ‘tpope/vim-rails’
        Bundle ‘vim-ruby/vim-ruby’
        Bundle ‘Shougo/neocomplcache’

        rvm

        $ curl -L get.rvm.io | bash -s stable
        $ source ~/.rvm/scripts/rvm
        $ rvm requirements

        homebrew

        $ /usr/bin/ruby -e “$(/usr/bin/curl -fsSL https://raw.github.com/mxcl/homebrew/master/Library/Contributions/install_homebrew.rb)”
        $ brew install libksba

        imagemagick

        If you get something wrong, use below.

        $ brew install imagemagick –build-from-source

        ruby

        You can’t use multibyte-language (Japanese etc) in irb when install without option.

        $ rvm pkg install readline iconv
        $ rvm install 1.9.3-p194 –with-readline-dir=$rvm_usr_path --with-iconv-dir=$rvm_path/usr

        mysql

        $ brew install mysql
        $ unset TMPDIR
        $ mysql_install_db –verbose –user=whoami –basedir=”$(brew –prefix mysql)” –datadir=/usr/local/var/mysql –tmpdir=/tmp
        $ cp /usr/local/Cellar/mysql/5.5.20/homebrew.mxcl.mysql.plist ~/Library/LaunchAgents/
        $ launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

怖話リゾートバイトが途中で切れるバグを直しました。

PostgreSQLの調子で使ってたMySQLのtext型の最長を超えてるだけだった。

text: 65535Byte
mediumtext: 16777215Byte
longtext: 4294967295Byte

リゾートバイトは120KBぐらいの長編なのでmediumtextに変えて対応。

# RAILS_ROOT/db/migrate/20120127081325_alter_body_to_mediumtext_stories.rb 
class AlterBodyToMediumtextStories < ActiveRecord::Migration
  def up
    if Rails.env.production?
      execute 'ALTER TABLE stories MODIFY body mediumtext COLLATE utf8_unicode_ci;'
    end
  end

  def down
    if Rails.env.production?
      execute 'ALTER TABLE stories MODIFY body text COLLATE utf8_unicode_ci;'
    end
  end
end

超えてもエラーが出ないから気づかなかったなあ。

rails3.1でMySQLからやってくる文字列がASCII-8BITになっているのでto_jsonすると壊れる(to_jsonがencodingを見て処理するので)。sqlite3では起こらない。

環境はSnow Leopard、ruby1.9.2-p290、homebrewで入れたmysql 5.1.54。

% rails new foo
% cd foo
% vi Gemfile
(...)
gem 'mysql'
(...)
% bundle
% vi config/database.yml
(...)
development:
  adapter: mysql
  encoding: utf8
  database: foo_development
  pool: 5
  username: root
  password: 
  host: localhost
  socket: /tmp/mysql.sock
(...)
% rails g model post title:string
% rake db:create
% rake db:migrate
% vi db/seeds.rb
Post.create!(title: 'うんk')
% rake db:seed
% rails c
ruby-1.9.2-p290 :001 > puts Post.first.title
うんk
 => nil 
ruby-1.9.2-p290 :002 > Post.first.title.encoding
 => #<encoding:ascii-8bit>
ruby-1.9.2-p290 :003 > puts Post.first.title.to_json
"\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd"
 => nil

CentOS 5.6でも同じ。

解決:

mysql gemはruby1.9.1からのencodingに対応してない。だからmysql2を使えば解決でした。

% vi Gemfile
(...)
  gem 'mysql2'
(...)
% vi config/database.yml
(...)
  adapter: mysql2
(...)
% rails c
ruby-1.9.2-p290 :001 > Post.first.title.encoding
 => #<Encoding:UTF-8>

adapterにmysql2と書けるというところが盲点でした・・・。