Skip to content

Instantly share code, notes, and snippets.

View nobuh's full-sized avatar

Nobuhiro Hatano nobuh

View GitHub Profile
@nobuh
nobuh / iptables
Last active August 29, 2015 14:02
/etc/sysconfig/iptables basic template
*filter
# deny all inbound
:INPUT DROP [0:0]
:FORWARD DROP [0:0]
# accept all outbound
:OUTPUT ACCEPT [0:0]
# accept already connected sessions
@nobuh
nobuh / nginx.conf
Created August 26, 2014 02:17
Zone Apex / Naked Domain / Root Domain redirect to the www subdomain by nginx
# Zone Apex / Naked Domain / Root Domain redirect to the www subdomain by nginx
# Here is a part of nginx config file
#
# For example on Debian 6 (Squeeze)
# /etc/nginx/site-available/default
#
server {
listen 80; ## listen for ipv4
listen [::]:80 default ipv6only=on; ## listen for ipv6
@nobuh
nobuh / cowbuilder_container.md
Last active August 29, 2015 14:06
cowbuilder でコンテナ風に使えないかやってみた

cowbuilder でコンテナ風に使えないかやってみた

  • 不安定版(sid)のイメージを /var/cache/pbuilder/base.cow に作成する
sudo cowbuilder --create
  • Debian 6.0 (squeeze) のイメージを /var/cache/pbuilder/squeeze.cow に作成する
sudo cowbuilder --create --distribution squeeze --basepath /var/cache/pbuilder/squeeze.cowil
@nobuh
nobuh / space_to_newline.sh
Created September 25, 2015 04:51
スペースを改行に変換する
tr ' ' '\n'
@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 / 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