以前作った「Suica 利用履歴から運賃を算出」iGoogle ガジェットが ITmedia で紹介されてた

「Suica 利用履歴から運賃を算出」ガジェットの UI をタブ仕様に変更 - Tosshi Note で作った Suica の運賃算出 iGoogle ガジェットが 3分LifeHacking:Suica、PASMOで“さらに”交通費精算を簡単にする - 誠 Biz.ID で紹介されているではないか。 同じところ(残額しかないから計算する必要があること)で引っかかった人がたくさんいるだろうなと思いつつも、あまりガジェットのユーザー数が伸びなかったが、この記事が出たあとページビューが15倍に膨らんだ。 知り合いのエントリを見るまで気づかなかった。一人歩きとはこういうことを言うのだろうな。 これでJR東日本がそもそも運賃表示機能を追加してくれれば一番良いのですが。 Firefox にも対応してほしいですね。 ITmediaの斎藤さん、紹介いただきありがとうございました。

2008年4月5日 · Toshimitsu Takahashi

Apache 2.2 のロードバランスでセッション毎にワーカーのパーシステンスを図るには

mod_proxy_balancer では、単純に stickysession の値をマッピングをしてくれるわけではないことが http://www.res-system.com/weblog/item/618 をみてわかった。 そこで、 http://d.hatena.ne.jp/tagomoris/20070717/1184671767 を参考にして、とにかくルートを持つ値をクッキーにセットすることにした。 フロントエンド バランサ側の設定を下記のようにする。 ProxyRequests Off ProxyPass / balancer://cluster/ stickysession=RWORKER ProxyPassReverse / http://worker1:8081/ ProxyPassReverse / http://worker2:8081/ <Proxy balancer://cluster/> BalancerMember http://worker1:8081/ route=worker1 BalancerMember http://worker2:8081/ route=worker2 </Proxy> バックエンド リクエストヘッダに RWORKER があるかどうかを判別してなければ付加するようにバックエンド側の Apache 設定を worker1 では SetEnvIf Cookie “RWORKER=[^;]+” HAVA_RWORKER Header add Set-Cookie “RWORKER=route.worker1” env=!HAVA_RWORKER として、worker2 では SetEnvIf Cookie “RWORKER=[^;]+” HAVA_RWORKER Header add Set-Cookie “RWORKER=route.worker2” env=!HAVA_RWORKER とした。 stickysession は . 以降を route 値としてみる仕様なので、route.worker としている。 ちなみにバックエンドが Tomcat だったら jvmRoute でいけたらしい・・・。

2008年3月29日 · Toshimitsu Takahashi

Mac OS X で自動ログインを復活させるには

家で Mac mini を iTunes サーバとして使っているが、バックアップ用にユーザを追加してから自動ログインが働かなくなってしまった。 毎回起動の度にディスプレイを切り替えるのが面倒なので調べたところ・・・ Apple - Support の方法で直すことができた。 ちなみに iTunes は自動起動にしている。

2008年3月23日 · Toshimitsu Takahashi

Solaris で暴走プロセスを KILL するウォッチャスクリプトを作るには

CPU リソースを食いつぶすプロセスがあったら、KILL する監視用スクリプトを書いてみる。 Linux だと top が有名だが、Solaris では標準ではない。prstat を使う。prstat を単に実行して標準出力するには $ prstat -c 1 1 とすればよい。後はターゲットプロセス名で grep して awk で cpu 使用率を取り出して合計値が閾値を超えたら、プロセスを KILL -KILL するようにする。 引数: 対象プロセス名(grep してるだけなので不十分) 暴走したとみなすしきい値 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 #!/bin/bash target=$1 threshold=$2 exp=0 for u in `prstat -c 1 1 | grep $target | awk '{print $9}' | sed -e "s/%$//"` do exp="${exp}+${u}" done cpu=`echo "s=${exp}; s/1" | bc` if \[ $cpu -lt $threshold \] then echo "no driving $target. (cpu usage: $cpu%)" exit 0 fi ps -ef | grep $target | awk '{print $2}' | xargs kill -KILL echo "killed driving $target. (cpu usage: $cpu%)" ※bc で実数の計算をしているが、scale=0; としても小数値が帰ってしまうので s/1 とした。

