Fork me on GitHub

2011/04/26


このエントリーをはてなブックマークに追加
let [s:i,s:t]=[0,system("curl -L -s http://hackertyper.net/text.txt")]
funs:hacker_typing()
  let c=s:t[s:i]
  let s:i=s:i+1
  retu c
endfun
new|on!|setl ft=c noci noai nosi cink= |imapc
for c in range(1,255)|exe "inoremap <buffer> <expr> <char-".c."> <SID>hacker_typing()"|endfor
star!
ファイル開いて
:so %
で開始してね!
終了するには、「おっぱいおっぱい」と入力して下さい。
Posted at 17:27 in ソフトウェア::vim
Tagged as: vim, vimscript, ネタ
Bookmarks: add to hatena add to hatena | add to delicious.com | add to livedoor.clip add to livedoor.clip

2010/10/31


このエントリーをはてなブックマークに追加
古くからvimmerの人は知ってるかもしれませんが、昔excitetranslate.vimというスクリプトを書きました。 英語が書かれたバッファで
:ExciteTranslate
と実行すると分割ウィンドウに翻訳された文章が表示されるという物です。昨日githubにも入れておきました。
mattn's excitetranslate-vim at master - GitHub

Translate between English and Japanese using Excite

http://github.com/mattn/excitetranslate-vim
前は別のリポジトリに置いてあって、最初にリポジトリにcommitしたのが2006年でした。結構長く使っているスクリプトです。
これまでvimの環境を作る際には結構な頻度で入れてきたスクリプトですが、GoogleTranslateの方が場合によっては翻訳精度が高かったりするので、googletranslate.vimというのを書きました。

mattn's googletranslate-vim at master - GitHub

Translate between English and Japanese using Google

http://github.com/mattn/googletranslate-vim
使い方はexciteと同じく
:GoogleTranslate
で翻訳可能です。ちなみに文章が英語であれば日本語に、日本語であれば英語に翻訳されます。
Dan the Man with Too Many Home Appliances to Maintaitain

:GoogleTranslate
引用: http://blog.livedoor.jp/dankogai/archives/51541861.html
あまりにも多くの家電製品とダンマンはMaintaitainする

...

