<?xml version='1.0' encoding='UTF-8'?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/'><id>tag:blogger.com,1999:blog-20640549</id><updated>2008-01-28T14:39:31.693+09:00</updated><title type='text'>CodeBlog</title><link rel='alternate' type='text/html' href='http://pitecan.com/codeblog/'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20640549/posts/default'/><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://pitecan.com/codeblog/atom.xml'/><author><name>増井</name></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>18</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-20640549.post-7898181045274810498</id><published>2008-01-19T17:16:00.002+09:00</published><updated>2008-01-19T17:19:25.933+09:00</updated><title type='text'>RubyCocoaでスクリーンセーバを作る</title><content type='html'>MacOSでは
&lt;a href="http://developer.apple.com/documentation/UserExperience/Reference/ScreenSaver/Classes/ScreenSaverView_Class/Reference/Reference.html"&gt;ScreenSaverView&lt;/a&gt;
クラスを実装して.saverという名前のbundleに格納すればスクリーンセーバになる。
RubyCocoaでスクリーンセーバを書く方法を
&lt;a href="http://pitecan.com/RubySaver/"&gt;こちら&lt;/a&gt;に解説しておいた。</content><link rel='alternate' type='text/html' href='http://pitecan.com/codeblog/2008/01/rubycocoa_19.html' title='RubyCocoaでスクリーンセーバを作る'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=20640549&amp;postID=7898181045274810498' title='0 Comments'/><link rel='replies' type='application/atom+xml' href='http://pitecan.com/codeblog/atom.xml' title='Post Comments'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20640549/posts/default/7898181045274810498'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20640549/posts/default/7898181045274810498'/><author><name>増井</name></author></entry><entry><id>tag:blogger.com,1999:blog-20640549.post-6884804747755072626</id><published>2008-01-13T17:33:00.001+09:00</published><updated>2008-01-13T17:33:41.838+09:00</updated><title type='text'>自前のCプログラムをRubyCocoaから呼ぶ</title><content type='html'>Objective-CのメソッドをRubyCocoaから呼ぶのはとても簡単である。
&lt;br&gt;
πを計算する以下のようなクラスが存在するとき、

&lt;pre class="code"&gt;
#import &amp;lt;Cocoa/Cocoa.h&gt;

@interface Pi : NSObject
- (double)calc:(id)param;
@end

@implementation Pi
- (double)calc:(id)param
{
  // すごい方法でπを計算
  return 3.14159265358979;
}
@end
&lt;/pre&gt;

Xcodeを使ってこれからPi.frameworkを作成し、
/Library/Frameworksとかに置いておけば
以下のように簡単にRubyから呼び出すことができる。

&lt;pre class="code"&gt;
require 'osx/cocoa'
include OSX

NSBundle.bundleWithPath("/Library/Frameworks/Pi.framework").load
ns_import :Pi

class Pi &lt; NSObject
  addRubyMethod_withType('calc', 'v@:@')
end

pi = Pi.alloc.init
puts pi.calc(nil)
&lt;/pre&gt;

自前のCプログラムをすぐにRubyから使えるので便利である。</content><link rel='alternate' type='text/html' href='http://pitecan.com/codeblog/2008/01/crubycocoa.html' title='自前のCプログラムをRubyCocoaから呼ぶ'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=20640549&amp;postID=6884804747755072626' title='1 Comments'/><link rel='replies' type='application/atom+xml' href='http://pitecan.com/codeblog/atom.xml' title='Post Comments'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20640549/posts/default/6884804747755072626'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20640549/posts/default/6884804747755072626'/><author><name>増井</name></author></entry><entry><id>tag:blogger.com,1999:blog-20640549.post-4287164821092554402</id><published>2008-01-08T14:57:00.001+09:00</published><updated>2008-01-13T17:28:05.966+09:00</updated><title type='text'>10桁ISBNのチェックディジットの計算</title><content type='html'>&lt;pre class="code"&gt;
def add_checksum(isbn)
  v = 0
  (0..8).each { |i|
    v += isbn[i,1].to_i * (i+1)
  }
  v %= 11
  checksum = (v == 10 ? 'X' : v.to_s)
  isbn + checksum
