Skip to content

Instantly share code, notes, and snippets.

@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 December 20, 2016 11:19
client router
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
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 June 1, 2018 09:33
Create an object instead of an array
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 July 5, 2016 07:44
Higher-order component form of connectToStores
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 April 8, 2019 04:42
Loop for N times
const n = 10
Array.apply(null, Array(n)).forEach( … )
// or
[...Array(n).keys()].forEach( … )
// or
Array(n).fill().forEach( … )
/**
* http://easings.net/#easeOutCubic
*/
function easeOutCubic(t) {
const _t = t - 1;
return _t * _t * _t + 1;
}
/**
@pocotan001
pocotan001 / isHalfWidth.js
Created February 17, 2016 09:35
コードポイントから絞る簡易版。→のがちゃんとしてる https://github.com/komagata/eastasianwidth
// 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);
}
import url from 'url';
const WHITE_LIST = ['hoge.com', 'piyo.com', 'huga.com'];
/**
* 対象のサイトで iframe の埋め込みを許可するかどうか
*
* @returns {boolean}
*/
const isAllowEmbed = () => {
@pocotan001
pocotan001 / removeReactIds.js
Last active July 5, 2016 05:36
func: removeReactIds
removeReactIds() {
const children = this.el.querySelectorAll('[data-reactid]');
this.el.removeAttribute('data-reactid');
Array.prototype.forEach.call(children, (child) => {
child.removeAttribute('data-reactid');
});
}