Rails3.xでseeds.rbを追加投入したい

Railsの運用中にDBの仕様変更とかで追加の初期データーとか投入したいときとか
rake db:seedsはソースコード読んだけどdb/seeds.rbにファイルが固定されてこまったりするわけです。
Railsのrakeタスクは隠し引く数多くてこまるんだけどね……)

scriptかいてもいいけど今後のことを考えるとタスクつくったほうがいいかなとおもってつくってみました。これで引数でファイル名指定して追加でデーター投入できるっ。


$ cat lib/tasks/db.rake
namespace :db do
desc 'Load the seed data from SEED_FILENAME'
task :seed_from_file => 'db:abort_if_pending_migrations' do
seed_file = File.join(Rails.root, 'db', ENV['SEED_FILENAME'])
load(seed_file) if File.exist?(seed_file)
end
end
というtaskを書くと

$ rake db:seed_from_file SEED_FILENAME='hogehoge.rb'
とすると追加データーが入るようになりました。
まあscriptかいて実行するという手もありますが、dryってことで(?

homebrew on MacOS10.7(lion)でemacsがinstallできない

いろいろ探したけど、本家のpatchもおかしいので通るように強引のFormula書換。
時間あったらpull request送るけどそんな時間は1ミリもない予感。。。

diff --git a/Library/Formula/emacs.rb b/Library/Formula/emacs.rb
index 33affb7..f88f63f 100644
--- a/Library/Formula/emacs.rb
+++ b/Library/Formula/emacs.rb
    if ARGV.include? "--use-git-head"
     head 'git://repo.or.cz/emacs.git'
@@ -29,6 +29,8 @@ class Emacs < Formula
     # Fix for building with Xcode 4; harmless on Xcode 3.x.
     unless ARGV.build_head?
       p << "http://repo.or.cz/w/emacs.git/commitdiff_plain/c8bba48c5889c4773c62
+      p << "https://raw.github.com/gist/1098107"
+      p << "https://raw.github.com/gist/1102744"
     end
 
     if ARGV.include? "--cocoa"

EC2でUbuntuのS3 AMIを作ると起動しない

Commniuty Imageからカスタマイズすると起動しない!!とおもったらgrubとfstabの設定を変えないとダメ。なんでこんな仕様になってるんだw

64bit版の場合。

/boot/grub/menu.lst
title		Ubuntu 10.10, kernel 2.6.35-24-virtual
root		(hd0)
kernel		/boot/vmlinuz-2.6.35-24-virtual root=/dev/sda1 ro console=hvc0 
initrd		/boot/initrd.img-2.6.35-24-virtual

rootを/dev/sda1に変更。

/etc/fstab
# /etc/fstab: static file system information.
#                                                
proc                                            /proc           proc    nodev,noexec,nosuid 0       0
/dev/sda1                                       /               ext4    defaults        0       0
/dev/sdb	/mnt	auto	defaults,nobootwait,comment=cloudconfig	0	2

/のmount pointを/dev/sda1に変更。

これで起動します。
これで半日つかったよ!!111

passenger-nginx-moudle-installでwith-http_ssl_moduleを使えるようにする

rvm+rails+nginxをEC2で使うときに、realipがとるためにnginxのコンパイルオプションを加えないと行けません。
そのためのquickhack

.rvm/gems/ruby-1.9.2-p180/gems/passenger-3.0.6/bin/passenger-install-nginx-module
393c393< command = "sh ./configure --prefix='#{prefix}' --with-http_ssl_module "

    • -

> command = "sh ./configure --prefix='#{prefix}' --with-http_ssl_module --with-http_realip_module "

すればOK。ここがConfigure Optionみたいですね。

PythonのPILをMacOS Xでつかったときに怒られる。

先日Pycon mini JPにいった時に、blockdiagというナイスなソフトを知りました。

ので使ってみようと思い、pipからインストールすると怒られます。

reki$:pip install blockdiag
(略)
reki$: blockdiag -o test.png test.diag
Traceback (most recent call last):
  File "/usr/local/bin/blockdiag", line 8, in <module>
    load_entry_point('blockdiag==0.6.6', 'console_scripts', 'blockdiag')()
  File "/Library/Python/2.6/site-packages/blockdiag/blockdiag.py", line 421, in main
    draw.draw()
  File "/Library/Python/2.6/site-packages/blockdiag/DiagramDraw.py", line 96, in draw
    self.node(node, **kwargs)
  File "/Library/Python/2.6/site-packages/blockdiag/DiagramDraw.py", line 204, in node
    font=self.font, badgeFill=self.badgeFill)
  File "/Library/Python/2.6/site-packages/blockdiag/noderenderer/box.py", line 24, in render_node
    lineSpacing=metrix.lineSpacing)
  File "/Library/Python/2.6/site-packages/blockdiag/ImageDrawEx.py", line 264, in textarea
    lines = TextFolder(box, string, scale=self.scale_ratio, **kwargs)
  File "/Library/Python/2.6/site-packages/blockdiag/utils/PILTextFolder.py", line 14, in __init__
    self.ttfont = ImageFont.truetype(font, fontsize)
  File "/Library/Python/2.6/site-packages/PIL/ImageFont.py", line 218, in truetype
    return FreeTypeFont(filename, size, index, encoding)
  File "/Library/Python/2.6/site-packages/PIL/ImageFont.py", line 134, in __init__
    self.font = core.getfont(file, size, index, encoding)
  File "/Library/Python/2.6/site-packages/PIL/ImageFont.py", line 34, in __getattr__
    raise ImportError("The _imagingft C module is not installed")