end
&lt;/pre&gt;</content><link rel='alternate' type='text/html' href='http://pitecan.com/codeblog/2008/01/10isbn.html' title='10桁ISBNのチェックディジットの計算'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=20640549&amp;postID=4287164821092554402' title='0 Comments'/><link rel='replies' type='application/atom+xml' href='http://pitecan.com/codeblog/atom.xml' title='Post Comments'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20640549/posts/default/4287164821092554402'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20640549/posts/default/4287164821092554402'/><author><name>増井</name></author></entry><entry><id>tag:blogger.com,1999:blog-20640549.post-8510629262692438595</id><published>2008-01-07T09:16:00.000+09:00</published><updated>2008-01-13T17:29:06.253+09:00</updated><title type='text'>AppleRemoteをRubyで使う</title><content type='html'>Tim Burks氏の
&lt;a href="http://rubycocoa.com/appleremote"&gt;Use your Apple Remote from Ruby&lt;/a&gt;というサイトに
AppleRemote(最近のMacに付属してくる赤外線リモコン)をRubyで使う方法が載っている。
Martin Kahr氏が作った
&lt;a href="http://www.martinkahr.com/2007/07/26/remote-control-wrapper-20/"&gt;AppleRemote用ライブラリ&lt;/a&gt;を
framework化してビルドしてRubyから呼べばよいらしい。

&lt;p&gt;
現在(2008/1)のKahr氏のシステムは、
ソースコードの構成やライブラリの引数がBurks氏の記事とは異なっているが、
必要そうなものを全部まとめてframework化して以下のようにコードを少し変えると
無事動かすことができた。

&lt;pre class="code"&gt;
require 'osx/cocoa'
include OSX

NSBundle.bundleWithPath("/Library/Frameworks/AppleRemote.framework").load
ns_import :AppleRemote

class AppleRemoteDelegate &lt; NSObject
  addRubyMethod_withType('sendRemoteButtonEvent:pressedDown:remoteControl:', 'v@:ii@')

  def sendRemoteButtonEvent_pressedDown_remoteControl(buttonIdentifier, pressDown, remoteControl)
    puts "button #{buttonIdentifier}, pressed #{pressDown}"
  end
end


appleRemoteDelegate = AppleRemoteDelegate.alloc.init
appleRemote = AppleRemote.alloc.initWithDelegate(appleRemoteDelegate)
appleRemote.startListening self

NSApplication.sharedApplication.run
&lt;/pre&gt;</content><link rel='alternate' type='text/html' href='http://pitecan.com/codeblog/2008/01/appleremoteruby.html' title='AppleRemoteをRubyで使う'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=20640549&amp;postID=8510629262692438595' title='0 Comments'/><link rel='replies' type='application/atom+xml' href='http://pitecan.com/codeblog/atom.xml' title='Post Comments'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20640549/posts/default/8510629262692438595'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20640549/posts/default/8510629262692438595'/><author><name>増井</name></author></entry><entry><id>tag:blogger.com,1999:blog-20640549.post-6196047358056404898</id><published>2008-01-07T05:39:00.001+09:00</published><updated>2008-01-13T17:29:49.760+09:00</updated><title type='text'>Leopard上でのOpenGL/GLUT</title><content type='html'>&lt;a href="http://pitecan.com/UnixMagazine/PDF/if9908.pdf"&gt;昔のUnixMagazine記事&lt;/a&gt;で
OpenGLによるクロスプラットフォーム開発の話を書いたのだがMacは含まれていなかった。
OSXにはOpenGLとGLUTがFrameworkとして標準装備されているので、
以下のようにリンクするだけで簡単にビルドすることができる。

