2008/03/31

はてな
今すぐこのページ
javascript:void(function(n){m=/profile_s\.gif$/;for(i=0;i<n.length;i++){if(m.test(n[i].src)){n[i].src='http://mattn.kaoriya.net/images/unk.gif'}}})(document.getElementsByTagName('img'))
するんだ!

はてな
コンパイルは通るだろうけど、ちょっと本文から直してほしいですね。影響力のある場所でしかも「推薦する」なんてリンクが付いている状態で放置は間違いを広めてしまうよ。
C/C++のポインタの機能--参照渡しのような処理 - builder by ZDNet Japan
で、Electric Fenceの紹介につなげる記事にしようと思ったのですが
electric-fence-win32 - Google Code
Electric Fenceのwin32版なんてものを見つけてしまった。
てっきりUNIX版と同様、リンクすれば動くと思って色々試したけど、どうやらそうじゃないみたい。
//#include <efence.h>
#include <stdio.h>
int main( void ) {
    char *a = (char*)malloc(12);
    a[ 0] = 'H';
    a[ 1] = 'e';
    a[ 2] = 'l';
    a[ 3] = 'l';
    a[ 4] = 'o';
    a[ 5] = ',';
    a[ 6] = ' ';
    a[ 7] = 'W';
    a[ 8] = 'o';
    a[ 9] = 'r';
    a[10] = 'l';
    a[11] = 'd';
    a[12] = '\0';
    return 0;
}
オーバーランを検知してくれなかった。README.win32によると

Since you need to modify your own project anyway, simply add efence.c, page-win32.c, and print.c to your project.

と書いてありました。てっきりスタートアップルーチンを入れ替えてくれてくれる物かと思って少しだけ期待してしまいました。
mingw32ならば
Index: Makefile
===================================================================
--- Makefile    (revision 7)
+++ Makefile    (working copy)
@@ -9,7 +9,7 @@
 MAN_INSTALL_DIR= /usr/man/man3
 
 PACKAGE_SOURCE= README libefence.3 Makefile efence.h \
-   efence.c page.c print.c eftest.c tstheap.c CHANGES COPYING
+   efence.c page-win32.c print.c eftest.c tstheap.c CHANGES COPYING
 
 # Un-comment the following if you are running HP/UX.
 # CFLAGS= -Aa -g -D_HPUX_SOURCE -DPAGE_PROTECTION_VIOLATED_SIGNAL=SIGBUS
@@ -26,7 +26,7 @@
 # as well if using Sun's compiler, -static if using GCC.
 # CFLAGS= -g -Bstatic -DPAGE_PROTECTION_VIOLATED_SIGNAL=SIGBUS
 
-OBJECTS= efence.o page.o print.o
+OBJECTS= efence.o page-win32.o print.o
 
 all:   libefence.a tstheap eftest
    @ echo
@@ -63,7 +63,7 @@
 
 tstheap: libefence.a tstheap.o
    - rm -f tstheap
-   $(CC) $(CFLAGS) tstheap.o libefence.a -o tstheap -lpthread
+   $(CC) $(CFLAGS) tstheap.o libefence.a -o tstheap -lpthreadGC2
 
 eftest: libefence.a eftest.o
    - rm -f eftest
こんな風に修正して
mingw32-make CC=gcc libefence.a
でlibefence.aが出来上がり、上のソースの冒頭の「//」を外して
#include <efence.h>
#include <stdio.h>
int main( void ) {
    char *a = (char*)malloc(12);
    a[ 0] = 'H';
    a[ 1] = 'e';
    a[ 2] = 'l';
    a[ 3] = 'l';
    a[ 4] = 'o';
    a[ 5] = ',';
    a[ 6] = ' ';
    a[ 7] = 'W';
    a[ 8] = 'o';
    a[ 9] = 'r';
    a[10] = 'l';
    a[11] = 'd';
    a[12] = '\0';
    return 0;
}
あぶないコードに修正した後
gcc -g -o dame.exe dame.c -lefence
とすれば、efenceビルドされたdame.exeが出来上がり実行すると、正しくクラッシュしてくれる。gdbで確認すれば
C:¥temp¥electric-fence-win32>gdb dame.exe
GNU gdb 6.3
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i686-pc-mingw32"...
(gdb) run
Starting program: C:¥temp¥electric-fence-win32/dame.exe
...
Program received signal SIGSEGV, Segmentation fault.
0x00401396 in main () at dame.c:17
17              a[12] = '\0';
(gdb)
とクラッシュ場所も分かると。でもUNIX版みたくソースは修正したくないなぁ。
あとmallocでなく
char a[12];
とした場合にクラッシュしてくれないのならば、威力半減ってところか。

はてな
嘘。難読化っていうか、これバグだな...
Vim script line continuation? - vim_dev | Google グループ

