Skip to content

Instantly share code, notes, and snippets.

var fs = require('fs'),
path = require('path');
(function scan(dir) {
fs.readdirSync(dir).forEach(function (item) {
var stat = fs.statSync(path.join(dir, item));
if (stat.isFile()) require(path.join(dir, item));
else if (stat.isDirectory()) scan(path.join(dir, item));
});
})('./lib/some/dir');

npm start コマンドを実行すると、 package.json の script.start コマンドが実行される

"scripts": {
  "start": "NODE_ENV=production NODE_PATH=lib node --harmony_typeof --harmony"
}

http://d.hatena.ne.jp/Jxck/20120410/1334071898 Node.js の起動オプション、環境変数、npm start の話

ChangeLog を支える英語

ChangeLog を書く際によく使われる英語をまとめました。

ほとんど引用です。

基本形

@nazomikan
nazomikan / interop.md
Created February 10, 2013 07:02 — forked from domenic/interop.md

module.exports = and ES6 Module Interop in Node.js

The question: how can we use ES6 modules in Node.js, where modules-as-functions is very common? That is, given a future in which V8 supports ES6 modules:

  • How can authors of function-modules convert to ES6 export syntax, without breaking consumers that do require("function-module")()?
  • How can consumers of function-modules use ES6 import syntax, while not demanding that the module author rewrites his code to ES6 export?

@wycats showed me a solution. It involves hooking into the loader API to do some rewriting, and using a distinguished name for the single export.

This is me eating crow for lots of false statements I've made all over Twitter today. Here it goes.

@nazomikan
nazomikan / gist:3670200
Created September 7, 2012 22:19
Strip subdomain
public static function stripSubdomain($domainb) {
$tlds = array('.com','.net','.org','.biz','.ws','.in','.me','.co','.co.uk','.org.uk','.ltd.uk',
'.plc.uk','.me.uk','.edu','.mil','.br.com','.cn.com','.eu.com','.hu.com','.no.com','.qc.com',
'.sa.com','.se.com','.se.net','.us.com','.uy.com','.ac','.co.ac','.gv.ac','.or.ac','.ac.ac',
'.af','.am','.as','.at','.ac.at','.co.at','.gv.at','.or.at','.asn.au','.com.au','.edu.au',
'.org.au','.net.au','.id.au','.be','.ac.be','.br','.adm.br','.adv.br','.am.br','.arq.br',
'.art.br','.bio.br','.cng.br','.cnt.br','.com.br','.ecn.br','.eng.br','.esp.br','.etc.br',
'.eti.br','.fm.br','.fot.br','.fst.br','.g12.br','.gov.br','.ind.br','.inf.br','.jor.br',
'.lel.br','.med.br','.mil.br','.net.br','.nom.br','.ntr.br','.odo.br','.org.br','.ppg.br',