&lt;pre class="code"&gt;
-framework GLUT -framework OpenGL
&lt;/pre&gt;</content><link rel='alternate' type='text/html' href='http://pitecan.com/codeblog/2008/01/leopardopenglglut_07.html' title='Leopard上でのOpenGL/GLUT'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=20640549&amp;postID=6196047358056404898' title='0 Comments'/><link rel='replies' type='application/atom+xml' href='http://pitecan.com/codeblog/atom.xml' title='Post Comments'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20640549/posts/default/6196047358056404898'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20640549/posts/default/6196047358056404898'/><author><name>増井</name></author></entry><entry><id>tag:blogger.com,1999:blog-20640549.post-3022566625714498459</id><published>2007-12-26T08:06:00.000+09:00</published><updated>2008-01-13T17:30:25.498+09:00</updated><title type='text'>RubyOSA</title><content type='html'>&lt;a href="http://rubyosa.rubyforge.org/"&gt;RubyOSA&lt;/a&gt;
を使うとRubyからAppleScriptを操作できる。
&lt;br&gt;
例えば以下のスクリプトでiTunesの中の曲をリストできるので、
Rubyから検索したり自動再生したりできる。

&lt;pre class="code"&gt;
require 'rubygems'
require 'rbosa'

OSA::app('iTunes').sources[0].library_playlists[0].tracks.each { |s|
  puts "#{s.name} / #{s.album} / #{s.artist}"
}
&lt;/pre&gt;

この方式だとAppleScript臭が皆無になるのが嬉しいかも。</content><link rel='alternate' type='text/html' href='http://pitecan.com/codeblog/2007/12/rubyosa.html' title='RubyOSA'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=20640549&amp;postID=3022566625714498459' title='0 Comments'/><link rel='replies' type='application/atom+xml' href='http://pitecan.com/codeblog/atom.xml' title='Post Comments'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20640549/posts/default/3022566625714498459'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20640549/posts/default/3022566625714498459'/><author><name>増井</name></author></entry><entry><id>tag:blogger.com,1999:blog-20640549.post-4468730806606504526</id><published>2007-12-23T02:33:00.000+09:00</published><updated>2008-01-13T17:31:03.827+09:00</updated><title type='text'>RubyでMacの辞書アプリケーションを呼ぶ</title><content type='html'>アプリケーションのサービスを利用するとMacのアプリケーションの機能を
Rubyから呼び出すことができる。
例えば辞書アプリを以下のように呼び出すことができて便利。

&lt;pre class="code"&gt;
require 'osx/cocoa'

p = OSX::NSPasteboard.generalPasteboard                                                                                                                                       
p.declareTypes_owner([OSX::NSStringPboardType],self)                                                                                                                          
p.setString_forType("単語",OSX::NSStringPboardType)                                                                                                                           

OSX::NSPerformService("Look Up in Dictionary", p)
&lt;/pre&gt;</content><link rel='alternate' type='text/html' href='http://pitecan.com/codeblog/2007/12/rubymac.html' title='RubyでMacの辞書アプリケーションを呼ぶ'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=20640549&amp;postID=4468730806606504526' title='0 Comments'/><link rel='replies' type='application/atom+xml' href='http://pitecan.com/codeblog/atom.xml' title='Post Comments'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20640549/posts/default/4468730806606504526'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20640549/posts/default/4468730806606504526'/><author><name>増井</name></author></entry><entry><id>tag:blogger.com,1999:blog-20640549.post-7555802468227168339</id><published>2007-12-23T02:29:00.000+09:00</published><updated>2008-01-13T17:31:56.578+09:00</updated><title type='text'>iTunesをRubyで制御する</title><content type='html'>RubyCocoa経由でAppleScriptを呼ぶことによって
RubyからiTunesなどを制御できるようだ。
屋上屋を重ねる感じだが、とりあえず仕方がないのかも。

&lt;pre class="code"&gt;
require 'osx/cocoa'

