以下所有的API都有两种方式可调用 http://api?key=value&key2=value2 以及 http://api/key/value/key2/value
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
/** | |
* A simple co | |
* @param {Function} fn Generator Function | |
* @return {Function} callback | |
*/ | |
function co(fn) { | |
return function(done) { | |
done = done || function() {}; | |
var gen = fn(); |
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
/** | |
* 实现一个nodejs的Master-Worker的小程序,要求: | |
* 1. Master维护与cpu核数相同的Worker的数量; | |
* 2. Master接收到Worker的disconnect消息时,重启新的Worker进程; | |
* 3. Worker监听1024端口并输出“Hello World”; | |
* 4. 在Worker遇到uncaughtException时,通知Master进程并等待3s后退出 | |
*/ | |
var os = require('os'), | |
cluster = require('cluster'), |
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 get(path, obj, fb = `$\{${path}}`) { | |
return path.split('.').reduce((res, key) => res[key] || fb, obj); | |
} | |
function parseTpl(template, map, fallback) { | |
return template.replace(/\$\{.+?}/g, (match) => { | |
const path = match.substr(2, match.length - 3).trim(); | |
return get(path, map, fallback); | |
}); | |
} |
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
{ | |
(* short names for important modules *) | |
module L = Lexing | |
module B = Buffer | |
type token = | |
| STR of string | |
| INT of int | |
| ID of string | |
| PLUSEQ |
(This is a translation of the original article in Japanese by moratorium08.)
(UPDATE (22/3/2019): Added some corrections provided by the original author.)
Writing your own OS to run on a handmade CPU is a pretty ambitious project, but I've managed to get it working pretty well so I'm going to write some notes about how I did it.