このページではパソコンに関する様々なご質問およびご見解を投稿していただき、まとめて公開していきます。

新規のご質問は右の「ページ」内にある「質問フォーム」からお願いいたします。

ご見解をお寄せ頂ける場合には、各記事にコメントとして投稿してくださるようお願いいたします。

ご質問およびご見解は、投稿いただいた後に担当者にてチェックを行ってからの公開となります。
公開までにしばらくお時間をいただく場合がありますことをご了承ください。
なお、公開作業は原則的に平日昼間のみの予定です。

Intel の Atom マザーである D525MW を使ってゼロスピンドルサーバを構築しようとしたのですが、その際に何故か USB メモリからブートできない問題が発生しました。

症状としては、USB 外付けDVDとかからはブートできるのですが、USB メモリやUSB SD リーダーなどからだとブートできたりできなかったりというものです。

BIOS の設定をアレコレ変更して試したのですが、全然ダメで、どうしたものかと小一時間悩みました。
その後、ふと思い立って BIOS アップデートを行ってみたところ、憎らしいほどスムーズに立ちあがるようになりました。

アップデートは Intel 公式ページの Support にある BIOS アップデートからダウンロードしました。
問題があった時点での BIOS バージョンは 0069 で、更新後は 0080 になりました。
今リリースノートを見ていたのですが、どうも 0078 あたりで USB デバイスの Linux パーティションからのブート問題が解決されていたようです。おそらくこれが原因だったのでしょう。

リリースノートにある中で一番古い 0049 が 2010年6月になってるわけですが、該当のブート問題が修正されたのが 2011年3月25日って、ついこの間なわけです。
2010年の段階で USB ブートって、それなりに使われてたことを考えると、ちょっとどうなのかという気はしますね。まあ、直ったバージョンをちゃんと出してるんで、いいんですけど…

以上、ちょっと愚痴混じりの報告でした。

Rails の各種サーバ起動時に path オプションでアプリケーションの先頭URL部分を指定しても、静的ファイルの指定にしか影響せず、ルーティングにはそのまま渡されてしまう件について。

例えば、Rails アプリケーションのURLを「/app1」以下にしたい場合、サーバ起動オプションに「–path /app1」を指定すれば良いのだが、これだけではルーティング解決時に「/app1/controller/action/id」のように渡ってしまい、期待した動作にならない。

これを解決するためには config/routes.rb を以下のように修正する必要がある。
実際のルート定義を 2 から 6 行目のように「Proc.new」で囲み、8 から 14 行目のように ENV['RAILS_RELATIVE_URL_ROOT'] を利用して判定するようにする。

RailsApp::Application.routes.draw do
  proc = Proc.new do
    # 実際のルート定義
    root :controller => 'home', :action => 'index'
    match ':controller(/:action(/:id(.:format)))'
  end

  if ENV['RAILS_RELATIVE_URL_ROOT']
    scope ENV['RAILS_RELATIVE_URL_ROOT'] do
      proc.call
    end
  else
    proc.call
  end
end

参考URL:http://d.hatena.ne.jp/mizincogrammer/20100819/1282192898

「undefined method ‘path’ for Gem:Module」が出てしまって問題になる場合。

一時的な解決策:起動時に ruby コマンドに「–disable-gems」オプションを付けると動く。