script = OSX::NSAppleScript.alloc.initWithSource(%{
tell application "iTunes"                                                                                                                                                                                   
  play                                                                                                                                                                                                      
end tell                                                                                                                                                                                                    
})
errinfo = OSX::OCObject.new
result = script.executeAndReturnError(errinfo)
&lt;/pre&gt;</content><link rel='alternate' type='text/html' href='http://pitecan.com/codeblog/2007/12/itunesruby.html' title='iTunesをRubyで制御する'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=20640549&amp;postID=7555802468227168339' title='3 Comments'/><link rel='replies' type='application/atom+xml' href='http://pitecan.com/codeblog/atom.xml' title='Post Comments'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20640549/posts/default/7555802468227168339'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20640549/posts/default/7555802468227168339'/><author><name>増井</name></author></entry><entry><id>tag:blogger.com,1999:blog-20640549.post-117028089377412913</id><published>2007-02-01T06:55:00.000+09:00</published><updated>2007-02-01T07:01:33.806+09:00</updated><title type='text'>Greasemonkeyで外部スクリプトを呼ぶ</title><content type='html'>Greasemonkeyの中でprototype.jsなど外部のライブラリを呼ぶには以下のようにすればいいらしい。
&lt;ul&gt;
&lt;li&gt;&lt;a href='http://d.hatena.ne.jp/ysano2005/20060127/1138382734'&gt;CMS Researcher氏&lt;/a&gt;
&lt;li&gt;&lt;a href='http://rektunpe.sakura.ne.jp/diary/?date=20070107'&gt;たかはしまさゆ記&lt;/a&gt;
&lt;/ul&gt;
面倒だけれども使える。</content><link rel='alternate' type='text/html' href='http://pitecan.com/codeblog/2007/02/greasemonkey.html' title='Greasemonkeyで外部スクリプトを呼ぶ'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=20640549&amp;postID=117028089377412913' title='0 Comments'/><link rel='replies' type='application/atom+xml' href='http://pitecan.com/codeblog/atom.xml' title='Post Comments'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20640549/posts/default/117028089377412913'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20640549/posts/default/117028089377412913'/><author><name>増井</name></author></entry><entry><id>tag:blogger.com,1999:blog-20640549.post-115543786352430222</id><published>2006-08-13T11:56:00.000+09:00</published><updated>2006-08-13T11:57:43.536+09:00</updated><title type='text'>Rubilicious</title><content type='html'>del.icio.us APIは仕様が変わったようなので古いRubiliciousが動かなくなってしまったようだ。
&lt;a href="http://masao.jpn.org/d/2006-08.html#2006-08-11"&gt;まさお氏のパッチ&lt;/a&gt;で直るようだ。</content><link rel='alternate' type='text/html' href='http://pitecan.com/codeblog/2006/08/rubilicious.html' title='Rubilicious'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=20640549&amp;postID=115543786352430222' title='0 Comments'/><link rel='replies' type='application/atom+xml' href='http://pitecan.com/codeblog/atom.xml' title='Post Comments'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20640549/posts/default/115543786352430222'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20640549/posts/default/115543786352430222'/><author><name>増井</name></author></entry><entry><id>tag:blogger.com,1999:blog-20640549.post-114618866540184022</id><published>2006-04-28T10:42:00.000+09:00</published><updated>2006-04-28T10:44:25.410+09:00</updated><title type='text'>Rubilicious</title><content type='html'>&lt;a href="http://pablotron.org/software/rubilicious/"&gt;Rubilicious&lt;/a&gt;から
&lt;a href="http://del.icio.us/masui"&gt;del.icio.us&lt;/a&gt;へのアクセスがエラーになるのでいろいろ調べていたら
勝手に直ってしまった。
&lt;br&gt;
&lt;a href="http://del.icio.us/masui"&gt;del.icio.us&lt;/a&gt;にしばらくアクセスしないとエラーになるんだろうか?</content><link rel='alternate' type='text/html' href='http://pitecan.com/codeblog/2006/04/rubilicious.html' title='Rubilicious'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=20640549&amp;postID=114618866540184022' title='0 Comments'/><link rel='replies' type='application/atom+xml' href='http://pitecan.com/codeblog/atom.xml' title='Post Comments'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20640549/posts/default/114618866540184022'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20640549/posts/default/114618866540184022'/><author><name>増井</name></author></entry><entry><id>tag:blogger.com,1999:blog-20640549.post-114035882855854877</id><published>2006-02-19T23:17:00.000+09:00</published><updated>2006-02-19T23:20:28.570+09:00</updated><title type='text'>SQLite</title><content type='html'>&lt;a href="http://hondana.org/"&gt;本棚.org&lt;/a&gt;がどうにも遅いのでSQLiteという簡易RDBを試してみたところ、
ファイルを利用してデータベースを構築するよりはかなり高速に処理できることがわかった。
SQLiteでは全データがひとつのファイルとして扱われるのだが
本棚.org全データで30MBぐらいになる。意外と小さい。
毎日バックアップをとっても困らないかもしれない。
&lt;br&gt;
...というわけで完全移行しようと思う。いつごろできるやら。</content><link rel='alternate' type='text/html' href='http://pitecan.com/codeblog/2006/02/sqlite.html' title='SQLite'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=20640549&amp;postID=114035882855854877' title='0 Comments'/><link rel='replies' type='application/atom+xml' href='http://pitecan.com/codeblog/atom.xml' title='Post Comments'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20640549/posts/default/114035882855854877'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20640549/posts/default/114035882855854877'/><author><name>増井</name></author></entry><entry><id>tag:blogger.com,1999:blog-20640549.post-113929944691944304</id><published>2006-02-07T17:02:00.000+09:00</published><updated>2006-02-07T17:04:06.926+09:00</updated><title type='text'>TCP通信のログを見る</title><content type='html'>田中氏作のdebug-socket.rbを利用すると、
TCP通信のログを見ることができる。
&lt;pre class='code'&gt;
require 'debug-socket'
require "xmlrpc/client"

