efcl’s blog

GitHub英語のメモや引用が中心です。

(Node.js) 0.8のサポート外す時

drop 0.8 from travis

引用元: drop 0.8 from travis · 87bf97a · mozilla/sweet.js.

他の言い回し

Node 0.8 no longer supported

Update: Node 0.8 no longer supported (fixes #734) · e3432cc · roadhump/eslint

もう既にサポートしてないよ と伝える場合

Bower doesn't officially support node 0.8 any more either.

npm install doesn't work anymore with node 0.8 with bower version v1.2.8 · Issue #1315 · bower/bower

戻す場合

Restore node.js 0.8 compatibility

Restore node.js 0.8 compatibility · d1dff45 · expressjs/timeout

JSでQueueとして配列を使った場合と自作したQueue(linked-list)での最適化の話

2 Since you're queuing functions to be executed, you can use a more efficient data structure than a JS array. A queue that has only enqueue, dequeue and isEmpty operations can have all these operations be O1. A JS array probably doesn't behave that way. See http://jsperf.com/jsqueue-vs-array

引用元: Benchmark NPO's performance against other libs · Issue #8 · getify/native-promise-only.

JavaScriptの配列でpush()shift()のみでデータを出し入れするデータ構造のケースで、シンプルにそれ用のQueueを実装するとJavaScriptエンジンの最適化が効きやすい O(1)の処理

iOSのWebViewとSafariとかで計測した結果を比べたりすると分かりやすいけど、

WebViewだと最適化全然されないので微妙な結果だけど、SafariだとQueueの方が早くなる。

後、このコードだとQueueの実装はコンストラクタ関数でやってるので、

こういう繰り返し回すベンチマークだと、ここでhidden classesみたいな最適化が効いたりしてるのがでてるのかもしれないです。

デザイン的にはJavaScriptのArrayは自由なので、目的ごとにデータ構造を作るの基本良いことだと思います。

インストールしようとしたけどエラーになったのを報告する時

Got following error when trying to run npm install on Ubuntu

引用元: npm install error · Issue #19 · jiangmiao/node-curl.

I've got the error when trying to 〜〜 :

エラー内容

何かをインストールしようとしたけど、エラーでできない時等に良く使うテンプレ的な内容。

エラーログはpreにしておくのと、ブラウザなら実行ブラウザのバージョンなどをちゃんと明記するとよい。

動作的なやつなら再現してるgifとか貼ると喜ばれる。

〜というのが正しい(だが実際には気にしなくていい)

application/javascript is the correct MIME type for JavaScript (although browsers don’t really care).

via Use the correct JavaScript MIME type by mathiasbynens · Pull Request #2 · substack/browserify-handbook.

application/javascript というのがJavaScriptの正しいMIME typeだけど、ブラウザは問題なく解釈するので実際には気にしなくていいけど。