Q4MをMacのMacPortsにインストール

Q4Mをインストールしました。

環境

MySQLをインストール

sudo port install mysql5 +fast_mutexes
sudo port install mysql5_server

Q4Mソースコードを取得、コンパイル

ソースコードをダウンロードし解凍する。

tar xzf q4m-0.9.5.tar.gz

configureのためにシンボリックリンクを作成。

pushd /opt/local/include/
sudo ln -s mysql5/mysql
popd

コンパイルとインストール。

./configure --with-mysql=/tmp/mysql-5.1.59 --prefix=/opt/local/
make
sudo make install
sudo mv /opt/local/lib/libqueue_engine.* /opt/local/lib/mysql5/mysql/plugin/
mysql5 -u root -f mysql < support-files/install.sql

テスト

Q4Mにはテストスクリプトが同封されているので、それを実行してみる。

まずテスト実行のために必要なPerlモジュールをインストールする。(他にも必要かも。。足りなかったらテストでエラーが出る)

sudo ln -s mysql_config5 mysql_config # これをしないとインストールに失敗する。
sudo cpan -i DBD::mysql
sudo cpan -i Data::Compare

テストを実行。

make test

MacPortsにMySQL5をインストールしたときのメモ

taisuke@th-air:~$ sudo port install  mysql5-server
Password:
--->  Computing dependencies for mysql5-server
--->  Fetching archive for mysql5-server
--->  Attempting to fetch mysql5-server-5.1.59_0.darwin_11.noarch.tbz2 from http://packages.macports.org/mysql5-server
--->  Fetching mysql5-server
--->  Verifying checksum(s) for mysql5-server
--->  Extracting mysql5-server
--->  Configuring mysql5-server
--->  Building mysql5-server
--->  Staging mysql5-server into destroot
--->  Creating launchd control script
###########################################################
# A startup item has been generated that will aid in
# starting mysql5-server with launchd. It is disabled
# by default. Execute the following command to start it,
# and to cause it to launch at startup:
#
# sudo port load mysql5-server
###########################################################
--->  Installing mysql5-server @5.1.59_0
******************************************************
* In order to setup the database, you might want to run
* sudo -u _mysql mysql_install_db5
* if this is a new install
******************************************************
--->  Activating mysql5-server @5.1.59_0
--->  Cleaning mysql5-server

と出たので、指示通りに以下を実行。

taisuke@th-air:~$ sudo -u _mysql mysql_install_db5
Installing MySQL system tables...
OK
Filling help tables...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

/opt/local/lib/mysql5/bin/mysqladmin -u root password 'new-password'
/opt/local/lib/mysql5/bin/mysqladmin -u root -h th-air.local password 'new-password'

Alternatively you can run:
/opt/local/lib/mysql5/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd /opt/local ; /opt/local/lib/mysql5/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd /opt/local/mysql-test ; perl mysql-test-run.pl

Please report any problems with the /opt/local/lib/mysql5/bin/mysqlbug script!

サーバーの起動

sudo /opt/local/share/mysql5/mysql/mysql.server start

Ubuntu 11.04をMBAのVirtualBoxにインストール

Guest Additionsインストール

これをインストールしないと画面の解像度が自動で切り替わらない。

VirtualBoxのメニュー -> デバイス -> Guest Additionsのインストール

でできる。

ネットワークの設定変更

VirtualBoxのネットワークの設定を、ブリッジアダプタに変更し、MBAと通信できるようにする。

gnomeをソフトウェアセンターからインストール

Unityは使いにくそうなのでgnomeを使うことにする。

ホームディレクトリを英語化

env LANG=C xdg-user-dirs-gtk-update

インプットメソッドの切り替えのキーを変更

Ctrl-SpaceをCtrl-\ に変更

インストールするソフト

  • emacs23
  • chrome
  • git
  • openssh-server

gitから設定ファイルを取得

git clone git@github.com:taisukeh/th.git

ThriftをUbuntu10.04にインストール

ThriftをUbuntu10.04にインストールする手順を残します。

Thriftのウェブサイトはhttp://incubator.apache.org/thrift/ですが、このサイトにはドキュメントはほとんどありません。そこで、http://wiki.apache.org/thrift/にあるインストール手順を見ながら作業を進めます。

必要要件

必要要件には以下のようにあります。

  • POSIXに(ほとんど)準拠した*NIXシステム
  • g++ 3.3.5+
  • boost 1.33.1+ (テストのためには1.34.0以上)
  • lex, yacc

そこで、まずは必要なパッケージをインストールします。Ubuntu10.04ではg++,boostは指定されたバージョン以上のパッケージが用意されています。また、lex, yaccはそれぞれflex, bisonというパッケージに含まれています。

