gitでトラッキングされてないファイルも含めてstashする
なんとなく
$ git stash --all
ってやったら、ignoreされてるファイルも全部消えてファッってなった。
$ git stash -u # or $ git stash --include-untracked
が正しいっぽい。以下helpより。
If the --include-untracked option is used, all untracked files are also stashed and then cleaned up with git clean, leaving the working directory in a very clean state.
If the --all option is used instead then the ignored files are stashed and cleaned in addition to the untracked files.
Polymer/platform.jsでdocument.currentScriptが動かない
Web ComponetsのPolyfillのPolymer/platform.jsでHTML import使ったときに、呼び出される側のHTMLのJSのdocumentを取得したいときに、
var doc = document.currentScript.ownerDocument;
ってやればとれるらしいんだけど、これがうまくPolyfillできなくて動かないらしい。
https://github.com/Polymer/HTMLImports/blob/a2accf9e3e15ee4584196a9aa5803cd5e7535820/src/HTMLImports.js#L196-L206
ので
var doc = document._currentScript.ownerDocument;
とする必要があるらしい。
Backbone.jsでPATCHをPUTに書き換える
Backbone.jsでsaveするときに patch: true にするとPATCHメソッドになってsaveに渡した引数だけをbodyに含める(patch :true しないとmodelの全attributesをbodyにしてPUTする)んだけど、API側がPATCHメソッドに対応してなかったりPATCHメソッドを通さないproxyがあったりした場合にPATCHをPUTに強制的に書き換えたい。
こうする。
var originalSync = Backbone.sync; Backbone.sync = function(method, model, options) { if (method === 'patch') options.type = 'PUT'; return originalSync(method, model, options); };
うーん。。
angular-scenarioで特定のテストだけ実行する
- describe -> ddescribe
- it -> iit
ってすればそのテストだけ実行される。今のところアンドキュメントな気がする。
describe('foo', function() { it('xxx', function() { ... }); iit('xxx', function() { ... }); // これだけ実行する it('xxx', function() { ... }); });
git reset --hardで新規ファイルの扱い
$ git --version git version 1.8.3.2 $ touch newfile $ git status -s ?? newfile $ git reset --hard $ git status -s ?? newfile
このようにまだgitに管理されてないファイルはgit reset --hardしても削除されない。これはよい。
ただ、次のように、インデックスに追加した後にgit reset --hardするとファイルが消える。
$ git add newfile $ git status -s A newfile $ git reset --hard $ git statsu -s # no output $ ls newfile ls: newfile: No such file or directory
なんでこうなるのかイマイチよくわからない。
ちなみにcheckoutだとインデックスに追加してようがしていまいが何も影響しない。
$ git status -s ?? newfile $ git checkout HEAD . $ git status -s ?? newfile $ git add newfile $ git status -s A newfile $ git checkout HEAD . $ git status -s A newfile
新規ファイルの扱い以外は`reset --hard`と`checkout HEAD .`は同じ挙動だと思う。たぶん。
AngularJSの$httpにX-Requested-Withをつける
AngularJSでHTTP Requestする際に、1.1.1より前まではX-Requested-Withをつけてたらしいんだけど、CORSのpreflightを飛ばさないためにデフォルトでは削除したらしい。
https://github.com/angular/angular.js/issues/1004
X-Requested-Withをつけたい場合は以下のようにする。
myModule.config(function($httpProvider) { $httpProvider.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest'; });
このヘッダでXHRかどうか判断する場合がある(Railsとかも)ので注意。