Skip to content

Instantly share code, notes, and snippets.

@typoerr
typoerr / closure.js
Created February 9, 2016 06:40
Closure基礎
/*---------------------------------------------------------
* Closure
* ----------------------------------------------------------
* Closureは関数の閉じられたScopeの中でprivateな変数を定義すること
* 関数の中でのみ変数の更新を許可し、変数の状態を保持する
* */
function createCounter() {
// 外部からアクセスできない変数
@typoerr
typoerr / observer.js
Last active July 12, 2016 06:13
Observerパターン
/*-------------------------------------
* Observerパターン
* -------------------------------------
* Observerクラスに監視者を登録
* 通知者がイベントを通知
* 監視者はイベントを受け取り、目的を実行する
*
*
* ### 以下はとても単純なObserverパターンの例 ###
* Observerクラスは関数を配列に格納し、triggerで格納している関数を実行する
@typoerr
typoerr / template.webpack.config.js
Created February 28, 2016 13:53
webpack.config.jsのテンプレート
var WebpackNotifierPlugin = require('webpack-notifier');
var ExtractTextPlugin = require("extract-text-webpack-plugin");
module.exports = {
devtool: 'inline-source-map',
entry: './src/js/index.js',
output: {
path: "./dist",
filename: "bundle.js"
},
{
"always-semicolon": true,
"remove-empty-rulesets": false,
"block-indent": 2,
"color-case": "lower",
"color-shorthand": true,
"element-case": "lower",
"eof-newline": true,
"leading-zero": false,
"space-after-colon": 1,
@typoerr
typoerr / smooth_scroll.js
Created June 4, 2016 01:02
smooth_scroll.js
/*
参考: [javascript - ScrollTo with animation - Stack Overflow](http://stackoverflow.com/questions/12199363/scrollto-with-animation)
*/
window.requestAnimFrame = (function () {
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
function (callback) {
window.setTimeout(callback, 1000 / 60);
@typoerr
typoerr / replaceTextRange.js
Created June 12, 2016 02:31
replaceTextRange()
function replaceTextRange(str, start, end, substitute) {
return str.substring(0, start) + substitute + str.substring(end);
}
@typoerr
typoerr / remark-node-depth.js
Created June 12, 2016 06:30
ASTを再帰的に探索してnodeDepthをつけるremark plugin
/**
* 再帰的にchildren nodeを探索してnodeにnodeDepthを付ける
*
* @param {Array} children - node chldren
* @param {Number} depth - childrenのnodeDepth数
*/
function attachNodeDepth(children, depth) {
for (const node of children) {
node.nodeDepth = depth;
if (node.children) attachNodeDepth(node.children, depth + 1);
@typoerr
typoerr / .csscomb.json
Created October 31, 2016 04:28
csscomb.json
{
"always-semicolon": true,
"block-indent": 4,
"color-case": "lower",
"color-shorthand": true,
"element-case": "lower",
"eof-newline": true,
"leading-zero": false,
"quotes": "single",
"remove-empty-rulesets": false,
@typoerr
typoerr / r-dom.d.ts
Last active December 31, 2016 23:07
[WIP]r-dom.d.ts
declare module 'r-dom' {
import {
ReactDOM,
ReactElement,
ReactNode,
Attributes,
SFC,
ClassType,
ClassicComponent,
ComponentState,
@typoerr
typoerr / unified.d.ts
Last active February 26, 2017 01:48
unified.d.ts
/*
[wooorm/unified: ☔ Text processing umbrella: Parse / Transform / Compile](https://github.com/wooorm/unified)
version: 6.0.1
*/
declare module 'unified' {
export = processor
/* processor function */