This file contains hidden or 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
function idxOf(str) { | |
var results = []; | |
var idx = str.indexOf(' '); | |
while (idx >= 0 && str.length) { | |
if (idx > 0) { | |
results.push(str.slice(0, idx)); | |
} | |
str = str.slice(idx + 1); | |
idx = str.indexOf(' '); |
This file contains hidden or 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
["一","丁","七","万","丈","三","上","下","不","与","丑","且","世","丘","丙","丞","両","並","中","串","丸","丹","主","乃","久","之","乍","乎","乏","乗","乙","九","乞","也","乱","乳","乾","亀","了","予","争","事","二","云","互","五","井","亘","亙","些","亜","亡","交","亥","亦","亨","享","京","亭","亮","人","什","仁","仇","今","介","仏","仔","仕","他","付","仙","代","令","以","仮","仰","仲","件","任","企","伊","伍","伎","伏","伐","休","会","伝","伯","伴","伶","伸","伺","似","伽","佃","但","位","低","住","佐","佑","体","何","余","作","佳","併","佼","使","侃","例","侍","供","依","侠","価","侭","侮","侯","侵","侶","便","係","促","俄","俊","俗","保","信","俣","修","俳","俵","俸","俺","倉","個","倍","倒","倖","候","借","倣","値","倦","倫","倭","倶","倹","偉","偏","停","健","偲","側","偵","偶","偽","傍","傑","傘","備","催","傭","債","傷","傾","僅","働","像","僑","僕","僚","僧","僻","儀","億","儒","償","優","儲","允","元","兄","充","兆","兇","先","光","克","免","兎","児","党","兜","入","全","八","公","六","共","兵","其","具","典","兼","内","円","冊","再","冒","冗","写","冠","冥","冨","冬","冴","冶","冷","凄","准","凋","凌","凍","凝","凡","処","凧","凪","凱","凶","凸","凹","出","函","刀","刃","分","切","刈","刊","刑","列","初","判","別","利","到","制","刷","券","刺","刻" |
This file contains hidden or 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
var fork = require("child_process").fork; | |
var workers = []; | |
for (var i=0; i<6; i++) { (function(i) { | |
workers[i] = fork(__dirname + "/worker.js"); | |
workers[i].send(i); | |
})(i) } |
This file contains hidden or 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
/** | |
* | |
* iterateAsync | |
* iterate array or object asynchronously. | |
* | |
* @author shinout | |
* | |
* @param Object / Array obj : object to iterate. | |
* @param function fn : function to apply to each key, value. | |
* arguments order -> function(value, key) |
This file contains hidden or 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
var count = 0; | |
var N = 10000000; | |
var f = function(v) { | |
count++; | |
}; | |
for (var i=0; i<N; i++) process.nextTick(f); | |
process.nextTick(function() { | |
console.log(count); | |
}); |
This file contains hidden or 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
var N = 1000000; | |
process.nextTick(function nextTick(n) { | |
n = n || 1; | |
if (n < N) process.nextTick(nextTick.bind(null, ++n)); | |
else clearInterval(timeId); | |
}); | |
var timeId = setInterval(function() { | |
console.log("."); | |
}, 1000); |
This file contains hidden or 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
var list = [ | |
"部屋を掃除しろ!", | |
"部屋を片付けろ!", | |
"資料を整理しろ!", | |
"タスクを整理しろ!", | |
"メモを整理しろ!", | |
"「あとで読む」でも読んどけ!", | |
"風呂でも入っとけ!", |
This file contains hidden or 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
function fibo(n) { | |
if (n < 2) return 1; | |
var prev1 = 1, prev2 = 1, i = 2, current = 0; | |
while (i <= n) { | |
current = prev1 + prev2; | |
prev2 = prev1; | |
prev1 = current; | |
i++; | |
} |
This file contains hidden or 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://topcoder.g.hatena.ne.jp/eller/20091207 */ | |
function countTools(need) { | |
return need.join(' ').split(' ').reduce(function(sofar, v) { | |
if (!sofar.hash[v]) sofar.count++; | |
sofar.hash[v] = true; | |
return sofar; | |
}, {hash: {}, count: 0}).count; | |
} |