2008-04-09

Google App Engine SDKインストール編

TekTekで使えたらいいなと思って、Google App EngineのSDKをインストールしてみた。
(まだ登録は順番待ちなのです。(T_T)
ひとまずHello worldまで実験完了したので書いておきます。

1. SDKのダウンロード
http://code.google.com/appengine/downloads.html


2. インストール
ダウンロードしたパッケージをひたすらクリックしてインストールして行きます。
その間表示されるメッセージには、以下のようなことが書いてあります。

開発用サーバーは、/usr/local/bin/dev_appserver.py にインストールされます。
その他の部品は /usr/local/google_appengine へインストールされます。

開発サーバーの起動
/usr/local/bin/dev_appserver.py [options] <application root>

"application root"は、文字通りアプリケーションのルートディレクトリで、
正式なフォーマットのapp.yamlかapp.ymlファイルを置いていなければならない。


追加で、以下のコマンドを実行し、各アプリをPythonにインストール。
% sudo ln -s /usr/local/google_appengine/google /usr/local/Python25/lib/python2.5/site-packages/google
※上記"/usr/local/Python25/lib/python2.5/site-packages/"の部分は、
あなたがお使いのPythonのインストールパスに合わせてください。

% cd /usr/local/google_appengine/lib/webob
% sudo python setup.py install
% cd /usr/local/google_appengine/lib/yaml
% sudo python setup.py
※djangoをインストールしていない方は、さらに
% cd /usr/local/google_appengine/lib/django
% sudo python setup.py

3. 確認
% python
>>> from google.appengine.ext import webapp
※このimportで何もエラーがでなければ、OKのようだ。
>>> ^D


4. Hello worldを書く。
% mkdir helloworld
% cd helloworld
※ここでこのディレクトリに以下の2ファイルを作成。
% cat helloworld.py
print 'Content-Type: text/plain'
print ''
print 'Hello, world!'

% cat app.yaml
application: helloworld
version: 1
runtime: python
api_version: 1

handlers:
- url: /.*
script: helloworld.py

5. hello worldアプリを起動
先ほどのhelloworldディレクトリ内にいる場合は、その上の階層へ
% cd ..

そして、以下を実行
ayu@~/work% /usr/local/google_appengine/dev_appserver.py helloworld
Allow dev_appserver to check for updates on startup? (Y/n): n
※上でdev_appserver.pyのアップデートをするかを聞かれるが、あせってnを選びました。。。

WARNING 2008-04-09 01:31:55,128 datastore_file_stub.py] Could not read datastore data from /tmp/dev_appserver.datastore
WARNING 2008-04-09 01:31:55,128 datastore_file_stub.py] Could not read datastore data from /tmp/dev_appserver.datastore.history
INFO 2008-04-09 01:31:55,131 dev_appserver_main.py] Running application helloworld on port 8080: http://localhost:8080

ここまでできたら、以下のURLをブラウザで開く。
http://127.0.0.1:8080/

これでhello world!が画面に表示されるはず!!!

2008-04-08

MySQL5のFederatedはまだまだ使えないという話

Every query to a federated table results in a full scan of MyISAM table.

Federatedエンジンでselect count(*) from ...をすると、いちいちテーブルの全レコードをリモートに送り込むというバグがあるそうで、期待のFederatedであったがまだまだ使い物にはならない。
5.1以上で直すことになると見えるが、現時点ではChange logにその修正の旨は発見できず。

PythonでLatent semantic analysis

Latent Semantic Analysis in Python

興味深い。

【要点】
* TFIDFをベクトルの成分とする。
* scipy のsvdルーチンを使う。(次元が100万とかになっても大丈夫なんだろうか?Lanczos法のような手法を内部で使っているか?)

Blogの記事のような、極端に短い内容の記事も大量にあるような文書集合だと、こういった手法でぼかした検索ができるといいのかもしれません。

でもこういうのは実運用の場合はC++で書くべきと思うよ。

2008-04-07

optparseのhelp文で改行を生かす方法