Well, it seems the new line continuation can be placed weirdly, which will make the vim script syntax file even messy when considering the line continuation. Any comments?

検証コード
e
\c
\h
\o
\ "
\
\
\P
\l
\a
\!"

それPla!

2008/03/27

はてな
追記
os0xさんが、マルチプラットフォームで動くしかもブックマークレットで起動出来るAutoPagerize for IE6公開されておられます。
「できた!」とほぼ同時にtwitterに書き込んでたのが笑った。
確かに、iframeを使えばXHRを使った場合と違ってresponseTextからcreateContextualFragment等で苦労する事無く、同じドメイン内のiframeだからDOM操作が出来ると...
諦め所がXPath(responseTextからcreateDocumentが出来ないという意味で)でなく、XHRを諦めるべきだったかも。

でけれた。
AutoPagerizeとか、oAutoPagerizeとか、jAutoPagerizeとかをベースに改造しようかと思ったけど、結局XPathでつまづいた。
AutoPagerizeを実現するには、カレントのdocumentとは別のdocumentに読み込んだHTMLを入れてページ部を抽出する必要があるんだけど、IE6ではカレントdocumentにappencChildしないとXPathセレクタが動かない(amachangのJavaScript-XPathで検証)。また、createRange/createContextualFragmentも動かないだろうし、どちみち駄目。
つまり、XPathは実現出来ない事になる。
諦めて、mala氏が作ったオリジナル、「GoogleAutoPager」をベースに作り直した。
で、最初はGoogleだけでいいかと思ったけど、欲が出てtwitterやtumblr、d.hatena.ne.jp、b.hatena.ne.jpでも動かせるようにした。
iAutoPagerize
アイコンとかはありません。ダブルクリックで起動です。
但し、セレクタとしてはCSSセレクタを使ってるので、特殊な調べ方は出来ない。しかもIE6なのでCSSのバージョンが低い。

セレクタライブラリとしてはjQueryを使用しています。動かす為にはTrixieが必要です。Trixieをインストール後
C:¥Program Files¥Bhelpuri¥Trixie¥Scripts¥
に以下のリンクにあるiAutoPagerize.user.jsを放り込めばインストールは完了。現状、SITEINFOはベタ打ちです。今後SITEINFOサーバを用意するつもりもありません。ただ、codereposに置いておくので誰でも修正出来る様にしておきます。

ネーミングは、「OperaのがoAutoPagerize」なら「IEはiAutoPagerize?」くらいの思考能力で付けた名前です。

よろしかったらどうぞ。
iAutoPagerize


はてな
またまた知らなかった。勉強不足。
例えば
<div class="foo">
    <p>
        <span class="test1">title1</span>
    </p>
    <ul>
        <li>list1</li>
        <li>list2</li>
        <li>list3</li>
    </ul>
</div>

<div class="foo">
    <div>
        <span class="test1">title2</span>
    </div>
    <ul>
        <li>list1</li>
        <li>list2</li>
        <li>list3</li>
    </ul>
</div>

<div class="foo">
    <div>
        <span class="test2">title3</span>
    </div>
    <ul>
        <li>list1</li>
        <li>list2</li>
        <li>list3</li>
    </ul>
</div>
こんなHTMLで
  • class属性"foo"を持つdiv
  • その孫にclass属性"test1"を持つspan
  • 上の条件下にある上記divの孫にあるli
を検索したい場合
//div[@class="foo"]//span[@class="test1"]/../..//li
こう書いてたんですが、これだとliの階層が深い場合に".."を書く個数が限定されてしまっていました。
で、今日知ったのですが、expr部には「@xxx="yyy"」といったexprだけでなくパスも書けるのを知った。
//div[@class="foo" and .//span[@class="test1"]]//li
これだとcurrent-contextとして
  • class属性"foo"を持つdiv
を保ったままliを検索出来る訳。勉強不足だな。
上の例だとtitle1の下のliと、title2の下のliがマッチする。

ところで皆さんはXPathをテストしたい場合、何を使ってますか?
私はjAutoPagerizeを使っています。jAutoPagerizeはcho45氏作のAutoPagerizeクローンで、私は本家を使わずこちらを使っています。
なぜこれを使っているかというと、jAutoPagerize本来の機能も良いのですがXPathGeneratorが付いているからです。
jAutoPagerizeをインストールすると
jautopagerize-icon
というアイコンが画面右上に出るのですが、これをクリックすると
jautopagerize-xpathgenerator
といった形でXPathの入力画面が現れます。ここにXPathを書いて"TAB"キー等でフォーカスを外すと
jautopagerize-xpathresult
と赤くハイライトされるのです。視覚的にも分かりやすいですね。他直接ノードからXPathを取得するInspectボタンもクラス名を知るのに使えます。
また、AutoPagerize対応でないページでアイコンが出ていなくても
XPathGenerator
こんなブックマークレットさえ用意しておけば、何時でもXPathGeneratorを表示出来るようになります。

