[#9811] Ruby book — WATANABE Tetsuya <tetsu@...>

今日のひとこと(10/05)

22 messages 1998/10/05
[#9812] Re: Ruby book — matz@... (Yukihiro Matsumoto) 1998/10/05

まつもと ゆきひろです

[#9813] Re: Ruby book — "D.Kanda" <MAP2303@...> 1998/10/05

[#9815] Re: Ruby book — matz@... (Yukihiro Matsumoto) 1998/10/05

まつもと ゆきひろです

[#9827] Are there any NNTP Client Class? — Takeshi UME Imai <takeshi@...>

はじめまして。今井といいます。

17 messages 1998/10/05
[#9828] Re: Are there any NNTP Client Class? — aamine@... 1998/10/05

はじめまして、あおきともうします。

[#9869] man-1.1/Marshal.html — ttate@...

立石です。

47 messages 1998/10/07
[#9872] Re: man-1.1/Marshal.html — matz@... (Yukihiro Matsumoto) 1998/10/08

まつもと ゆきひろです

[#9880] comments on manual (Re: man-1.1/Marshal.html) — Motoyuki Kasahara <m-kasahr@...> 1998/10/08

SRA の笠原です。

[#9881] Re: comments on manual (Re: man-1.1/Marshal.html) — matz@... (Yukihiro Matsumoto) 1998/10/08

まつもと ゆきひろです

[#9909] Re: comments on manual (Re: man-1.1/Marshal.html) — Motoyuki Kasahara <m-kasahr@...> 1998/10/09

SRA の笠原です。

[#9936] Re: comments on manual (Re: man-1.1/Marshal.html) — matz@... (Yukihiro Matsumoto) 1998/10/09

まつもと ゆきひろです

[#9939] Re: comments on manual (Re: man-1.1/Marshal.html) — Shin-ichro Hara <sinara@...> 1998/10/09

原です。

[#9940] Re: comments on manual (Re: man-1.1/Marshal.html) — matz@... (Yukihiro Matsumoto) 1998/10/09

まつもと ゆきひろです

[#9941] Re: comments on manual (Re: man-1.1/Marshal.html) — Shin-ichro Hara <sinara@...> 1998/10/09

原です。

[#9942] Re: comments on manual (Re: man-1.1/Marshal.html) — matz@... (Yukihiro Matsumoto) 1998/10/09

まつもと ゆきひろです

[#9944] read(nil) (Re: comments on manual) — Shin-ichro Hara <sinara@...> 1998/10/09

原です。

[#9884] List of UserInterface Kits for Ruby ? — a.furudo@...

20 messages 1998/10/08
[#9906] Re: List of UserInterface Kits for Ruby ? — matz@... (Yukihiro Matsumoto) 1998/10/09

まつもと ゆきひろです

[#9885] 文字化け失礼、再送 — Akihiro Furudo <a.furudo@...>

26 messages 1998/10/08
[#9888] Re: 文字化け失礼、再送 — ttate@... 1998/10/08

立石です。

[#9897] お礼と、 Ruby/Gtk(i18n) について質問 — Akihiro Furudo <A.Furudo@...> 1998/10/08

[#9982] Re: お礼と、 Ruby/Gtk(i18n) について質問 — Daisuke Kanda <MAP2303@...> 1998/10/11

[#10320] Ruby/Gtk を FreeBSD にインストール (re:9982) — Akihiro Furudo <a.furudo@...> 1998/10/24

[#10328] Re: Ruby/Gtk を FreeBSD にインストール (re:9982) — Daisuke Kanda <MAP2303@...> 1998/10/25

[#9976] ruby:struct -> ext module -> ruby — Kikutani Makoto <kikutani@...>

きくたにです。

17 messages 1998/10/11

[#9999] ruby on HP-UX — AU6M-IWM@... (Iwama Misao)

20 messages 1998/10/12
[#10001] Re: ruby on HP-UX — matz@... (Yukihiro Matsumoto) 1998/10/12

まつもと ゆきひろです

[#10030] Ruby/Gtk text widget — TAKAHASHI Masayoshi <maki@...>

高橋です。

29 messages 1998/10/12
[#10035] Re: Ruby/Gtk text widget — Daisuke Kanda <MAP2303@...> 1998/10/12

[#10038] ruby/gtk method naming (Re: Re: Ruby/Gtk text widget) — "D.Kanda" <MAP2303@...> 1998/10/13

[#10067] Re: ruby/gtk method naming (Re: Re: Ruby/Gtk text widget) — Kazumi Okamoto <kazusan@...> 1998/10/13

岡本です。

[#10092] for が修飾子だったら — ARIMA Yasuhiro <fit0298@...>

有馬@FITECです。

46 messages 1998/10/14
[#10093] Re: for が修飾子だったら — matz@... (Yukihiro Matsumoto) 1998/10/14

まつもと ゆきひろです

[#10236] Array.html again — Motoyuki Kasahara <m-kasahr@...>

笠原です。こんにちは。

18 messages 1998/10/22
[#10237] Re: Array.html again — Kanda <MAP2303@...> 1998/10/22

[#10239] Re: Array.html again — matz@... (Yukihiro Matsumoto) 1998/10/22

まつもと ゆきひろです

[#10311] Re: 大規模プログラムの友 — m_seki@... (SEKI)

At 11:23 PM 98.10.23 +0900, Takashi Nakai wrote:

24 messages 1998/10/23
[#10312] Re: 大規模プログラムの友 — Takashi Nakai <nakai@...1.sys.to.casio.co.jp> 1998/10/23

ど〜も、(またしても)中井です。

[#10369] Re: 大規模プログラムの友 — matz@... (Yukihiro Matsumoto) 1998/10/27

まつもと ゆきひろです

[#10415] split — flare@... (Takashi Ikeda)

ふれあです。

20 messages 1998/10/28

[#10473] case with Class — MineroAoki <aamine@...>

あおきです。

46 messages 1998/10/29
[#10483] Re: case with Class — matz@... (Yukihiro Matsumoto) 1998/10/30

まつもと ゆきひろです

[#10521] Re: case with Class — aamine@... 1998/10/30

こんにちは。あおきです。

[#10523] Re: case with Class — gotoken@... (GOTO Kentaro) 1998/10/30

ごとけんです

[#10530] Re: case with Class — aamine@... 1998/10/31

あおきです。

[#10544] Re: case with Class — shugo@... (MAEDA Shugo) 1998/10/31

前田です。

[#10548] Re: case with Class — Wakou Aoyama <wakou@...> 1998/10/31

青山です。

[#10555] Re: case with Class — shugo@... (MAEDA Shugo) 1998/11/01

前田です。

[#10566] Re: case with Class — Wakou Aoyama <wakou@...> 1998/11/01

青山です。

[ruby-list:9921] Re: signal 関係

From: Kazunori NISHI <kazunori@...>
Date: 1998-10-09 03:39:57 UTC
List: ruby-list #9921
西@九大です。

From: matz@netlab.co.jp (Yukihiro Matsumoto)
> 西さん辺りに実際のコードを出して頂けると参考になると思うので

呼ばれてノコノコ出て来た訳じゃないんですが、(イヤ、ほんまはその通りな
んですけど)実例として、稚拙ながら、私が利用している TimeStampObserver
というものを添付させて頂きます。

これは、指定された「Web の URL」や「ファイルのパス」からタイムスタンプ
(Web の場合は Last-Modified)を取得するだけのものなんですが、以下のよう
に「よく見る Web 関係の更新チェック」に利用できます。
#下記のサイトが「Last-Modified」を返すかどうかは知りませんが。

----------------------------------------------------------------------
#!/usr/local/bin/ruby

require "TimeStampObserver"

URIS = ["http://www.netlab.co.jp/ruby/jp/", "http://iij.asahi.com/", "file:."]
  
array = []

URIS .each do |uri|
  if observer = TimeStampObserver .new(uri)
    observer .seek # same as `.start'
    array << observer
  end
end

sleep 3

array .each do |observer|
  if observer .status
    observer .stop
    #      タイムアウト処理はここ
    p 'timeout!'
  else
    #      通常処理はここ
  end
end

array .sort .reverse .each do |observer|
  p [observer .uri, observer .time]
end
----------------------------------------------------------------------

タイムアウトとは直接関係ありませんが、一応、Thread と socket を利用し
ているという事で、参考になれば幸いです。

------------------------------------------------------------------
九州大学大学院システム情報科学研究科 情報工学専攻 博士後期課程二年
      西 和則   ( e-mail: kazunori@swlab.csce.kyushu-u.ac.jp )
------------------------------------------------------------------

require "socket"
require "thread"

######################################################################
### Class TimeStampObserver
###   aTimeStampObserver accepts an URI for a constructor argument
###   and gets the time stamp of it by `seek'(or `start') method.
###
### Author: Kazunori NISHI <kazunori@swlab.csce.kyushu-u.ac.jp>
### Created: Jun 10, 1998
### Revised: Oct  9, 1998
###

class TimeStampObserver
  MONTH = {
    'jan',  1, 'feb',  2, 'mar',  3, 'apr',  4,
    'may',  5, 'jun',  6, 'jul',  7, 'aug',  8,
    'sep',  9, 'oct', 10, 'nov', 11, 'dec', 12}
  
  attr :uri
  attr :time
  attr :method
  attr :locate
  attr :thread

  # 初期化。
  def initialize (uri)
    @time			# 最終改竄時刻(unix 秒)
    @uri			# 時刻を取る URI
    @method			# 時刻を取る手段
    @locate			# 時刻を取る対象の場所(ファイル名など)
    @thread			# 自分が使うスレッド
    @method, @locate = (@uri = uri) .split(/:/, 2)
  end

  # 定義された手段(@method)によって、時刻を取得し、@time に入れる
  def get_last_modified
    @time =
      case @method .downcase
      when "file"; self .get_time_stamp_local(@locate)
      when "http"; self .get_time_stamp_remote(@uri)
      when "const"; @uri .to_i
      when "comment"; 0
      end .to_i
    return self
  end

  def seek
    @thread = Thread .new {self .get_last_modified}
  end

  def stop
    if seeking?
      @time = 0
      @thread .exit
    end
  end

  def seeking?
    (@thread && @thread .status)
  end

  def <=> (other)
    @time <=> other .time
  end

  ######################################################################
  ## get time stamp of a local file
  ######################################################################
  def get_time_stamp_local (file)
    File::mtime(file) .to_i
  end

  ######################################################################
  ## Get last modified of a remote file by http
  ######################################################################
  def get_last_modified_by_http (url)
    begin
      if url =~ /http:\/\/([^\/]*)/
	host, port = $1 .split(/:/, 2)
	s = TCPsocket.open(host, port || 80)
	s .write("HEAD " + url + " HTTP/1.0\n\n")
	while s .gets()
	  return $_ if /^(Last-Altered:|Last[- ]Modified:)/i
	end
      end
      return nil
    rescue
      return nil
    end
  end

  def get_time_stamp_remote (uri)
    case self .get_last_modified_by_http (uri)
      # Last-Modified: Sun, 08 Mar 1998 13:49:00 GMT
    when /^Last-Altered: (.*)$/i
      return $1 .to_i
    when /^Last[- ]Modified: (.*)$/i
      week, day, mon, year, hour, min, sec = $1 .split(/[: ]/)
      return Time.gm(year.to_i - 1900, MONTH[mon.downcase], day.to_i,
		     hour.to_i, min.to_i, sec.to_i) .to_i
    else
      return -1
    end
  end

  alias start seek
  alias status seeking?

end

In This Thread