2012年3月28日水曜日

commons-daemon [第1回]

Javaでも常駐プロセスを、つまりデーモンを作りたいときもある。
もしくは、Windowsサービスを作りたいときもある。

そんなとき、やっぱり常駐するだけあって、実績のあるものを使いたい!!(←本音)

ということで選択したのはtomcatでも採用されている「commons-daemon

しかし、情報が少ない。 日本語も少ないし、英語も少ない(全部読んだわけではないけど)。

というわけで、自分で書いてみる。

第1回目は目標を掲げます。

目標

LinuxでもWindowsでも動くデーモンorサービスを作る

準備

次のサイトからダウンロードします。※1.0.10使います。 Commons Daemon Download
  1. [Commons Daemon Binaries] commons-daemon-1.0.10-bin.tar.gz
  2. [Browse native binaries download area...] commons-daemon-1.0.10-bin-windows.zip
  3. [Commons Daemon Source] commons-daemon-1.0.10-native-src.tar.gz


1番目は実装するときに使います。
2番目はWindowsサービス化で使います。
3番目はLinuxデーモン化で使います。
第2回はいきなりソース公開します。

2011年10月2日日曜日

Objective-C @Windows XP

Objective-C @Windows XP

Objective-Cに興味を持ったのでWindows XPで環境構築してみた。

参考にさせていただきました → 参考サイト

ダウンロードサイト

GNUSTEP公式サイト 0.22系だったので、以下の3つをダウンロードしました。
  1. gnustep-system-0.22.0-setup.exe
  2. gnustep-core-0.22.0-setup.exe
  3. SystemPreferences-1.0.2-7-setup.exe
  4. gorm-1.2.4-6-setup.exe (0.20.xのみ必要)
  5. Calculator-1.0.0-2-setup.exe (0.19.xのみ必要)

インストール

上記の番号順にインストールしました。
なんとなくインストールフォルダは「C:\opt\gnustep」としました。
インストール場所は毎回聞かれますが、毎回「C:\opt\gnustep」です。

私は0.22系だったので、1から3番をインストールしました。

環境変数の設定

環境変数に
  • GNUSTEP_HOME=C:\opt\gnustep
  • PATHに「%GNUSTEP_HOME%\bin」を追記

サンプルソース

では、ためしにやってみよう!ということで、以下のサイトにあったサンプルソースで実行してみました。 勝手にすみません。 ほんまの走り書き技術メモ

サンプルコンパイル

上記のソースをコンパイル。オプション多すぎて面倒、、、
C:\Documents and Settings\xxxxxx\デスクトップ>gcc -o hello hello.m -I C:\opt\g
nustep\GNUstep/System/Library/Headers -L C:\opt\gnustep\GNUstep/System/Library/L
ibraries -lobjc -lgnustep-base -fconstant-string-class=NSConstantString -enable-
auto-import
hello.exeができたので実行しました。
Hello Objective-C World
よかった、よかった

2011年9月19日月曜日

原発のしくみと放射能

Newton別冊 原発のしくみと放射能
そろそろ話題も絞られてきた気がするので
ちゃんと勉強しておこうと思って読んでみた。

結構難しいなーさすがNewton

2011年9月16日金曜日

日本人の9割は英語はいらない


日本人の9割は英語はいらない 成毛眞 (著)

こういった意見はたまに聞いていた気がしたけど まとまった本として読むのは初めて。

404ブログに、元マイクロソフトの取締役が書いたことに意味があるとあったが、 まさにそのとおりだと思う。

読むべし。
最近のグローバル化の波に押されている自分ですが、
ちょっとやる気が出てきた。

そのうち、1割に入りそうな気もするけど、、、

2011年3月27日日曜日

2010年12月19日日曜日

HTML中のクエリパラメータについて -2-

HTML中のクエリパラメータについて書いたけど
その続き。


html中にあるhref属性にて
クエリ文字列の区切りを「&」としても「&」としても
どっちでもステータスバーには「&」と表示され、
リクエストは「&」で送信されます。


でも、javascriptのlocation.href, replaceなどを使った場合、
ブラウザによって挙動が異なります。


以下のようなコードを書いて実行すると、

location.replace('http://search.yahoo.co.jp/search?p=href+smgl&aq=-1&oq=&ei=UTF-8&fr=top_ga1_sa&x=wrt');



IEの場合

※Internet Explorer 8で実験

 → 「&」が「&」となってリクエストが送信されます。

Firefoxの場合

※Firefox 3.6.12で実験

 → 「&」が「&」のままリクエストが送信されます。


で、HTTPの仕様としてはどうなのだろうと思って調べたけど
どのページを見ていいか分からず...

たぶん「&」が正しいと思うんだけどなー

2010年12月18日土曜日

HTML中のクエリパラメータについて

以下のページにあるように、html中に記述するときは、&ではなくて&

でも、リクエストを送信するときは、ちゃんと&で送信するように!

http://www.ietf.org/rfc/rfc1866.txt


8.2.1. The form-urlencoded Media Type

The default encoding for all forms is `application/x-www-form-
urlencoded'. A form data set is represented in this media type as
follows:

1. The form field names and values are escaped: space
characters are replaced by `+', and then reserved characters
are escaped as per [URL]; that is, non-alphanumeric
characters are replaced by `%HH', a percent sign and two
hexadecimal digits representing the ASCII code of the
character. Line breaks, as in multi-line text field values,
are represented as CR LF pairs, i.e. `%0D%0A'.

2. The fields are listed in the order they appear in the
document with the name separated from the value by `=' and
the pairs separated from each other by `&'. Fields with null
values may be omitted. In particular, unselected radio
buttons and checkboxes should not appear in the encoded
data, but hidden fields with VALUE attributes present
should.


NOTE - The URI from a query form submission can be
used in a normal anchor style hyperlink.
Unfortunately, the use of the `&' character to
separate form fields interacts with its use in SGML
attribute values as an entity reference delimiter.
For example, the URI `http://host/?x=1&y=2' must be
written `<a href="http://host/?x=1&#38;y=2"' or `<a
href="http://host/?x=1&amp;y=2">'.

HTTP server implementors, and in particular, CGI
implementors are encouraged to support the use of
`;' in place of `&' to save users the trouble of
escaping `&' characters this way.