XPathGeneratorかわいいよXPathGenerator

2008/03/26

はてな
なんか久々。
/lang/perl/plagger/lib/Plagger/Plugin/Publish/Diigo.pm - CodeRepos::Share - Trac
www.diigo.com...ブックマークレットから実行出来る専用ポスト画面がなかなかカッコイイ。
今回はこのブックマークレットのhackで作った。

これで、私が同期しているソーシャルブックマークは
  • Publish::Delicious
  • Publish::LivedoorClip
  • Publish::Buzzurl
  • Publish::LivedoorCilp
  • Publish::Buzzurl
  • Publish::GooBookmark
  • Publish::NiftyClip
  • Publish::Pookmark
  • Publish::YahooBookmark
  • Publish::FC2Bookmark
  • Publish::BlueDot という名の Pubilsh::Delicious
  • Publish::Magnolia という名の Publish::Delicious
  • Publish::Diigo
となった。
以下、今後変わっていくかもしれないけどコード。

続きを読む...


はてな
昨日kuさんが頑張って探してたのはなんだったんだろう...苦笑
朝起きたらAPIが出来てました。確か昨日「/api」にアクセスしても無かったのになぁ。
FriendFeed Blog: FriendFeed API: Extend and improve FriendFeed

We are very excited to announce the launch of the FriendFeed API, which enables developers to interact with the FriendFeed site programmatically. It's designed to make it possible for anyone to improve FriendFeed or integrate FriendFeed into other applications. You can develop a FriendFeed interface for a mobile phone, build a FriendFeed widget for your blog, or develop an application that makes it easy to post photos to your feed from your iPhone.

さっそく使ってみました。APIはJSON、XML、RSS、ATOMで提供されており、クライアントライブラリとしてPHPとpythonのライブラリが用意されています。
つまり、XMLフォーマットを使っているgtktwitterを改造してgtkfriendfeedなんて事も出来る訳ですね。
ApiDocumentation - friendfeed-api - Google Code
friendfeed-api - Google Code
twitterと同じくprivateでなければ認証無しでアクセス出来ます。
認証が必要な場合は、「remotekey」と呼ばれるアプリケーションキーを取得する必要があります。remotekeyは
FriendFeed - Remote Key
で取得出来ます。認証方法はBasic認証です。今日は認証を使わない例ですが、javascriptからjsonで私と、kuさんと、otsuneさんのフィードをミックス表示する例をサンプルとして上げておきます。
まずコード
<style type="text/css"><!--
#mattn_friendfeed {
    margin: 1em;
    font-family: Verdana;
    width: 400px;
}
#mattn_friendfeed a {
    color: blue;
}
.friendfeed-line {
    padding-bottom: 1em;
}
.friendfeed-link {
    font-size: small;
}
--></style>
<script type="text/javascript"><!--
function mattn_friendfeed_callback(data) {
    var container = document.createElement('div');
    for(var n = 0; n < data.entries.length; n++) {
        var user = document.createElement('a');
        var link = document.createElement('a');
        var line = document.createElement('div');
        var icon = document.createElement('img');
        var br = document.createElement('br');
        user.href = data.entries[n].user.profileUrl;
        link.className = 'friendfeed-link';
        link.href = data.entries[n].link;
        link.appendChild(document.createTextNode(link.href));
        icon.src = user.href + '/picture?size=small';
        icon.setAttribute('align', 'left');
        user.appendChild(icon);
        br.setAttribute('clear', 'all');
        line.className = 'friendfeed-line';
        line.appendChild(user);
        line.appendChild(document.createTextNode(' ' + data.entries[n].title + ' '));
        line.appendChild(document.createElement('br'));
        line.appendChild(link);
        line.appendChild(br);
        container.appendChild(line);
    }
    document.getElementById('mattn_friendfeed').innerHTML = container.innerHTML;
}
function show_mattn_friendfeed() {
    document.getElementById('mattn_friendfeed').innerHTML = '<img src="http://mattn.kaoriya.net/images/ajax-loader.gif">';
    var s = document.createElement('script');
    s.charset = 'utf-8';
    s.src = 'http://friendfeed.com/api/feed/user?nickname=mattn,otsune,ku0522&callback=mattn_friendfeed_callback';
    document.body.appendChild(s);
}
--></script>
<input type="button" value="mattnのfriendfeedエントリを表示" onclick="show_mattn_friendfeed();" />
<br />
<em>mattnと、ku0522さんと、otsuneさんのmix表示</em><br />
<div id="mattn_friendfeed"></div>

そして実行例

続きを読む...


2008/03/25

