Skip to content

Instantly share code, notes, and snippets.

View nobuh's full-sized avatar

Nobuhiro Hatano nobuh

View GitHub Profile
@nobuh
nobuh / httpd.js
Created July 23, 2011 13:53
node.js a tiny http server
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(1337, "127.0.0.1");
console.log('Server running at http://127.0.0.1:1337/');
@nobuh
nobuh / FindTriangle.js
Created July 29, 2011 07:48
Find maximum circumference of a triangles. An exercise of js
// Triangle.js
//
// Pick up 3 side numbers a[i] to make a triangle from n numbers.
// Find the maximum circumference of triangles.
//
// Constraints :
// 3 <= n <= 100
// 1 <= a[i] <= 10^6
var TRI = {};
@nobuh
nobuh / createObj.js
Created August 1, 2011 08:27
Create new child from an object.
if (typeof Object.create != 'function') {
Object.create = function (obj) {
var F = function () {};
F.prototype = obj;
return new F();
};
}
@nobuh
nobuh / factorial-node.js
Created August 7, 2011 22:37
Test recursive factorial on node.js
// factorial.js for node.js
BD = require("./bigdecimal"); // https://github.com/jhs/bigdecimal.js
ONE = new BD.BigDecimal.ONE;
// Usage : factorial(BD.BigDecimal("number"))
factorial = function (n) {
if (n.compareTo(ONE) == 0) {
return ONE;
} else {
return n.multiply(factorial (n.subtract(ONE)));
@nobuh
nobuh / factorial.js
Created August 8, 2011 01:07
Test recursive factorial on rhino
// mathcontext & bigdecimal.js is http://stz-ida.de/index.php?option=com_content&id=18
load("mathcontext.js");
load("bigdecimal.js");
ONE = new BigDecimal("1");
// Usage : factorial(new BigDecimal("number"))
function factorial (n) {
if (n.compareTo(ONE) == 0) {
return ONE;
} else {
@nobuh
nobuh / BigInt.js
Created August 13, 2011 14:59
JavaScript Arbitrary Integer Library in the Public Domain (http://www.leemon.com/crypto/BigInt.js)
////////////////////////////////////////////////////////////////////////////////////////
// Big Integer Library v. 5.4
// Created 2000, last modified 2009
// Leemon Baird
// www.leemon.com
//
// Version history:
// v 5.4 3 Oct 2009
// - added "var i" to greaterShift() so i is not global. (Thanks to PŽter Szab— for finding that bug)
//
@nobuh
nobuh / factorial.coffee
Created August 18, 2011 09:18
BigInteger factorial in CoffeeScript
# Usage: coffee factorial.coffee _number_
bi = (require "./bigdecimal").BigInteger # github.com/jhs/bigdecimal.js
ONE = bi '1'
n = bi (process.argv[2] or= '100')
# factorial (BigInteger) returns BigInteger
factorial = (x) ->
if x.compareTo(ONE) is 0
ONE
else
@nobuh
nobuh / wozmon.asm
Created August 22, 2011 09:08
WOZ Monitor for the Apple 1
;-------------------------------------------------------------------------
;
; The WOZ Monitor for the Apple 1
; Written by Steve Wozniak 1976
;
;-------------------------------------------------------------------------
.CR 6502
.OR $FF00
.TF WOZMON.HEX,HEX,8
@nobuh
nobuh / nakedhttp.js
Created September 1, 2011 05:48
Naked HTTP. a sample of http server in node.js
var http = require("http");
var port;
if (process.argv.length < 3) {
port = 8192;
} else {
port = process.argv[2];
}
http.createServer(function(requset, response) {
@nobuh
nobuh / readdir.js
Created September 14, 2011 06:58
readdir - node.js readdir sample
var fs = require('fs');
fs.readdir( process.argv[2], function (err, files) {
if (!err)
console.log(files);
else
throw err;
});
console.log("Fired callback.");