2008年3月20日 · Toshimitsu Takahashi

style が white-space:pre なブロック要素内で折り返すように JavaScript でハックするには

かなり限定的な話です。 スタイルシートの white-space 属性が pre 指定だと任意に改行が行われなくなるので、長い行が存在するとスクロールが入って見づらくなるのは、よく知られていると思います。 そんなときに JavaScript を適用して直して表示させる方法です。 .prestyle { white-space:pre; } となっていたときに下記のように load 時に修正します。 $(window).load(function() { $(".prestyle").each(function(){ var ctn = $(this).html(); ctn = ctn.replace(/^\\n|\\n$/g, "").replace(/\\n/g, "<br>"); $(this).html(ctn).css("white-space", "normal"); }); }); ※jQuery.js を使ってます。改行を br タグ に置き換えて white-space をノーマルに戻しています。Firefox だと前後に改行が入るようなので消しています。 IE だと中身に CR, LF が入っていても、white-space:pre や pre タグでないと innerHTML で取得するときは全てスペース化されてしまいます。 改行を活かしたいけど、HTML には手は付けられない。けれども CSS と JavaScript は付加できる。そんな場合に今回は有効な方法です。

2008年3月19日 · Toshimitsu Takahashi

プロバイダの DNS のせいで Google に繋がらないから、自前の BIND で解決してしまうには

下記は過去の話です。現在、復旧しています(2008/03/16 21:55 現在) リアルタイムネタです。OCN、ぷららから Google が見られないみたいです。 単に Windows PC からだけなら Windows\System32\drivers\etc\hosts にエントリ書くだけですが、一台ではないので 自 BIND サーバで設定してしまった。 named.conf に Google.com, Google.co.jp ゾーンを追加する /var/named/chroot/etc/named.conf に追記する。 zone "google.com" { type master; file "google.zone"; }; zone "google.co.jp" { type master; file "google.zone"; }; ゾーンファイル Google.zone を追加する /var/named/chroot/var/named/Google.zone を新規に作成して下記を定義する。 $TTL 86400 @ IN SOA dns.mydomain.local. root.mydomain.local. ( 2007102601 ; serial 3600 ; refresh 1hr 900 ; retry 15min 604800 ; expire 1w 86400 ; min 24hr ) IN NS dns.mydomain.local. www IN A 64.233.161.18 反映 /etc/init.d/named reload などで反映。 ...

2008年3月16日 · Toshimitsu Takahashi

アクセスログの URL エンコードされた部分を見るパイプ用スクリプトを Python で書く

decode.py を下記のように作る。 #!/usr/bin/env python import sys, urllib line = sys.stdin.readline() while line: print urllib.unquote_plus(line), line = sys.stdin.readline() ※ urllib.unquote だと + がスペースには置換されない。 $ tail -f /var/log/httpd/access_log | ./decode.py みたいに使う。ロケールが UTF-8 であることを前提にしてます。

2008年3月13日 · Toshimitsu Takahashi

Ruby net/http で Web サービスが動いているか確認する

Web サービスが停止していないかどうか確認するスクリプト。 open-uri を使うとタイムアウトが設定できないので、net/http で行う。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 #!/usr/bin/env ruby require 'net/http' PROXY_ADDRESS = nil \# プロキシサーバのアドレス PROXY_PORT = nil \# プロキシサーバのポート def check\_site\_alive(domain, port = 80) begin Net::HTTP.start(domain, port, PROXY_ADDRESS, PROXY_PORT) do |http| http.open_timeout = 20 http.read_timeout = 40 \# ↓は Web サービスにあわせて書き換える response = http.post(path, data) return response.code == '200' end rescue Exception =\> e puts e return false end end puts check\_site\_alive("webservice.domain")

2008年3月2日 · Toshimitsu Takahashi

Ruby CGI::Session で Cookie が発行されない

