Skip to content

Instantly share code, notes, and snippets.

View nakamura-to's full-sized avatar

Toshihiro Nakamura nakamura-to

View GitHub Profile
@nakamura-to
nakamura-to / gist:1574872
Created January 7, 2012 14:26
dynamic object in Soma
open System
open Soma.Core
let config =
{ new MsSqlConfig() with
member this.ConnectionString = "Data Source=.\SQLEXPRESS;Initial Catalog=Soma.Tutorial;Integrated Security=True" }
let person = dynamic config.Dialect
person?name <- "hoge";
person?age <- 20;
@nakamura-to
nakamura-to / gist:1604587
Created January 13, 2012 03:43
prototype chain
var assert = require('assert');
// Object -> Function.prototype -> Object.prototype -> null
assert.strictEqual(Object.__proto__, Function.prototype);
assert.strictEqual(Function.prototype.__proto__, Object.prototype);
assert.strictEqual(Object.prototype.__proto__, null);
// Function -> Function.prototype -> Object.prototype -> null
assert.strictEqual(Function.__proto__, Function.prototype);
assert.strictEqual(Function.prototype.__proto__, Object.prototype);
@nakamura-to
nakamura-to / gist:1717789
Created February 1, 2012 16:16
nue v0.0.2 sample
var nue = require('nue');
var serial = nue.serial;
var serialEach = nue.serialEach;
var parallel = nue.parallel;
var parallelEach = nue.parallelEach;
var start = nue.start;
start(serial(
function () { console.log('a'); this.next(); },
function () { console.log('b'); this.next(); },
@nakamura-to
nakamura-to / gist:1842456
Created February 16, 2012 05:54
nue with CoffeeScript
nue = require('nue')
flow = nue.flow
parallel = nue.parallel
fs = require('fs')
flow(
parallel(
-> fs.readFile('path1', 'utf-8', @async())
-> fs.readFile('path2', 'utf-8', @async()))
(results) -> fs.writeFile('path3', results[0] + results[1], @async());
@nakamura-to
nakamura-to / gist:1861338
Created February 18, 2012 23:48
Function.prototype.apply and Function.prototype.call
function f(a, b, c) {
console.log(this);
console.log(a);
console.log(b);
console.log(c);
}
var context = {
name: 'context'
};
@nakamura-to
nakamura-to / gist:1873877
Created February 21, 2012 05:08
Function.prototype.call.bind
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/bind
var toArray = Function.prototype.call.bind(Array.prototype.slice);
function f() {
var array = toArray(arguments);
console.log(Array.isArray(array)); // true
}
f(1,2,3);
@nakamura-to
nakamura-to / gist:1922527
Created February 27, 2012 08:19
experimental implementation: flow.exec
var flow = require('../index').flow;
var fs = require('fs');
var hogeFlow = flow(
function (a, b) {
var self = this;
throw new Error('ERROR');
setTimeout(function () {
self.next('HELLO' + a + b);
}, 0);
@nakamura-to
nakamura-to / gist:1953568
Created March 1, 2012 22:05
functions chain
function a(x) {
console.log('a is called: ' + x);
if (this.next) {
this.next.call(null, 'aaa');
}
}
function b(x) {
console.log('b is called: ' + x);
if (this.next) {
@nakamura-to
nakamura-to / gist:2144051
Created March 21, 2012 03:30
Event emittable function
var EventEmitter = require('events').EventEmitter;
var util = require('util');
var F = function () {};
util.inherits(F, EventEmitter);
Object.getOwnPropertyNames(Function.prototype).forEach(function(e) {
F.prototype[e] = Function.prototype[e];
});
@nakamura-to
nakamura-to / gist:2144167
Created March 21, 2012 04:03
Command Pattern in JavaScript
// see http://d.hatena.ne.jp/ashigeru/20090113/1231857274
function edit(start, end, chars, buf) {
var undo = buf.val.slice(start, end);
buf.val = buf.val.slice(0, start) + chars + buf.val.slice(end);
return edit.bind(null, start, start + chars.length, undo);
}
function sequence(commands, buf) {
var undos = [];