This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const promisify = require('util.promisify'); | |
/** | |
* Promisifyはコールバックのパラメータの最初の一つしか返さない。 | |
* | |
* $ node promisify_test.js | |
* [ 'a', undefined, undefined ] | |
* { '0': 'a' } | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const co = require('co'); | |
// 0‾1秒の処理 | |
const proc = function*() { | |
const wait = Math.random(); | |
return new Promise(resolve => | |
setTimeout(function() { | |
return resolve(wait); | |
}, wait * 1000) | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; nvm環境で、npm install -g prettier | |
; M-x list-packages で nvm と prettierを追加 | |
; init.elに追加 | |
(require 'nvm) | |
(nvm-use "v6.11.0") | |
(add-hook 'js2-mode-hook 'prettier-js-mode) | |
(add-hook 'web-mode-hook 'prettier-js-mode) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<script type="application/javascript"> | |
document.addEventListener('DOMContentLoaded', function(){ | |
var elem = document.querySelector('.input'); | |
document.addEventListener('keydown', function(e) { | |
elem.textContent += JSON.stringify(e); | |
e.preventDefault(); | |
}); | |
}); | |
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;(require 'un-define) | |
(setq debug-on-error t) | |
(setenv "SSH_AUTH_SOCK" "/tmp/501/SSHKeychain.socket") | |
(setq transient-mark-mode nil) | |
(setq-default case-fold-search t) | |
(require 'package) | |
(package-initialize) | |
(add-to-list 'package-archives '("melpa" . "http://melpa.milkbox.net/packages/") t) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://csv.adaltas.com/parse/ | |
csvParse = require 'csv-parse' | |
through2 = require 'through2' | |
stream = process.stdin | |
csv = csvParse columns: true | |
stream | |
.pipe(csv) | |
.pipe through2 objectMode: true, (chunk, enc, next)-> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://developer.cybozu.co.jp/tech/?p=8757 | |
{sprintf} = require 'sprintf-js' | |
pattern = /(\w|_){1,64}@/ | |
#pattern = /(\w){1,64}@/ | |
for i in [1..64] | |
target = [1..i].reduce ((p, n)-> p + '_'), '' | |
start = process.hrtime() | |
pattern.exec(target) | |
elapsed = process.hrtime(start) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mongo dbname --quiet --eval 'db.getCollectionNames().sort().join("\n")' | |
# mongo shellの 'show collections' はJavaScriptの命令ではないので、evalに渡せない。 | |
# http://docs.mongodb.org/manual/reference/mongo-shell/#administrative-command-helpers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sinon = require 'sinon' | |
MongooseModel = require 'mongoosemodeldefinition' | |
describe 'when the mongoose document failed to save', ()-> | |
stub = null | |
before (done)-> | |
origSave = MongooseModel.prototype.save | |
createCount = 0 | |
stub = sinon.stub MongooseModel.prototype, 'save', (cb)-> | |
createCount += 1 |
NewerOlder