タグ

ブックマーク / murky-satyr.hatenadiary.org (8)

  • WeakMap uniq - ellaneous

    [http://wiki.ecmascript.org/doku.php?id=harmony:weak_maps:title=WeakMap] で uniq を書いて [https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/indexOf:title=indexOf] 版と比較してみた。 Primitive を受け付けない*1ので Object.create(null) と併用する。 https://gist.github.com/1005856 ちゃんと速いようで安心。 *1:WeakMap().set(1) //=> Error: value is not a non-null object

    WeakMap uniq - ellaneous
    teramako
    teramako 2011/06/03
    『WeakMap で uniq を書いて indexOf 版と比較』
  • Re: E4X - ellaneous

    x.list.(function::hasOwnProperty("@id") && @id == "b"); http://teramako.github.com/doc/modest-20100904/index.html#(10) .(function::child("@id") == "b") で良さそう。 さらにゴルフするなら .(*.parent().@id == "b") とか。 xlist[i] = <span>hoge</span>; http://teramako.github.com/doc/modest-20100904/index.html#(18) 初耳。jsPerf で試したら確かに速い。 要素数以上の数字を指定すれば追加になる*1ので添え字を増やさずとも適当に大きい数((上限 4294967294 == -2 >>> 0))でいい。 Unfocused には

    Re: E4X - ellaneous
    teramako
    teramako 2010/09/05
    child("@id")でOKという指摘 // フィルタはメモリ効率が悪いらしい
  • typeof / / - ellaneous

    ECMAScript 4 discussion - Callable RegExp vs. typeof Bug 61911 - typeof(/regExp/) should return "object", not "function" (WebKit) Bug 28117 - Native JSON.stringify does not omit functions Bug 582717 - Make regular expressions not callable engine\code typeof/ / / /(0) Function.call.call(/ /,/ /,0) SpiderMonkey (Fx3.6) "object" null TypeError*1 Carakan (Op10.6) "object" null TypeError*2 v8 (GC5) "fu

    typeof / / - ellaneous
  • 464B tetris - ellaneous

    <body onkeydown=K=event.which-38 onload="Z=X=[B=A=12],function Y(){for(q=c=i=4;f =i--*K;c-=!Z[h+(K+6?p+K:Y[i]=p*A-(p/9|0)*145)])p=B[i];for(c?0:K+6?h+=K:t?B=Y:0;i =K=q--;f+=Z[A+p])k=X[p=h+B[q]]=1;if(f|B)for(Z=X,X=[l=228],B=[~[10,23,-3,-14,A][t =++t%7],0,1,t-6?-A:2];l--;h=5)for(l%A?l-=l%A*!Z[l]:(P+=k++,c=l+=A);--c>A;)Z[c]=Z [c-A];h+=A;for(S=P;i<240;S+=X[i]|(X[i]=Z[i]|=++i%A<2|i>228)?~-i%A?'■':'<br>■

    464B tetris - ellaneous
    teramako
    teramako 2010/08/02
    ゴルフ
  • lmnpop - ’ellaneous

    https://addons.mozilla.org/addon/196133 / GitHub - satyr/lmnpop: Pops elements as resizable windows. 説明 DOM 要素をポップアップ 詳細 親切な誰かが書いてくれた 用途 Flash 観賞等 経緯 単に open('data:text/html,'+ parent.innerHTML) とかするとベースが browser.xul になり、他の拡張の overlay がくっついてきて重いので <browser/> のみを配置した .xul で代用する。当初これを data:application/vnd.mozilla.xul+xml にして .uc.js で済ませようと思っていたが、 persist が効いてくれなかったので諦めて拡張に。 備考 alwaysRaised の挙動が酷い。他ダ

    lmnpop - ’ellaneous
    teramako
    teramako 2010/07/16
    flash動画等を別ウインドウで開くアドオン。軽くて良い感じ
  • insertText - ellaneous

    テキストボックス((textarea, input:-moz-any(:not([type]), [type=text], [type=password]))) tbox のカーソル位置へ文字列 text を挿入したいとき,HTMLTextAreaElement の貧弱な機能で実現するとこんな風になる。 var {value, selectionStart, selectionEnd} = tbox; tbox.value = value.slice(0, selectionStart) + text + value.slice(selectionEnd); tbox.selectionEnd = selectionStart + text.length; 一見うまくいくようだが,スクロール位置がリセットされるしアンドゥも狂う。 自然にやるには chrome 権限が必要。*1 const

    insertText - ellaneous
    teramako
    teramako 2010/05/17
    textarea.QueryInterface(Ci.nsIEditor).QueryInterface(Ci.nsIPlainTextEditor)してinsertText
  • uc - ellaneous

    http://github.com/satyr/uc (AMO) userChromeJS もどきに subscriptoverlayloader.js 相当の機能を付けた拡張。 いい加減 XUL を覚えねばと思い*1,習作として作成。 ○ 読み込み元を複数指定可能*2 若干高速 メタ情報をいちいち読まない(起動時とファイル更新時のみ) 体が jsm 子孫ウィンドウも対象 @include/@exclude で正規表現 先頭に ~ 名前が短い × Firefox 3.5+ のみ http://bugzil.la/330458 対応がおざなり*3 *1:Ubiquity はほぼ XUL-less *2:プロファイル間でスクリプト共有したいというのが主な作成動機 *3:個人的に *.uc.xul をほとんど使わないので

    uc - ellaneous
  • escape(_,0) - ellaneous

    SpiderMonkey の escape() は第二引数にビットフラグを受け取る。 AmazonAPI 用にこんな関数を書いてて気付いた。 function amazEnc(str) encodeURIComponent(str).replace(/[!\'()]+/g, escape).replace(/[*]/g, '%2A'); amazEnc('unescape(_)') //=> Error: invalid string escape mask 8 この 8 は replace() が escape() に渡したマッチ位置。 該当ソースコードを見てみる。 /* * Contributions from the String class to the set of methods defined for the * global object. escape and un

    escape(_,0) - ellaneous
    teramako
    teramako 2010/03/19
    escape関数の第2引数
  • 1