はてな
最近私もFirefox3を使い始めたのですが、Operator 0.9.1と組み合わせると、microformatsが「hCard」と「adr」だけになってしまい、少し困ってました。 何かのバグにしてはエラーコンソールに何も出ないし悩んでいたのですが、今日ソースを見て納得。
Firefox3からは、ブラウザ自身でmicroformatsを解析出来る仕組みが入ったのですが、その対応がOperatorに中途半端に入っている様です。
chromeからmicroformatsを扱う為には
Components.utils.import("resource://gre/modules/Microformats.js");
というコードが必要なのですが、この処理がコメントアウトされていました。
実際には
$(FIREFOX_PROFILE)/extensions/{95C9A302-8557-4052-91B7-2BB6BA33C885}/chrome/operator.jar
に含まれる
content/operator.js
が原因で、パッチで表すならば以下の様な感じ。
--- chrome/content/operator.js.orig Wed Mar 19 11:44:26 2008
+++ chrome/content/operator.js  Tue Mar 25 19:11:01 2008
@@ -77,7 +77,7 @@
     /* Attempt to use the Microformats module if available (Firefox 3) */
     if (Components.utils.import) {
       try {
-//        Components.utils.import("resource:///modules/Microformats.js");
+        Components.utils.import("resource:///modules/Microformats.js");
       } catch (ex) {
         /* Unable to load system Microformats - use builtin */
       }
おしいなぁ...作者。もしくは開発時はバギーだったかな?
実際の作業としては「operator.jar」を解凍し上記パッチを当てた(もしくは手編集)後に再度zip(拡張子jar)化すればOK。見事以前までのmicroformat Operatorが帰ってきました。
相変わらずウチのサイトはmicroformatsだらけですが...
bigsky-microformats-20080325

ところでFirefox3で扱えるmicroformats、「Describing microformats in JavaScript - MDC」を見るとどうやら自前でmicroformatの定義が出来る様です。今後draftとして拡張されていくであろうmicroformatsへの配慮ですかね。せっかくmicrosummaryのOperatorプラグイン作ってたのに、こっちの方向で作り直しか?

で、さらにドキュメントの例を見ていると
var adr_definition = {
  mfVersion: 0.8,
  mfObject: adr,
  className: "adr",
  properties: {
    "type" : {
      plural: true,
      types: ["work", "home", "pref", "postal", "dom", "intl", "parcel"]
    },
    "post-office-box" : {
    },
    "street-address" : {
      plural: true
    },
    "extended-address" : {
    },
    "locality" : {
    },
    "region" : {
    },
    "postal-code" : {
    },
    "country-name" : {
    }
  }
};
という記述が...。これOperatorのソースコードのままだね。ってことはOperatorのソースをFirefox3に持ってったのかな?
とにかく簡単に拡張出来そうな仕組みなので、しばらく追ってみる。

2008/03/24

はてな
たしかにコレ、やばいっす。
ku spreadsheetとつながってるってやばいじゃんこれspreadsheetをバックエンドdbにしていろいろできるってことでしょ
ku's post on twitter
使い方次第では、結構強力な物になりそうな気がする。
ちなみに
F's Garage:iPhone SDKを読み解くのに必須! Google AJAX Language APIを使ったブックマークWidget作った。
Google AJAX Language APIは、document.writeで翻訳機能読み込みのscript要素コードを出力するようにできており、ブックマークレットには必須の遅延ロードができないようなので、なんだかいろいろ苦労しちゃいました。
多分以下の様にすれば行けるはず。(jsapiのクエリパラメータ「callback」と、loadの第三引数「callback」)
wikiも確かに管理しやすいかもしれないけど、Google SpreadSheetも可能性があると思う。
ちなみに今回作ったSITEINFOは簡単な物なので、「ネタフル」と「IDEA * IDEA」くらいしかない。
google-spreadsheets-siteinfo
あと、クエリのfrom区には「sheet1」とか使えるのが分かった。
以下、Google SpreadSheetからSITEINFOを読み込むサンプル
var siteinfo = [];
function handleQueryResponse(response) {
    var data = response.getDataTable();
    if (!data || response.isError()) {
        alert(response.getMessage() + ':' + response.getDetailedMessage());
        return;
    }
    for (var row = 0; row < data.getNumberOfRows(); row++) {
        siteinfo.push({
            'name'  : data.getFormattedValue(row, 0),
            'link'  : data.getFormattedValue(row, 1),
            'url'   : data.getFormattedValue(row, 2),
            'xpath' : data.getFormattedValue(row, 3),
            'base'  : data.getFormattedValue(row, 4)
        });
    }
    var html = '';
    for (var n = 0; n < siteinfo.length; n++) {
        html += '<b><a href="' + siteinfo[n].link + '">' + siteinfo[n].name + '</a></b><br />'
            html += '<blockquote' + '><' + 'pre>';
        html += '<b>url</b>:' + siteinfo[n].url + '<br />';
        html += '<b>xpath</b>:' + siteinfo[n