server = XMLRPC::Client.new("b.hatena.ne.jp", "/xmlrpc", 80)
ok, param = server.call2("bookmark.getCount","http://d.hatena.ne.jp/")

param.each { |key,val|
  puts key
  puts val
}
&lt;/pre&gt;
などとするとXMLRPCのログが/tmpに残る。</content><link rel='alternate' type='text/html' href='http://pitecan.com/codeblog/2006/02/tcp.html' title='TCP通信のログを見る'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=20640549&amp;postID=113929944691944304' title='0 Comments'/><link rel='replies' type='application/atom+xml' href='http://pitecan.com/codeblog/atom.xml' title='Post Comments'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20640549/posts/default/113929944691944304'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20640549/posts/default/113929944691944304'/><author><name>増井</name></author></entry><entry><id>tag:blogger.com,1999:blog-20640549.post-113720913740338607</id><published>2006-01-14T12:24:00.000+09:00</published><updated>2006-01-29T11:00:24.680+09:00</updated><title type='text'>Emacsに色をつける</title><content type='html'>&lt;a href="http://pitecan.com/codeblog/images/coloremacs.jpg" border=none&gt;&lt;img src="http://pitecan.com/codeblog/images/coloremacs.jpg" width="234"&gt;&lt;/a&gt;
インデントに応じて色を変えると便利かと思ったのだが、
こういうことをするためには
&lt;a href="http://www.fan.gr.jp/%7Ering/doc/elisp-manual/elisp_513.html#SEC514"&gt;文字ごとに属性を設定しなければならないらしい&lt;/a&gt;。
面倒なのでやる気がうせたが一応作ってみた。
&lt;pre class="code"&gt;
(setq indent-colors
     '(
       "DarkSeaGreen1"
       "DarkSeaGreen2"
       "DarkSeaGreen3"
       "DarkSeaGreen4"
       "SeaGreen1"
       "SeaGreen2"
       "SeaGreen3"
       "SeaGreen4"
       "PaleGreen1"
       "PaleGreen2"
       "PaleGreen3"
       ))

