ページ

2010年10月31日日曜日

MacRubyでGUIつきでググる

検索結果のURLを開いてるだけ。


# -*- coding: utf-8 -*-
framework 'Cocoa'
framework 'WebKit'
application = NSApplication.sharedApplication
# create the window
width = 800.0
height = 600.0
frame = [0.0, 0.0, width, height]
mask = NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask
window = NSWindow.alloc.initWithContentRect(frame,
styleMask:mask,
backing:NSBackingStoreBuffered,
defer:false)
# assign a content view instance
content_view = NSView.alloc.initWithFrame(frame)
window.contentView = content_view
# create a web view positioned in the top left quarter of the super view
web_view_frame = [0.0, 0.0, width, height] # [位置,位置,長さ,長さ] (開始位置は左下)
web_view = WebView.alloc.initWithFrame(web_view_frame, frameName: "Web Frame", groupName: nil)
request = NSURLRequest.requestWithURL(NSURL.URLWithString("http://www.google.co.jp/search?q=zakuni"))
web_view.mainFrame.loadRequest(request)
content_view.addSubview(web_view)
# center the window
window.center
# show the window
window.display
window.makeKeyAndOrderFront(nil)
window.orderFrontRegardless
application.run

2010年10月21日木曜日

sshでエラーが出たけどなんとかなった

 sshでログインしようとしたらこんなんが出た。(若干編集してあります)

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that the RSA host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
**************.
Please contact your system administrator.
Add correct host key in /Users/***/.ssh/known_hosts to get rid of this message.
Offending key in /Users/***/.ssh/known_hosts:3
RSA host key for ***.com has changed and you have requested strict checking.
Host key verification failed.

つまりはRSA host keyってのが変わったか何かしたから、直すなりなんなりしろってことらしい。
cyberduck使ったら普通に入れたし、頭にsudo付けて再度ログインしてもいけたけど、それじゃ解決してないし。
ググったら、known_hostsの該当部分を消してやり直したら解決できたという話が。

というわけでやってみると、以下のメッセージ


The authenticity of host '******.com (***.**.**.**)' can't be established.
RSA key fingerprint is ******************.
Are you sure you want to continue connecting (yes/no)? 

yesして、出来た。

なんか初歩の初歩っぽくて恥ずかしいけど気にしない。

2010年10月15日金曜日

rvmでインストールしたRubyをアップデート

なんかググッてもあんまり出てこないので。

rvm upgradeというコマンドを使えばできるみたい。

例えば既にインストールしてあるruby-1.8を1.9にしたいときは

rvm upgrade ruby-1.9 ruby-1.8

みたいにしてやればできる。
gemも引き継がれるので(確か引き継ぐかどうかも選択できる)、gemsetをexportしたりとかする必要もない。

もとのやつ(上の例だとruby-1.8)を消すか残すかも選択できるっぽいので、gemそのままでruby1.9をインストールしたいときとかも使えるのかも。

rvm install ruby-headとかでインストールしたものをアップデートするにはどうするんだろう。

2010年10月14日木曜日

rb-appscriptでRubyからAppleScriptを使う

参照: http://appscript.sourceforge.net/

まずはrb-appscriptというgemをインストール

sudo gem install rb-appscript

で、実際使うときは

require 'rubygems'
require 'appscript'
include Appscript 

require 'rb-appscript'じゃないのね。
include Appscriptはどうも本来必要ないっぽいのだけど、僕の環境では書いてないとエラーが出た。

あとはAppleScriptのコードをRubyな感じで書くだけ

例として、Firefoxを起動してカーソルキーの下を一回押すには

app('Firefox,app').activate
app('System Events').keystroke(31.chr) 

で、できるはず。

から、各アプリケーションが持ってるActionScriptを出力できるASDictionaryと、AppleScriptのコードをRubyとかPythonとかの文法に翻訳してくれるASTranlateがダウンロードできる。