sudo apt-get install libboost-dev g++ flex bison

また、インストール手順には書いていないのですが、ビルドには以下のパッケージが必要でした。おそらく他にもjavaなどが必要になっていると思われます。ビルドに失敗したら入れてみてください。

sudo apt-get install ruby-1.8-dev python-dev

インストール

まずはThriftをダウンロードします。公式ページからダウンロードページに行くと、間違ったURLに飛ばされダウンロードできませんでした。0.3.0-incubating を 0.4.0-incubatingに直すとダウンロードできます。

# ダウンロード
$ wget http://ftp.kddilabs.jp/infosystems/apache//incubator/thrift/0.4.0-incubating/thrift-0.4.0.tar.gz
#ファイルを展開
$ tar xzvf thrift-0.4.0.tar.gz 
$ cd thrift-0.4.0/
$ ./configure
$ make
$ make install

以上の処理でエラーがでなかったらインストール完了です。

ClojureをUbuntuに導入した

[http://clojure.org/:Clojure処理系とemacsでの作業環境をUbuntu10.04に構築した。

  1. JDKをインストール。Ubuntuだと非常に楽。aptのリポジトリ
add-apt-repository "deb http://archive.canonical.com/ lucid partner"
apt-get update
apt-get install sun-java6-jdk sun-java6-plugin
update-java-alternatives -s java-6-sun
  1. Clojureから最新版の処理系をダウンロード。
    1. Clojure 1.2 Beta 1が最新だったのでそれをダウンロードした。
  2. ~/lib/clojure に展開

次にemaceのClojure環境

  1. ~/opt で
git clone git://git.boinkor.net/slime.git
git clone git://github.com/jochu/clojure-mode.git
git clone git://github.com/jochu/swank-clojure.git
  1. 足りないパッケージをインストール
sudo apt-get install sbcl
  1. Google サイトを参考にemacsの初期化ファイルに以下を記述。
(nconc load-path
       '("~/opt/swank-clojure/src/emacs"
	 "~/opt/clojure-mode"
	 "~/opt/slime"))

(setq swank-clojure-jar-path "~/lib/clojure-1.2.0-beta1/clojure.jar"
      swank-clojure-extra-classpaths '("~/opt/swank-clojure/src/main/clojure"
                                       "~/lib/clojure"
                                      "~/lib/clojure/clojure-contrib.jar"
                                       ))