(defun set-indent-color ()
 (let (symbol face indent)
   (setq indent (% (indent-level) (length indent-colors)))
   (setq symbol (make-symbol (concat "indent" (format "%d" indent))))
   (setq face (make-face symbol))
   (set-face-foreground face "black")
   (set-face-background face (indent-color indent))
   (save-excursion
     (let (start end)
       (beginning-of-line)
       (setq start (point))
       (end-of-line)
       (setq end (point))
       (if (looking-at "\n") (setq end (1+ (point))))
       (put-text-property start end 'face face)
       ))
   ))

(defun set-indent-colors ()
 (save-excursion
   (let (old new (done nil))
     (goto-char 1)
     (setq old (point))
     (while (not done)
       (set-indent-color)
       (forward-line)
       (setq new (point))
       (setq done (= old new))
       (setq old new)
       )
   )))

(defun indent-color (indent)
 (let (c)
   (setq c (nth indent indent-colors))
   (if (null c)
       (setq c "white"))
   c
   ))

(defun indent-level ()
 (save-excursion
   (progn
     (beginning-of-line)
     (re-search-forward "[^ \t]" nil t)
     (backward-char)
     (current-column)
     )))
&lt;/pre&gt;</content><link rel='alternate' type='text/html' href='http://pitecan.com/codeblog/2006/01/emacs.html' title='Emacsに色をつける'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=20640549&amp;postID=113720913740338607' title='1 Comments'/><link rel='replies' type='application/atom+xml' href='http://pitecan.com/codeblog/atom.xml' title='Post Comments'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20640549/posts/default/113720913740338607'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20640549/posts/default/113720913740338607'/><author><name>増井</name></author></entry><entry><id>tag:blogger.com,1999:blog-20640549.post-113694855254515837</id><published>2006-01-11T12:02:00.000+09:00</published><updated>2006-01-18T23:27:12.820+09:00</updated><title type='text'>Windows/Mac上のRubyスクリプトをDrag&amp;Dropで動かす</title><content type='html'>WindowsでもMacintoshでも、
ファイルをアイコンにDrag&amp;DropすることによってRubyスクリプトを起動することができる。
&lt;ul&gt;
&lt;li&gt;Windowsの場合:
&lt;p&gt;
xxxx.batというバッチファイルを作り、以下のようにRubyスクリプトを記述する。
&lt;pre class="code"&gt;
\cygwin\usr\local\bin\ruby -S -x %0 %1 %2
exit
#!ruby
file = ARGV[0]
(...普通のRubyスクリプト)
&lt;/pre&gt;
&lt;li&gt;Macintoshの場合:
&lt;p&gt;
AppleScriptを使う。
スクリプトエディタで以下のようなスクリプトを作成し、
「アプリケーション形式」で保存するとxxxx.appのような名前のアプリケーション
(ドロップレット)ができ、Drag&amp;DropしたファイルがfileListに渡されるので、
これらを連結して引数としてxxxx.rbに渡す。

&lt;pre class="code"&gt;
on open (fileList)
  set args to ""
  repeat with i in fileList
    set arg to POSIX path of i
    set args to args &amp; " " &amp; arg
  end repeat
  do shell script "ruby xxxx.rb " &amp; args
end open 
&lt;/pre&gt;
&lt;/ul&gt;</content><link rel='alternate' type='text/html' href='http://pitecan.com/codeblog/2006/01/windowsmacrubydragdrop.html' title='Windows/Mac上のRubyスクリプトをDrag&amp;Dropで動かす'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=20640549&amp;postID=113694855254515837' title='0 Comments'/><link rel='replies' type='application/atom+xml' href='http://pitecan.com/codeblog/atom.xml' title='Post Comments'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20640549/posts/default/113694855254515837'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20640549/posts/default/113694855254515837'/><author><name>増井</name></author></entry><entry><id>tag:blogger.com,1999:blog-20640549.post-113677123559131056</id><published>2006-01-09T10:46:00.000+09:00</published><updated>2006-01-18T23:06:57.690+09:00</updated><title type='text'>RubyでExifライブラリ(libexif)を使う</title><content type='html'>RubyからExifファイル(デジカメのJPEG拡張形式)を扱うlibexif-rubyのインストールメモ。(Cygwin)
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://sourceforge.net/projects/libexif"&gt;SourceForge&lt;/a&gt;から
&lt;a href="http://prdownloads.sourceforge.net/libexif/libexif-0.6.13.tar.gz?download"&gt;libexif-0.6.13&lt;/a&gt;
を入手したがConfigureに失敗するので
&lt;a href="http://prdownloads.sourceforge.net/libexif/libexif-0.6.12.tar.gz?download"&gt;libexif-0.6.12&lt;/a&gt;
を入手してインストール。
&lt;li&gt;libexif-rubyはオリジナルのものがうまく使えないので
&lt;a href="http://packages.qa.debian.org/libe/libexif-ruby.html"&gt;Debian&lt;/a&gt;の
&lt;a href="http://ftp.debian.org/debian/pool/main/libe/libexif-ruby/libexif-ruby_0.1.2.orig.tar.gz"&gt;libexif-ruby_0.1.2.orig.tar.gz&lt;/a&gt;
に
&lt;a href="http://ftp.debian.org/debian/pool/main/libe/libexif-ruby/libexif-ruby_0.1.2-7.diff.gz"&gt;libexif-ruby_0.1.2-7.diff.gz&lt;/a&gt;
のパッチをあててruby extconf.rb; makeするとうまくいく。
&lt;/ul&gt;</content><link rel='alternate' type='text/html' href='http://pitecan.com/codeblog/2006/01/rubyexiflibexif.html' title='RubyでExifライブラリ(libexif)を使う'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=20640549&amp;postID=113677123559131056' title='0 Comments'/><link rel='replies' type='application/atom+xml' href='http://pitecan.com/codeblog/atom.xml' title='Post Comments'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20640549/posts/default/113677123559131056'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20640549/posts/default/113677123559131056'/><author><name>増井</name></author></entry><entry><id>tag:blogger.com,1999:blog-20640549.post-113671186426323734</id><published>2006-01-08T18:12:00.000+09:00</published><updated>2006-01-09T08:49:47.643+09:00</updated><title type='text'>JavaScriptで認意のサイトと通信する方法</title><content type='html'>Ajaxで使われる
XMLHttpRequestでは別サイトと通信を行なうことはできないのだが、
scriptタグを使うと認意のサイトと通信を行なうことができることをmala先生に教えてもらった。
(&lt;a href="http://la.ma.la/misc/js/jsan.html"&gt;mala氏のコード&lt;/a&gt;)


以下のようなコードで動的にscript要素を生成し、
JavaScriptプログラムを吐くCGIを呼び出す。

&lt;pre class="code"&gt;
var s=document.createElement("script");
s.charset="UTF-8";
s.type = "text/javascript";
s.src="http://pitecan.com/xxx.cgi";
document.body.appendChild(s)
&lt;/pre&gt;
たとえばxxx.cgiが
&lt;pre class="code"&gt;
a = 100;
&lt;/pre&gt;
というテキストを返す場合、
このコードが非同期的に実行されてaに100が代入される。
(appendChildの実行終了後すぐにこのコードが実行されるわけではないことに注意が必要である)
&lt;p&gt;
しかしscriptタグでこういうことができるのならば
普通のAjaxで使うXMLHttpRequestは不要ということなのだろうか?
不思議。&lt;/p&gt;</content><link rel='alternate' type='text/html' href='http://pitecan.com/codeblog/2006/01/javascript.html' title='JavaScriptで認意のサイトと通信する方法'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=20640549&amp;postID=113671186426323734' title='0 Comments'/><link rel='replies' type='application/atom+xml' href='http://pitecan.com/codeblog/atom.xml' title='Post Comments'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20640549/posts/default/113671186426323734'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20640549/posts/default/113671186426323734'/><author><name>増井</name></author></entry><entry><id>tag:blogger.com,1999:blog-20640549.post-113660418257559507</id><published>2006-01-07T12:22:00.000+09:00</published><updated>2006-01-07T12:23:02.583+09:00</updated><title type='text'>CodeBlog</title><content type='html'>g新部氏のプロジェクトに参加してコードブログを書く。
RubyとかJavaScriptとかのプログラムを読んでみよう。</content><link rel='alternate' type='text/html' href='http://pitecan.com/codeblog/2006/01/codeblog.html' title='CodeBlog'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=20640549&amp;postID=113660418257559507' title='0 Comments'/><link rel='replies' type='application/atom+xml' href='http://pitecan.com/codeblog/atom.xml' title='Post Comments'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20640549/posts/default/113660418257559507'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20640549/posts/default/113660418257559507'/><author><name>増井</name></author></entry></feed>