Ruby Filter

どうせやるなら、Ruby の中でもパイプラインを構築できるようにすればいいのに。

require 'pp'
require 'uri'
require 'open-uri'
require 'rubygems'
require 'scrapi'

class Filter
   def initialize(&block)
      @proc = block
   end

   def |(filter)
      Filter.new do |arg|
         filter.execute(execute(arg))
      end
   end

   def execute(arg)
      @proc.call(arg)
   end
end

def parseURI
   Filter.new do |arg|
      URI.parse(arg)
   end
end

def getHTTP
   Filter.new do |uri|
      open(uri, 'r') do |fp|
         fp.read
      end
   end
end

def parseHTML
   Filter.new do |html|
      scraper = Scraper.define do
         process 'title',               :title => :text
         process 'link[title=RSS 2.0]', :rss20 => '@href'
         process 'link[title=RSS]',     :rss10 => '@href'
         process 'link[title=RSS 1.0]', :rss10 => '@href'
         process 'link[title=Atom]',    :atom  => '@href'

         result :title, :rss20, :rss10, :atom
      end
      scraper.scrape(html, :parser => :html_parser)
   end
end

if $0 == __FILE__
   pipeline = eval(ARGV.shift)
   uri = ARGV.shift

   pp pipeline.execute(uri)
end

こう使う。

% ruby filter.rb 'parseURI | getHTTP | parseHTML' 'http://d.hatena.ne.jp/odz/'
#<struct
 title="odz buffer",
 rss20="http://d.hatena.ne.jp/odz/rss2",
 rss10="http://d.hatena.ne.jp/odz/rss",
 atom=nil>

Google Desktop のホットキー

Windows では CraftLaunchEx にホットキー Win + Space を割り当てて使っているのだが、Google Desktop を入れてからホットキーが利かなくて困った。まぁ、多分 Google Desktop で Win + Space というホットキーを使っているんだろうけど、押しても何も起こらないし、設定画面は見つからないわで意味不明。
でまぁ、Google 先生に聞いてみたら答えが見つかった。

ということで、regedit で HKEY_CURRENT_USER\Software\Google\Google Desktop\Preferences に hot_key_flags という DWORD 値を作って 0 に設定、Google Desktop を再起動で Win + Space のホットキーが無効になる。
いや、しかしそもそも、ホットキーが動いてなかったように見えるのだが*1、ホットキーの登録だけはされている(から他のアプリでホットキー登録に失敗する)とか何事だろ。

*1:動作としては Gadget の表示/非表示切り替えらしい。同じ動作の shift 2回は動く