Skip to content

Instantly share code, notes, and snippets.

Avatar
:shipit:
𒅃

Hayato Mizuno pocotan001

:shipit:
𒅃
View GitHub Profile
View pocotumblr.css
@charset "UTF-8";
/* ================================================== [ Reset ] */
* {
margin: 0;
padding: 0;
}
article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section {
display: block;
@pocotan001
pocotan001 / Route.js
Last active Dec 20, 2016
client router
View Route.js
import pathToRegexp from 'path-to-regexp'
import queryString from 'query-string'
export default class Route {
/**
* @param {string} path
* @param {Function} handler
*/
constructor (path, handler) {
this.path = path
View serialize-error.js
const error = new Error('unicorn')
const serialized = JSON.stringify(error, ['name', 'message', 'stack'])
console.log(error) // { name: 'Error', message: 'unicorn', stack: 'Error: unicorn\n at Object.<anonymous> …' }
@pocotan001
pocotan001 / reduce.js
Last active Jun 1, 2018
Create an object instead of an array
View reduce.js
const ABC = ["a", "b", "c"];
ABC.reduce((acc, key) => {
acc[key] = `${key}!`;
return acc;
}, Object.create(null));
ABC.reduce(
(acc, key) => Object.assign(acc, { [key]: `${key}!` }),
@pocotan001
pocotan001 / Store.js
Last active Jul 5, 2016
Higher-order component form of connectToStores
View Store.js
import { EventEmitter } from 'events'
import Dispatcher from '../Dispatcher'
const CHANGE_EVENT = 'change'
/**
* Extend certain stores from a this `Store` class
*/
export default class Store extends EventEmitter {
emitChange () {
@pocotan001
pocotan001 / times.js
Last active Apr 8, 2019
Loop for N times
View times.js
const n = 10
Array.apply(null, Array(n)).forEach( )
// or
[...Array(n).keys()].forEach( )
// or
Array(n).fill().forEach( )
View smoothScroll.js
/**
* http://easings.net/#easeOutCubic
*/
function easeOutCubic(t) {
const _t = t - 1;
return _t * _t * _t + 1;
}
/**
@pocotan001
pocotan001 / isHalfWidth.js
Created Feb 17, 2016
コードポイントから絞る簡易版。→のがちゃんとしてる https://github.com/komagata/eastasianwidth
View isHalfWidth.js
// Basic Latin (0000–007F) http://unicode.org/charts/PDF/U0000.pdf
// Halfwidth Katakana (FF61–FF9F) http://unicode.org/charts/PDF/UFF00.pdf
function isHalfWidth(string) {
return /[\u0000-\u007f\uff61-\uff9f]/.test(string);
}
View isAllowEmbed.js
import url from 'url';
const WHITE_LIST = ['hoge.com', 'piyo.com', 'huga.com'];
/**
* 対象のサイトで iframe の埋め込みを許可するかどうか
*
* @returns {boolean}
*/
const isAllowEmbed = () => {
@pocotan001
pocotan001 / removeReactIds.js
Last active Jul 5, 2016
func: removeReactIds
View removeReactIds.js
removeReactIds() {
const children = this.el.querySelectorAll('[data-reactid]');
this.el.removeAttribute('data-reactid');
Array.prototype.forEach.call(children, (child) => {
child.removeAttribute('data-reactid');
});
}