ログイン CGI でクッキーがクライアントに返らないので調べたら・・・ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 #!/usr/bin/env ruby require 'cgi/session' …(省略)… def create_session(cgi, timeout) begin \# 既存のセッションは削除 session = CGI::Session.new(cgi, { 'new_session' =\> false }) session.delete rescue ArgumentError end return CGI::Session.new(cgi, { 'new_session' =\> true, 'session_expires' =\> timeout }) end end session = create_session(cgi, Time.now + 3600) session\['savadata'\] = "hogehoge" print "Content-Type:text/html\\r\\n\\r\\n" print <<EOF <html> <body> <p>login success.</p> </body> </html> EOF exit 0 としたらクッキーができない。 ヘッダの出力がないことに気づいた。 ...

2008年2月29日 · Toshimitsu Takahashi

CentOS でカーネルをバージョンアップしたときに VMWare Server の再設定をするには

VMWare Server ではカーネルのバージョンを上げると再コンパイルが必要になる。 まずカーネルの確認。 $ uname -r 2.6.18-53.1.13.el5xen ノーマルもしくは xen の devel パッケージをインストール。 # yum install kernel-devel.i386 もしくは # yum install kernel-xen-devel.i386 vmware-config.pl を実行する。 $ sudo vmware-config.pl Making sure services for VMware Server are stopped. Stopping VMware services: Virtual machine monitor \[ OK \] Bridged networking on /dev/vmnet0 \[ OK \] Virtual ethernet \[ OK \] Configuring fallback GTK+ 2.4 libraries. In which directory do you want to install the mime type icons? \[/usr/share/icons\] What directory contains your desktop menu entry files? These files have a .desktop file extension. \[/usr/share/applications\] In which directory do you want to install the application's icon? \[/usr/share/pixmaps\] Trying to find a suitable vmmon module for your running kernel. None of the pre-built vmmon modules for VMware Server is suitable for your running kernel. Do you want this program to try to build the vmmon module for your system (you need to have a C compiler installed on your system)? \[yes\] Using compiler "/usr/bin/gcc". Use environment variable CC to override. What is the location of the directory of C header files that match your running kernel? \[/usr/src/linux/include\] /usr/src/kernels/2.6.18-53.1.13.el5-i686/include The directory of kernel headers (version 2.6.18-53.1.13.el5) does not match your running kernel (version 2.6.18-53.1.13.el5xen). Even if the module were to compile successfully, it would not load into the running kernel. What is the location of the directory of C header files that match your running kernel? \[/usr/src/linux/include\] /lib/modules/2.6.18-53.1.13.el5xen/build/include Extracting the sources of the vmmon module. Building the vmmon module. Using 2.6.x kernel build system. make: ディレクトリ `/tmp/vmware-config0/vmmon-only' に入ります ake -C /lib/modules/2.6.18-53.1.13.el5xen/build/include/.. SUBDIRS=$PWD SRCROOT=$PWD/. modules make\[1\]: ディレクトリ `/usr/src/kernels/2.6.18-53.1.13.el5-xen-i686' に入ります C \[M\] /tmp/vmware-config0/vmmon-only/linux/driver.o CC \[M\] /tmp/vmware-config0/vmmon-only/linux/hostif.o CC \[M\] /tmp/vmware-config0/vmmon-only/common/cpuid.o CC \[M\] /tmp/vmware-config0/vmmon-only/common/hash.o CC \[M\] /tmp/vmware-config0/vmmon-only/common/memtrack.o CC \[M\] /tmp/vmware-config0/vmmon-only/common/phystrack.o CC \[M\] /tmp/vmware-config0/vmmon-only/common/task.o CC \[M\] /tmp/vmware-config0/vmmon-only/common/vmx86.o CC \[M\] /tmp/vmware-config0/vmmon-only/vmcore/moduleloop.o LD \[M\] /tmp/vmware-config0/vmmon-only/vmmon.o Building modules, stage 2. MODPOST CC /tmp/vmware-config0/vmmon-only/vmmon.mod.o LD \[M\] /tmp/vmware-config0/vmmon-only/vmmon.ko make\[1\]: ディレクトリ `/usr/src/kernels/2.6.18-53.1.13.el5-xen-i686' から出ます cp -f vmmon.ko ./../vmmon.o make: ディレクトリ `/tmp/vmware-config0/vmmon-only' から出ます The module loads perfectly in the running kernel. This program previously created the file /dev/vmmon, and was about to remove it. Somebody else apparently did it already. This program previously created the file /dev/vmnet0, and was about to remove it. Somebody else apparently did it already. You have already setup networking. Would you like to skip networking setup and keep your old settings as they are? (yes/no) \[no\] yes Extracting the sources of the vmnet module. Building the vmnet module. Using 2.6.x kernel build system. make: ディレクトリ `/tmp/vmware-config0/vmnet-only' に入ります make -C /lib/modules/2.6.18-53.1.13.el5xen/build/include/.. SUBDIRS=$PWD SRCROOT=$PWD/. modules make\[1\]: ディレクトリ `/usr/src/kernels/2.6.18-53.1.13.el5-xen-i686' に入ります CC \[M\] /tmp/vmware-config0/vmnet-only/driver.o CC \[M\] /tmp/vmware-config0/vmnet-only/hub.o CC \[M\] /tmp/vmware-config0/vmnet-only/userif.o CC \[M\] /tmp/vmware-config0/vmnet-only/netif.o CC \[M\] /tmp/vmware-config0/vmnet-only/bridge.o CC \[M\] /tmp/vmware-config0/vmnet-only/procfs.o CC \[M\] /tmp/vmware-config0/vmnet-only/smac_compat.o SHIPPED /tmp/vmware-config0/vmnet-only/smac_linux.x386.o LD \[M\] /tmp/vmware-config0/vmnet-only/vmnet.o Building modules, stage 2. MODPOST WARNING: could not find /tmp/vmware-config0/vmnet-only/.smac\_linux.x386.o.cmd for /tmp/vmware-config0/vmnet-only/smac\_linux.x386.o CC /tmp/vmware-config0/vmnet-only/vmnet.mod.o LD \[M\] /tmp/vmware-config0/vmnet-only/vmnet.ko make\[1\]: ディレクトリ `/usr/src/kernels/2.6.18-53.1.13.el5-xen-i686' から出ます cp -f vmnet.ko ./../vmnet.o make: ディレクトリ `/tmp/vmware-config0/vmnet-only' から出ます The module loads perfectly in the running kernel. Shutting down http.vmware: \[ OK \] Starting httpd.vmware: \[ OK \] Please specify a port for remote console connections to use \[9002\] WARNING: VMware Server has been configured to run on a port different from the default port. Remember to use this port when connecting to this server. xinetd を停止中: \[ OK \] xinetd を起動中: \[ OK \] Configuring the VMware VmPerl Scripting API. Building the VMware VmPerl Scripting API. Using compiler "/usr/bin/gcc". Use environment variable CC to override. Installing the VMware VmPerl Scripting API. The installation of the VMware VmPerl Scripting API succeeded. Do you want this program to set up permissions for your registered virtual machines? This will be done by setting new permissions on all files found in the "/etc/vmware/vm-list" file. \[no\] Generating SSL Server Certificate In which directory do you want to keep your virtual machine files? \[/var/lib/vmware/Virtual Machines\] Do you want to enter a serial number now? (yes/no/help) \[no\] Starting VMware services: Virtual machine monitor \[ OK \] Virtual ethernet \[ OK \] Bridged networking on /dev/vmnet0 \[ OK \] Starting VMware virtual machines... \[ OK \] The configuration of VMware Server 1.0.4 build-56528 for Linux for this running kernel completed successfully. Setup found that the VMware Management Interface is installed on your machine. The VMware Management Interface configurator (/usr/bin/vmware-config-mui.pl) needs to be run. Do you want to run this program now? \[yes\] File /usr/lib/vmware-mui/apache/conf/httpd.conf is backed up to /usr/lib/vmware-mui/apache/conf/httpd.conf.old.0. Configuring httpd.conf to run Apache as: User: nobody and Group: nobody Set the number of minutes before a http session times out. (This is the length of time before someone connecting to VMware Management Interface will be logged out) \[60\] Generating SSL Server Certificate Starting httpd.vmware: \[ OK \] The configuration of VMware Management Interface completed successfully. と動かそうと思ったら、 ...

2008年2月25日 · Toshimitsu Takahashi