(require 'clojure-mode)
(autoload 'clojure-mode "clojure-mode" "A major mode for Clojure" t)
(require 'swank-clojure-autoload)
(eval-after-load "slime"
  '(progn (slime-setup '(slime-repl slime-fuzzy slime-c-p-c)))) ;後述
(require 'slime)
(slime-setup)

(clojure-slime-config "~/opt") 

DOM Level 1仕様書を読んだので、まとめ

Document Object Model (DOM) Level 1 Specification (Second Edition)を一通り読んだので、復習としてまとめてみる。細かいところではよくわからない箇所がいくつかあった。原因はXMLやHTMLの知識が足らなかったからだと思う。

概要

  • この仕様はDocument Object Model Level 1を定義する。
  • DOM Level 1はプラットフォームにも言語にも中立なインタフェース。
  • プログラムやスクリプトにドキュメントのコンテンツや構造やスタイルへのアクセスや変更を提供する。
  • DOMの目標はXMLとHTMLのためのインタフェースを定義すること
  • DOM Level 1 の仕様は、CoreとHTMLの二つのパートがある。
  • CoreはXMLを表現するローレベルなインタフェースと拡張インタフェースからなる。拡張の方はHTMLへのアクセスだけを提供する実装では実装しなくてもいいよ。

Document Object Model Core

  • このセクションではドキュメントオブジェクトへのアクセスと操作を行うオブジェクトとインタフェースを定義する。
  • このセクションで定義されている機能を使えば、XMLXMLの要素へのアクセスや操作ができる。
The DOM Structure Model
  • DOMはドキュメントをノードオブジェクトの階層で表現する。ノードオブジェクトは継承される。
  • DOMはノードのリストとマップ(NodeList, NamedNodeMap)を定義する。NodeList,NamedNodeMapのオブジェクトは生きている、つまり、ドキュメントが変更されたら、こいつらのオブジェクトも自動的に変更される。
Memory Management
  • プログラミング言語によってメモリ管理ってずいぶん違うよね。DOMはそんなこと知ったこっちゃないよ。
Naming Conventions
  • 名前の衝突があるからDOMで使う名前は長くて説明的になるよ
  • 名前で使う単語の一貫性にも気をつけたよ。例えば、remove と deleteは意識して使い分けているよ
Inheritance vs. Flattened Views of the API
  • なんかキャストをすると処理が重くなるかもしれないから、Nodeインタフェースに結構機能を持たせたよ。
  • もちろん使いたい人は、Nodeを継承した高水準なインタフェースを使ってもいいよ
  • こんな風に二つの方法があるから、ちょっと冗長になっているんだよ
DomSTRING Type
  • DOMStringは16-bit単位のシーケンス
  • IDLではこうなる

typedef sequence DOMString;

String comparison in the DOM
  • 文字列の比較は16-bit単位のバイナリ比較をするよ。DOMの実装は、ちゃんと、テキスト(ノード名とかの)を正規化するんだよ。

Fundamental Interface

  • このセクションのインタフェースは基本的な物だから、全てのDOM実装で実装しなければならない。
Exception DOMException
  • DOMの操作は例外を投げるよ。
  • 言語が例外をサポートしていなかったらそれぞれのエラーレポーティングのメカニズムでなんとかしてね。
  • 例外のIDL定義はこんなんだよ

exception DOMException {
unsigned short code;
};
// ExceptionCode
const unsigned short INDEX_SIZE_ERR = 1;
const unsigned short DOMSTRING_SIZE_ERR = 2;
const unsigned short HIERARCHY_REQUEST_ERR = 3;
const unsigned short WRONG_DOCUMENT_ERR = 4;
const unsigned short INVALID_CHARACTER_ERR = 5;
const unsigned short NO_DATA_ALLOWED_ERR = 6;
const unsigned short NO_MODIFICATION_ALLOWED_ERR = 7;
const unsigned short NOT_FOUND_ERR = 8;
const unsigned short NOT_SUPPORTED_ERR = 9;
const unsigned short INUSE_ATTRIBUTE_ERR = 10;

Interface DOMImplementation
  • DOMImplementationインタフェースはドキュメントのインスタンスからは独立した操作を提供する。
  • ちなみに、DOM Level 1ではドキュメントインスタンスを作る方法は定義していないよ。Level 2以降で仕様かされることを望んでいるよ。

interface DOMImplementation {
boolean hasFeature(in DOMString feature,
in DOMString version);
};

  • hasFeatureメソッドはDOM実装が特定の機能を実装しているかをテストするよ
Interface DocumentFragment
  • DocumentFragmentは lightweight なドキュメントオブジェクトだよ。
  • ドキュメントツリーの一部分を作るときに使うよ。
  • DocumentFragmentをDocumentに挿入するときは、DocumentFragmentの子供ノード達が追加されて、DocumentFragment自身は追加されないよ。

interface DocumentFragment : Node {
};

Interface Document
  • DocumentインタフェースはHTML,XMLドキュメント全体を表すよ。ドキュメントツリーのルートだよ。

interface Document : Node {
readonly attribute DocumentType doctype;
readonly attribute DOMImplementation implementation;
readonly attribute Element documentElement;
Element createElement(in DOMString tagName)
raises(DOMException);
DocumentFragment createDocumentFragment();
Text createTextNode(in DOMString data);
Comment createComment(in DOMString data);
CDATASection createCDATASection(in DOMString data)
raises(DOMException);
ProcessingInstruction createProcessingInstruction(in DOMString target,
in DOMString data)
raises(DOMException);
Attr createAttribute(in DOMString name)
raises(DOMException);
EntityReference createEntityReference(in DOMString name)
raises(DOMException);
NodeList getElementsByTagName(in DOMString tagname);
};

  • こんな風に、createX っていうファクトリメソッドも持っているよ
Interface Node
  • ドキュメントツリーのノード。

interface Node {

// NodeType
const unsigned short ELEMENT_NODE = 1;
const unsigned short ATTRIBUTE_NODE = 2;
const unsigned short TEXT_NODE = 3;
const unsigned short CDATA_SECTION_NODE = 4;
const unsigned short ENTITY_REFERENCE_NODE = 5;
const unsigned short ENTITY_NODE = 6;
const unsigned short PROCESSING_INSTRUCTION_NODE = 7;
const unsigned short COMMENT_NODE = 8;
const unsigned short DOCUMENT_NODE = 9;
const unsigned short DOCUMENT_TYPE_NODE = 10;
const unsigned short DOCUMENT_FRAGMENT_NODE = 11;
const unsigned short NOTATION_NODE = 12;

readonly attribute DOMString nodeName;
attribute DOMString nodeValue;
// raises(DOMException) on setting
// raises(DOMException) on retrieval

readonly attribute unsigned short nodeType;
readonly attribute Node parentNode;
readonly attribute NodeList childNodes;
readonly attribute Node firstChild;
readonly attribute Node lastChild;
readonly attribute Node previousSibling;
readonly attribute Node nextSibling;
readonly attribute NamedNodeMap attributes;
readonly attribute Document ownerDocument;
Node insertBefore(in Node newChild,
in Node refChild)
raises(DOMException);
Node replaceChild(in Node newChild,
in Node oldChild)
raises(DOMException);
Node removeChild(in Node oldChild)
raises(DOMException);
Node appendChild(in Node newChild)
raises(DOMException);
boolean hasChildNodes();
Node cloneNode(in boolean deep)
raises(DOMException);
};

  • nodeNameとnodeValueとattributesは、ノードタイプによって値が変わるよ。
その他
  • Interface NodeList, NodeMap
  • Nodeインタフェースを継承した、CharacterData, Attr, Element, Text, Comment
拡張
  • HTMLのみを扱うDOM実装では、ここで定義するインタフェースは実装しなくて良いよ
  • CDDATASection, DocumentType, Notation, Entity, EntityReference, ProcessingInstruction

Document Object Model HTML

  • このセクションは Level 1 Core APIを HTML 4.0 のドキュメントに特化して拡張するよ。
  • 目標は
    • HTMLドキュメント用に機能を特化させる
    • DOM Level 0 との後方互換性を解決する
    • HTMLドキュメントで便利でよく使われる操作を提供する
  • 例えば、
    • Documentを継承した、HTMLDocument
    • Elementを継承したHTMLElement
    • HTMLの全ての要素のために、HTMLElementをさらに特化させている
  • ただし、CSS 1へのアクセスは提供していない
  • HTML 4.0向けであって、XHTMLではたぶん使えないよ。
Interface HTML Collection
  • HTMLCollectionはノードのリストで、こんな感じ

interface HTMLCollection {
readonly attribute unsigned long length;
Node item(in unsigned long index);
Node namedItem(in DOMString name);
};

Interface HTMLDocument

interface HTMLDocument : Document {
attribute DOMString title;
readonly attribute DOMString referrer;
readonly attribute DOMString domain;
readonly attribute DOMString URL;
attribute HTMLElement body;
readonly attribute HTMLCollection images;
readonly attribute HTMLCollection applets;
readonly attribute HTMLCollection links;
readonly attribute HTMLCollection forms;
readonly attribute HTMLCollection anchors;
attribute DOMString cookie;
void open();
void close();
void write(in DOMString text);
void writeln(in DOMString text);
Element getElementById(in DOMString elementId);
NodeList getElementsByName(in DOMString elementName);
};

Interface HTMLElement
  • HTML属性は、インタフェースのプロパティとして定義されるよ。属性のデータタイプはHTML 4.0の"transitional and frameset DTDs"から決定されるよ。
Naming Exceptions
  • 名前の衝突回避のために必要であれば属性の名前にhtmlプレフィックスをつけるよ。例えば、 LABEL 要素の for 属性は htmlFor になる。
Interface HTMLElement

interface HTMLElement : Element {
attribute DOMString id;
attribute DOMString title;
attribute DOMString lang;
attribute DOMString dir;
attribute DOMString className;
};

あとはHTMLの要素に対応するインタフェースがたくさんある
  • HTMLHtmlElement, HTMLHeadElement, HTMLLinkElement, HTMLTitleElement, HTMLMetaElement, HTMLBaseElement, HTMLIsIndexElement, HTMLStyleElement, HTMLBodyElement, HTMLFormElement, HTMLSelectElement, HTMLOptGroupElement, HTMLOptionElement, HTMLInputElement, HTMLTextAreaElement, HTMLButtonElement, HTMLLabelElement, HTMLFieldSetElement, HTMLLegendElement, HTMLUListElement, HTMLOListElement, HTMLDListElement, HTMLDirectoryElement, HTMLMenuElement, HTMLLIElement, HTMLDivElement, HTMLParagraphElement, HTMLHeadingElement, HTMLQuoteElement, HTMLPreElement, HTMLBRElement, HTMLBaseFontElement, HTMLFontElement, HTMLHRElement, HTMLModElement, HTMLAnchorElement, HTMLImageElement, HTMLObjectElement, HTMLParamElement, HTMLAppletElement, HTMLMapElement, HTMLAreaElement, HTMLScriptElement, HTMLTableElement, HTMLTableCaptionElement, HTMLTableColElement, HTMLTableSectionElement, HTMLTableRowElement, HTMLTableCellElement, HTMLFrameSetElement, HTMLFrameElement, HTMLIFrameElement