ImportError: The _imagingft C module is not installed

しらべると、PIL(Python Image Library)の1.1.6をいれるといいらしいのでいれてみる

reki:$pip uninstall pil
reki:$pip install pil==1.1.6
 Could not find a version that satisfies the requirement pil==1.1.6 (from versions: )
No distributions matching the version for pil==1.1.6
Storing complete log in /Users/marth/.pip/pip.log

ないっていわれたのでこまった。
Windowsだとバイナリーエディターとか荒技つかうんだけど、Macなので情報なし。

でもいっかいPILをいれてみると……

    --------------------------------------------------------------------
    PIL 1.1.7 SETUP SUMMARY
    --------------------------------------------------------------------
    version       1.1.7
    platform      darwin 2.6.1 (r261:67515, Jun 24 2010, 21:47:49)
                  [GCC 4.2.1 (Apple Inc. build 5646)]
    --------------------------------------------------------------------
    --- TKINTER support available
    *** JPEG support not available
    --- ZLIB (PNG/ZIP) support available
    *** FREETYPE2 support not available
    *** LITTLECMS support not available
    --------------------------------------------------------------------
    To add a missing option, make sure you have the required
    library, and set the corresponding ROOT variable in the
    setup.py script.

FREETYPE2がサポートされていない!!これが原因だ!!!

というわけでhomebrewでいれてみると(MacPorts嫌い)

reki$brew install freetype2
Error: No available formula for freetype2

ないっていわれたよ(´Д`;)

でしょうがないのでつくったw

https://github.com/yuuna/homebrew/blob/freetype/Library/Formula/freetype2.rb

require 'formula'

class Freetype2 <Formula
  url 'http://sourceforge.net/projects/freetype/files/freetype2/2.4.4/freetype-2.4.4.tar.gz/download'
  homepage 'http://freetype.sourceforge.net/index2.html'
  md5 '9273efacffb683483e58a9e113efae9f'
  version '2.4.4'

  # depends_on 'cmake'

  def install
    system "./configure", "--disable-debug", "--disable-dependency-tracking",
                          "--prefix=#{prefix}"
    # system "cmake . #{std_cmake_parameters}"
    system "make install"
  end
end

これを/usr/local/Library/Formula/にいれてFreetypeをいれてpipから再度インストール(pullリクエストおくってるのでそのうちmergeされるかも)

reki:$ sudo brew install freetype2
==> Downloading http://sourceforge.net/projects/freetype/files/freetype2/2.4.4/freetype-2.4.4.tar.gz/download
######################################################################## 100.0%
==> ./configure --disable-debug --disable-dependency-tracking --prefix=/usr/local/Cellar/freetype2/2.4.4
==> make install
/usr/local/Cellar/freetype2/2.4.4: 54 files, 2.5M, built in 16 seconds
reki:$ pip install pil

さすがMacProはやいっ、じゃなくて。
ログの最後をみると

    --------------------------------------------------------------------
    PIL 1.1.7 SETUP SUMMARY
    --------------------------------------------------------------------
    version       1.1.7
    platform      darwin 2.6.1 (r261:67515, Jun 24 2010, 21:47:49)
                  [GCC 4.2.1 (Apple Inc. build 5646)]
    --------------------------------------------------------------------
    --- TKINTER support available
    *** JPEG support not available
    --- ZLIB (PNG/ZIP) support available
    --- FREETYPE2 support available
    *** LITTLECMS support not available
    --------------------------------------------------------------------
    To add a missing option, make sure you have the required
    library, and set the corresponding ROOT variable in the
    setup.py script.

無事サポートされたみたい。

というわけで無事うごきました。
よくみるとjpegもサポートされていなかったのでlibjpegをいれて再度いれなおしました。

やっぱりhomebrewだね、homebrewヽ(´ー`)ノ