恒久的な解決策:読み込まれる新しい方の rubygems のファイル先頭に「Gem::QuickLoader.remove unless !defined? Gem」を追加する。
一般的には /usr/local/lib/ruby/site_ruby/1.9.1/rubygems.rb あたり。
見付け方としては以下のコマンドを実行してみて上にある方のファイルに追記してみる。直ったら OK ということで。
「ruby -e ‘$:.each{|d| f = “#{d}/rubygems.rb”; puts f if File.exist?(f)}’」

上の方法で QuickLoader.remove をすると、rails の実行などで問題が発生するようになる。
ruby 実行ファイルを ruby.orig などにリネームし、そこに ruby という名前で以下のシェルスクリプトを置いておくことで当面の解決になる模様。

#!/bin/sh
exec `dirname $0`/ruby.orig --disable-gems "$@"

ファイルを作成したら「chmod a+x ruby」で実行パーミッションを付けるのを忘れないこと。

シェルスクリプトを shebang で連鎖させると問題があって実行できない模様なので、オリジナルの ruby.orig を呼び出すバイナリを作ることにする。
以下を「g++ -Wall ruby.c -o ruby」としてコンパイルし、出来た ruby ファイルを元の ruby.orig のあるパスに置くこと。
なお、以下のソースでは ruby.orig のパスは「/usr/local/bin/」としているので、違う場合は適宜変更すること。

// ruby.c

#include <unistd.h>
#include <string>
#include <vector>

using namespace std;

int main(int argc, char* argv[]) {
  string cmd = "/usr/local/bin/ruby.orig";
  vector<char*> args;
  args.push_back((char*)"ruby");
  args.push_back((char*)"--disable-gems");
  for( int i = 1; i < argc; ++i ) {
    args.push_back( argv[i] );
  }
  args.push_back( NULL );
  execv( cmd.c_str(), &args[0] );
}

参考URL

http://arika.org/diary/2010/08/30/ruby-1-9-2-and-rubygems-1-3-7-and-gem-path

注意:力業での変更です。ご利用は自己責任でお願いします。

wordpress/wp-includes/ms-settings.php の95行目付近に以下のように追記します。

if ( defined( 'KTAI_ENTRY_BLOG_ID' ) ) {  // 追加
  $current_blog->blog_id = KTAI_ENTRY_BLOG_ID; // 追加
} elseif ( ! defined( 'WP_INSTALLING' ) ) { // 変更(先頭を elseif に)元の95行目あたり
  if ( $current_site->domain != $_SERVER['HTTP_HOST'] ) {

続いて wordpress/wp-content/plugins/ktai-entry/inject.php の12行目あたりに以下を追記します。

define('QMAIL_DELIVERY_FAILED_TRY_AGAIN', 111);

define('KTAI_ENTRY_BLOG_ID', $argv[1]); // 追加

if (isset($_SERVER['HTTP_HOST'])) {

以上の変更を行っておき、あとは KTAI_ENTRY の設定の .forward+SECRET の記述の時点で「inject.php」の後ろにブログIDを追記してやります。
具体的には以下のようになります。(ブログIDが2の場合)

"|/wordpressのパス/wp-content/plugins/ktai-entry/inject.php 2"

ブログIDはデータベース中の wp_blogs テーブルに書かれています。

WordPress の掲示板プラグインに zingiri-forum というのを発見しました。
この中で利用されているのが MyBB という掲示板なのですが、日本語設定が無かったので適当に翻訳してみました。
mybb.japanese

mybb/inc/language/ に解凍してご利用ください。

先達のソースコードを参考に、clojure での Mersenne Twister 乱数ライブラリを書いてみました。
ご利用は MIT ライセンスに基き、ご自由に行っていただいて構いません。

(defn expt [b p] (Math/pow b p))

(def *mt-k2-32* (int (expt 2 32)))
(def *mt-k-inverse-2-32f* (expt 2.0 -32.0))
(def *mt-bit-mask-32* 16rffffffff)

(def *mt-n* 624)
(def *mt-m* 397)
(def *mt-upper-mask* 16r80000000)
(def *mt-lower-mask* 16r7FFFFFFF)

(defstruct mt-random-state :mti :arr)

(defn set-next-value [arr i]
  (let [old (nth arr i)]
       (conj arr
             (bit-and (+ (* 1812433253 (bit-xor old (bit-shift-right old 30))) i 1) *mt-bit-mask-32*))))

(defn make-random-state [n]
  (struct mt-random-state (ref *mt-n*)
    (let [arr (ref [])]
         (dosync (ref-set arr
                          (loop [tmp [n] i 0]
                                (if (>= i (- *mt-n* 1))
                                    tmp
                                  (recur (set-next-value tmp i) (+ i 1))))))
         arr)))

(let* [matrix-a 16r9908B0DF
       mag01 [0 matrix-a]]
  (defn mt-refill [st]
    (let [state (:arr st) ret (atom [])]
      (dotimes [kk (- *mt-n* 1)]
             (let [y (bit-or
                      (bit-and (nth @state kk) *mt-upper-mask*)
                      (bit-and (nth @state (+ 1 kk)) *mt-lower-mask*))
                  val-fn (fn [idx old new] (let [n (mod (+ idx *mt-m*) *mt-n*)] (if (< n (count new)) (nth new n) (nth old n))))
                  next-fn (fn [kk y old new]
                              (bit-xor (bit-xor (val-fn kk old new) (bit-shift-right y 1)) (nth mag01 (bit-and y 1))))]
                  (swap! ret conj (next-fn kk y @state @ret))))
      (let [y (bit-or
             (bit-and (nth @state (- *mt-n* 1)) *mt-upper-mask*)
             (bit-and (nth @ret 0) *mt-lower-mask*))]
             (swap! ret conj
                   (bit-xor (bit-xor
                             (nth @ret (- *mt-m* 1))
                             (bit-shift-right y 1))
                            (nth mag01 (bit-and y 1)))))
      (dosync (ref-set state @ret)))
    (dosync (ref-set (:mti st) 0))
    st))

(defn mt-tempering-shift-u [n]
  (bit-and (bit-shift-right n 11) *mt-bit-mask-32*))

(defn mt-tempering-shift-s [n]
  (bit-and (bit-shift-left n 7) *mt-bit-mask-32*))

(defn mt-tempering-shift-t [n]
  (bit-and (bit-shift-left n 15) *mt-bit-mask-32*))

(defn mt-tempering-shift-l [n]
  (bit-and (bit-shift-right n 18) *mt-bit-mask-32*))

(let [mt-tempering-mask-b 16r9d2c5680
      mt-tempering-mask-c 16refc60000]
  (defn mt-genrand [state]
    (when (>= @(:mti state) *mt-n*)
      (mt-refill state))
    (let [y (nth @(:arr state) @(:mti state))]
         (dosync (ref-set (:mti state) (+ 1 @(:mti state))))
         (let [y (bit-xor y (mt-tempering-shift-u y))]
              (let [y (bit-xor y (bit-and (mt-tempering-shift-s y)
                                          mt-tempering-mask-b))]
                   (let [y (bit-xor y (bit-and (mt-tempering-shift-t y)
                                               mt-tempering-mask-c))]
                        (bit-xor y (mt-tempering-shift-l y))))))))

(defn mt-random [n state]
  (assert (> n 0))
  (if (integer? n)
      (mod (loop [bits-needed (int (Math/ceil (/ (Math/log n) (Math/log 2))))
                 bit-count    0
                 r            0]
                 (if (>= bit-count bits-needed)
		     r
		   (recur bits-needed (+ 32 bit-count) (+ (bit-shift-left r 32) (mt-genrand state)))))
	   n)
    (* (mt-genrand state) *mt-k-inverse-2-32f* n)))

Debian GNU/Linux 5.0 上で rubygems を使い、rails 2.3.8 をインストールして使おうとしたところ、標準の Mongrel サーバでは起動できるが、thin や unicorn の gem を入れて、thin コマンドや unicorn_rails コマンドで起動するとエラーしてしまう。

エラー内容は「rails 2.3.8」の読み込みエラーと出ている。

Debian GNU/Linux で、複数枚の NIC をボンディングするためには ifenslave パッケージをインストール後、以下のように設定します。

設定:eth0 と eth1 を合わせて bond0 として使う場合

/etc/network/interfaces

auto bond0
iface bond0 inet static
    address 192.168.0.xxx
    netmask 255.255.255.0
    gateway 192.168.0.1
    up /sbin/ifenslave bond0 eth0 eth1
    down /sbin/ifenslave -d bond0 eth0 eth1

/etc/modprobe.d/bonding(新規に作成)

alias bond0 bonding
options bonding mode=0 miimon=100

mode の設定など、細かいパラメータについてはここを参照してください。

Ruby on Rails のプラグイン jpmobile を利用して携帯サイトを作成したところ、trans_sid 機能を使っていても DoCoMo の携帯でアクセスするとセッションIDが変わってしまい、セッションデータが維持できない。

MinGW 環境で、スクリプト言語 Lua のビジュアルデバッガである lldebug がコンパイルできない。