pythonのoptparseモジュールは便利だが、help文に改行を使ってもうまく表示されない。
解決の参考になるのはここの議論だろう。
以下にそのソースを抜粋。

import optparse
import textwrap

class IndentedHelpFormatterWithNL(optparse.IndentedHelpFormatter):
def format_description(self, description):
if not description: return ""
desc_width = self.width - self.current_indent
indent = " "*self.current_indent
bits = description.split('\n')
formatted_bits = [
textwrap.fill(bit,
desc_width,
initial_indent=indent,
subsequent_indent=indent)
for bit in bits]
result = "\n".join(formatted_bits) + "\n"
return result

def format_option(self, option):
"""
The help for each option consists of two parts:
* the opt strings and metavars
eg. ("-x", or "-fFILENAME, --file=FILENAME")
* the user-supplied help string
eg. ("turn on expert mode", "read data from FILENAME")

If possible, we write both of these on the same line:
-x turn on expert mode

But if the opt string list is too long, we put the help
string on a second line, indented to the same column it would
start in if it fit on the first line.
-fFILENAME, --file=FILENAME
read data from FILENAME
"""
result = []
opts = self.option_strings[option]
opt_width = self.help_position - self.current_indent - 2
if len(opts) > opt_width:
opts = "%*s%s\n" % (self.current_indent, "", opts)
indent_first = self.help_position
else: # start help on same line as opts
opts = "%*s%-*s " % (self.current_indent, "", opt_width, opts)
indent_first = 0
result.append(opts)
if option.help:
help_text = self.expand_default(option)
help_lines = []
for para in help_text.split("\n"):
help_lines.extend(textwrap.wrap(para, self.help_width))
result.append("%*s%s\n" % (
indent_first, "", help_lines[0]))
result.extend(["%*s%s\n" % (self.help_position, "", line)
for line in help_lines[1:]])
elif opts[-1] != "\n":
result.append("\n")
return "".join(result)

if __name__ == "__main__":
parser = optparse.OptionParser(
formatter=IndentedHelpFormatterWithNL(),
usage=u"""....""")
....

2008-04-05

「ケータイマルチキャリア高機能テスター」を使ってみるよ。

ケータイマルチキャリア高機能テスター P1エミュレーター
を使ってみる事にした。

ほとんどの最近のケータイのエミュレーターになるそうで、携帯用サイトの作成に役立ちそうです。

これでTekTekのi-mode版、SB版も作ってみることにしよう。

2008-04-04

Amazon.comから尻を叩かれた話

TekTekを作った時に、米国のAmazon.comのアフィリエイトにも加入したのだが、今日、そのAmazon.comから「売り上げが上がってないぞ!」ということをやんわりと伝えるメールが来た。

Hello Associate,
We noticed that you were accepted to the Amazon.com Associate Program
several weeks ago but have yet to refer a sale. Here are a few quick
and easy steps to help you get started:

訳:
こんにちは、
数週間前にAmazon.comのアソシエイトプログラムに加入させてあげましたが、
まだ売り上げが上がってないようですねえ。助け舟として、すぐに&簡単に
できることを教えておきます、、、


あ、、、ありがとう、、、。がんばるよ。米国かーーー、、、どうやって宣伝すればいいものか。

2008-04-02

TekTekモバイル for EZwebをオープンしました!

TekTekのモバイル版TekTek mobile for EZwebをオープンしました。
今の所はEZwebのまあここ2〜3年ぐらいの機種のみ対応です。(古い機種での動作は確認していませんので保証できません。)

URLは以下になります。
http://www.tektek.in/d/tk/m/   → TekTek mobile for EZweb

TekTekを最初に作ろうと思った動機が、本屋で本を選ぶ時にAmazonの書評と評価点数をすばやく見たいからでした。
また、場合によってはその場で本を買わずに、Amazonに注文して届けてほしいと思う事もあります。
そんな用途を考えて、このモバイル版を作っています。

今後さらなる機能追加も行って行きますが、これでひとまず自分が使いたい最低ラインに到達です。