Skip to content

Instantly share code, notes, and snippets.

View hokaccha's full-sized avatar

Kazuhito Hokamura hokaccha

View GitHub Profile
@hokaccha
hokaccha / refinements.js
Last active December 17, 2015 03:48
JavaScript implementation of Ruby2.0 Refinements.
var Refinements = {};
Refinements.modules = {};
Refinements.register = function(name, fn) {
Refinements.modules[name] = fn;
};
Refinements.using = function() {
var args = Array.prototype.slice.call(arguments);
mocha.sinon = {
test: function(fn) {
var sandbox = sinon.sandbox.create();
if (fn.length >= 2) {
return function(done) {
var origOnError = window.onerror;
window.onerror = function() {
sandbox.restore();
mocha.sinon = {
test: function(fn) {
var sandbox = sinon.sandbox.create();
if (fn.length >= 1) {
return function(done) {
fn.call(sandbox, function(err) {
done(err);
sandbox.restore();
});
function coro(f) {
var g = f(function(x) { g.send(x) });
g.next();
}
function wait(ms, next) {
setTimeout(function() {
next('bar');
}, ms);
}
var Foo = Class.extend({
method: function() {
console.log('Hi!');
}
});
var Bar = Foo.extend({
});
var Baz = Bar.extend({
// http://ejohn.org/blog/simple-javascript-inheritance/
function Class() {}
Class.extend = function extend(props) {
var SuperClass = this;
function Class() {
if (typeof this.init === 'function') {
this.init.apply(this, arguments);
function Foo() {
if (!(this instanceof Foo)) {
throw new Error('called without new');
}
// initialize
}
var foo = Foo();
function Foo() {
'use strict';
this.prototype;
// initialize
}
var foo = Foo();
require 'test/unit'
require 'date'
def year_diff(a, b)
month_diff = (a.year * 12 + a.month) - (b.year * 12 + b.month)
month_diff -= 1 if a.month == b.month && a.day < b.day
month_diff / 12
end
@hokaccha
hokaccha / app.js
Created March 5, 2013 09:16
GRP test2
var express = require('express');
var http = require('http');
var app = express();
app.get('/', function(req, res) {
res.send(
'<body>' +
'<form action="/a" method="POST">' +
'<input type="text" name="foo">' +
'<input type="submit">' +