Skip to content

Instantly share code, notes, and snippets.

View shinout's full-sized avatar
🏠
Working from home

Shin Suzuki shinout

🏠
Working from home
View GitHub Profile
@shinout
shinout / .editorconfig
Created July 1, 2015 12:29
.editorconfig
root = true
[*]
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = space
@shinout
shinout / copy.coffee
Created March 3, 2015 09:24
copying class in CoffeeScript
copyClass = (klass) ->
newKlass = (new Function("""
return function (call) {
return function #{klass.name}() {
return call(this, arguments)
};
};
""")())(Function.apply.bind(klass))
for own key, value of klass
@shinout
shinout / strongloop
Last active August 29, 2015 14:15
npm install strongloop on OS X (10.10.2)
shinout ~ shinout$ npm install strongloop
> heapdump@0.2.10 install /Users/shinout/node_modules/strongloop/node_modules/strong-supervisor/node_modules/heapdump
> node-gyp rebuild
CXX(target) Release/obj.target/heapdump/src/heapdump.o
CXX(target) Release/obj.target/heapdump/src/platform-posix.o
SOLINK_MODULE(target) Release/heapdump.node
SOLINK_MODULE(target) Release/heapdump.node: Finished
@shinout
shinout / sync_async_fs.coffee
Created July 16, 2014 15:15
comparing performance of fs.readSync() with that of fs.read()
N = 100000
READ_SIZE = 100
fs = require "fs"
fd = fs.openSync __filename, "r"
i = 0
console.time "sync"
while i < N
@shinout
shinout / parse_3_byte_uint.coffee
Created July 11, 2014 12:48
benchmark: parsing 3byte-uint in CoffeeScript
rt = require "random-tools" # https://github.com/shinout/random-tools
N = 1000000
d = []
i = 0
# data preparation
while i < N
n = rt.randomInt(256 * 256 * 256 - 1)
b = new Buffer(3)
fs = require("fs")
rstream = fs.createReadStream process.argv[2]
wstream = fs.createWriteStream(process.argv[3])
rstream.setEncoding "utf-8"
ended = false
piping = ->
return if ended
d = rstream.read()
return rstream.once "readable", read_write if d is null
@shinout
shinout / smith-waterman.coffee
Created June 5, 2014 07:31
Smith-Waterman Algorithm in CoffeeScript
GAP = -1
MISMATCH = -1
MATCH = 1
class Cell
constructor: (i,j)->
@p1 = i
@p2 = j
@pointers = []
@score = 0
@shinout
shinout / nw.js
Created May 29, 2014 15:00
Needleman-Wunsch algorithm in JS
const UP = 1;
const LEFT = 2;
const UL = 4;
function nw(s1, s2, op) {
op = op || {};
const G = op.G || 2;
const P = op.P || 1;
const M = op.M || -1;
var mat = {};
@shinout
shinout / least_square.coffee
Created May 15, 2014 16:45
least square (最小二乗法)
least_square = (dataset)->
n = dataset.length
sigma_xy = 0
sigma_x = 0
sigma_y = 0
sigma_xsq = 0
for data in dataset
x = data[0]
y = data[1]
@shinout
shinout / steepest_descent.coffee
Created April 28, 2014 15:34
steepest descent method
# 最急降下法
steepest = (f, alpha, x0)->
alpha = 1/2 * (Math.abs Math.random()) + 0.1 if typeof alpha isnt "number"
alpha = Math.abs alpha
x0 = Math.random() if typeof x0 isnt "number"
fx0 = f(x0)
x = x0 + 0.01 # for approximating gradient
loop