:ExciteTranslate
Maintaitainへのあまりに多くの家電をもっているダン男性
えぇ......っと。。。。。(汗
Posted at 00:51 in ソフトウェア::vim
Tagged as: googletranslate, vim, vimscript
Bookmarks: add to hatena add to hatena | add to delicious.com | add to livedoor.clip add to livedoor.clip

2010/10/10


このエントリーをはてなブックマークに追加
以前まではreadonlyなAPIでしたが、先日見たら更新出来る様になってた。
Google Buzz API - Google Code

Share Buzz updates New!

Full read/write support with:
  • Activity Streams
  • AtomPub
  • OAuth
  • PubSubHubbub
  • JSON

http://code.google.com/intl/ja/apis/buzz/
これはいかん!とばかりにvimscriptから更新してみた。

今回の対応で、vim-oauth(現在webapi-vimに取り込まれました)に幾らか修正をしました。
mattn's webapi-vim at master - GitHub

webapi-vim: vim interface to Web API

http://github.com/mattn/webapi-vim
以下、使用したスクリプト。
set rtp+=webapi-vim

let request_token_url = "https://www.google.com/accounts/OAuthGetRequestToken"
let access_token_url = "https://www.google.com/accounts/OAuthGetAccessToken"
let auth_url = "https://www.google.com/buzz/api/auth/OAuthAuthorizeToken"
let post_url = "https://www.googleapis.com/buzz/v1/activities/@me/@self"

let consumer_key = $CONSUMER_KEY
let consumer_secret = $CONSUMER_SECRET
let domain = $CONSUMER_DOMAIN
let callback = $CONSUMER_CALLBACK

let [request_token, request_token_secret] = oauth#requestToken(request_token_url, consumer_key, consumer_secret, {"scope": "https://www.googleapis.com/auth/buzz", "oauth_callback": callback})
if has("win32") || has("win64")
  exe "!start rundll32 url.dll,FileProtocolHandler ".auth_url."?oauth_token=".request_token."&domain=".domain."&scope=https://www.googleapis.com/auth/buzz"
else
  call system("xdg-open '".auth_url."?oauth_token=".request_token."'")
endif
let verifier = input("PIN:")
let [access_token, access_token_secret] = oauth#accessToken(access_token_url, consumer_key, consumer_secret, request_token, request_token_secret, {"oauth_verifier": verifier})
echo access_token
echo access_token_secret
let data = ''
\.'<entry xmlns:activity="http://activitystrea.ms/spec/1.0/"'
\.' xmlns:poco="http://portablecontacts.net/ns/1.0"'
\.' xmlns:georss="http://www.georss.org/georss"'
\.' xmlns:buzz="http://schemas.google.com/buzz/2010">'
\.'  <activity:object>'
\.'    <activity:object-type>http://activitystrea.ms/schema/1.0/note</activity:object-type>'
\.'    <content>Bzz! Bzz!</content>'
\.'  </activity:object>'
\.'</entry>'
let ret = oauth#post(post_url, consumer_key, consumer_secret, access_token, access_token_secret, {}, data, {"Content-Type": "application/atom+xml", "GData-Version": "2.0"})
echo ret
Atom APIなのでXMLでポストします。なお、今回GoogleのOAuthを使ったのですが、GoogleのOAuthってドメイン持ってないと使えないんですね。
私はここのサイトを使いましたが、Google App EngineでもOKです。

まずココでドメインを登録します。実はこのドメイン名がconsumer_keyとなります。ドメインを登録するとconsumer_secretが貰えます。
またコールバック先のURLが必要になります。通常登録したドメイン上でもよいのですが、別のサイトでも構わない様です。さらにGoogle OAuthではリクエストトークンを取得する際、およびベリファイアを貰う際にscopeパラメータが必要です。個々のGoogleサービスによって異なりますので、ココの一覧を参照して設定して下さい。なお、Google Buzzについてはリストアップされていませんが、色々探して見つけました。
さて次にアクセストークンを取得するのですが、ここで気をつけないとハマる問題がありあます。
Authentication in the Google Data Protocol - Google Data Protocol - Google Code

https://www.google.com/accounts/OAuthAuthorizeToken, referencing the request token and including the oauth_callback parameter. Google may prompt the user to log into their Google Account. Once authenticated with Google, the user chooses to share their data.

http://code.google.com/intl/ja/apis/gdata/docs/auth/overview.html
Googleのドキュメント通りでは成功しません。実は、このアクセストークン要求先は各サービスによって異なります。ここにアクセスしてもアクセストークン、アクセストークンシークレットは貰えるのですが、これを使ってアクセスしても401が返ります。Google Buzzであれば実際はGoogle Buzz専用の「https://www.google.com/buzz/api/auth/OAuthAuthorizeToken」にアクセスしなければなりません。こちらにはBuzzに対する許可設定画面も出てきます。
google-buzz-api1
ここまでくればあとはAtomでXMLを送ればちゃんとBuzzってくれます。

ちなみにココが証拠ポスト。

追記
ちなみに日本語もOKでした。
Posted at 02:02 in ソフトウェア::vim
Tagged as: buzz, google, google buzz, oauth, vim, vimscript
Bookmarks: add to hatena add to hatena | add to delicious.com | add to livedoor.clip add to livedoor.clip

2009/06/22


このエントリーをはてなブックマークに追加
アナウンスしてなかったですが、先日書いた「VimからFastLadderを扱えるスクリプトFastLadder.vim書いた。」ですが、LivedoorReaderに対応させています。
let g:fastladder_server = 'http://reader.livedoor.com'
とvimrcに書いておくと
:FastLadder
でLivedoorReaderのフィードが見れます。
今後はFastLadderやLivedoorReaderの様にフォルダ単位の閲覧が出来る様に改良して行く予定です。