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 / LICENSE
Created September 21, 2011 16:15
Topological sort in JavaScript
Copyright 2012 Shin Suzuki<shinout310@gmail.com>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
@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 / to_kana_zenkaku.js
Last active December 25, 2020 02:15
半角カナを全角カナに変換するJavaScript
/**
* 半角カナを全角カナに変換する
* 半角スペースは変換しない
* 対応がとれない濁点、半濁点は変換しない
*/
function toKanaZenkaku(str) {
// lengthの等しい2つの文字列でkey-valueをつくる
const makeMap = (str1, str2) =>
str1
.split("")
@shinout
shinout / watch-and-read.js
Created February 6, 2012 07:37
fs.watchFile() -> fs.read()
var fs = require('fs');
var filename = process.argv[2];
fs.open(filename, 'r', function(err, fd) {
fs.watchFile(filename, function(cstat, pstat) {
var delta = cstat.size - pstat.size;
if (delta <= 0) return;
fs.read(fd, new Buffer(delta), 0, delta, pstat.size, function(err, bytes, buffer) {
console.log("err", err, "delta", delta, "bytes", bytes, "buffer", buffer.toString());
});
@shinout
shinout / jis1.json
Created November 29, 2011 07:13
JIS第一水準漢字 + 常用漢字 in JSON format
["一","丁","七","万","丈","三","上","下","不","与","丑","且","世","丘","丙","丞","両","並","中","串","丸","丹","主","乃","久","之","乍","乎","乏","乗","乙","九","乞","也","乱","乳","乾","亀","了","予","争","事","二","云","互","五","井","亘","亙","些","亜","亡","交","亥","亦","亨","享","京","亭","亮","人","什","仁","仇","今","介","仏","仔","仕","他","付","仙","代","令","以","仮","仰","仲","件","任","企","伊","伍","伎","伏","伐","休","会","伝","伯","伴","伶","伸","伺","似","伽","佃","但","位","低","住","佐","佑","体","何","余","作","佳","併","佼","使","侃","例","侍","供","依","侠","価","侭","侮","侯","侵","侶","便","係","促","俄","俊","俗","保","信","俣","修","俳","俵","俸","俺","倉","個","倍","倒","倖","候","借","倣","値","倦","倫","倭","倶","倹","偉","偏","停","健","偲","側","偵","偶","偽","傍","傑","傘","備","催","傭","債","傷","傾","僅","働","像","僑","僕","僚","僧","僻","儀","億","儒","償","優","儲","允","元","兄","充","兆","兇","先","光","克","免","兎","児","党","兜","入","全","八","公","六","共","兵","其","具","典","兼","内","円","冊","再","冒","冗","写","冠","冥","冨","冬","冴","冶","冷","凄","准","凋","凌","凍","凝","凡","処","凧","凪","凱","凶","凸","凹","出","函","刀","刃","分","切","刈","刊","刑","列","初","判","別","利","到","制","刷","券","刺","刻"
@shinout
shinout / chi-square-value.js
Created July 30, 2018 14:59
Calculate chi square values from n x m table
function chiSquareValue(values, separateBy = 2) {
if (values.length % separateBy !== 0) {
throw new Error(`Illegal separation rule. values.length ${valus.length} cannot be divided by ${separateBy}.`)
}
const sum = values.reduce((acc, val) => acc + val, 0)
const rowSums = []
const colSums = []
return values.reduce((chiSq, val, i) => {
const row = Math.floor(i / separateBy)
const col = i % separateBy
/**
* @param {number} n: 正n角形
* @param {number} r: 正n角形の中心から頂点への距離
* @return Array<{x: number, y: number }>: 座標
*/
function getRectanglePoints(n, r) {
// canvasに書かれる
const thetaUnit = Math.PI * 2 / n
const points = []
@shinout
shinout / cureapp_quiz.js
Last active March 16, 2017 12:22
次のコードは警告が出ます。何行目が原因?#cureapp_quiz をつけてtweetしよう!
1 import React from 'react'
2 import { AppRegistry, StyleSheet, Text, View } from 'react-native'
3 const styles = StyleSheet.create({
4 container: {
5 flex: 1,
6 justifyContent: 'center',
7 alignItems: 'center',
8 color: '#000000',
9 backgroundColor: '#F5FCFF',
10 },
@shinout
shinout / babel-register.js
Last active July 28, 2016 06:52
babel-register.js
module.exports = require('babel-register')({
ignore: /node_modules\/(?!memo-switch)/
})
@shinout
shinout / README-ja.md
Last active July 20, 2016 06:31
npm-v2-shrinkwrap-bug

状況

  • using npm v2.15.5
  • このpackageはnode-fetchに依存
  • このpackageはis-streamにdevDependenciesとして依存
  • node-fetchencodingis-streamに依存

期待される結果

npm-shrinkwrap.jsonnode-fetch, encodingおよびis-streamを含む。