Skip to content

Instantly share code, notes, and snippets.

View tpai's full-sized avatar
🌴
On vacation in Spain

Tony Pai tpai

🌴
On vacation in Spain
View GitHub Profile
@tpai
tpai / react-dom-umd.js
Created January 5, 2018 04:23
react-dom-umd
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('react')) :
typeof define === 'function' && define.amd ? define(['react'], factory) :
(global.ReactDOM = factory(global.React));
}(this, (function (React) {
@tpai
tpai / parcel_bundle.js
Created January 9, 2018 05:03
parcel_bundle
// modules are defined as an array
// [ module function, map of requires ]
//
// map of requires is short require name -> numeric require
//
// anything defined in a previous bundle is accessed via the
// orig method which is the require for previous bundles
// eslint-disable-next-line no-global-assign
require = (function (modules, cache, entry) {
@tpai
tpai / jest-cheatsheet.md
Last active September 28, 2020 12:01
paste jest cheatsheet
@tpai
tpai / with-without-cors.md
Last active March 23, 2018 07:52
In the present, web services almost build based on microservice architecture, separate front end node app and back end api, this will cause cors issue while developing and distributing production, that's go through some basic solution for dealing wit

CORS solution

In the present, web services almost build based on microservice architecture, separate front end node app and back end api, this will cause cors issue while developing and distributing production, that's go through some basic solution for dealing with cors.

API server CORS enabled

By default json-server is launch with cors enabled, so directly fetch data from API server.

API server CORS disabled

const mouseDownEvent = document.createEvent('MouseEvents');
mouseDownEvent.initEvent('mousedown', true, true);
let activeSquares = [];
function obsRoot() {
const root = document.getElementsByClassName('squares')[0];
const rootObserver = new MutationObserver((mutations) => mutations.map(mutation => {
obsSquares();
}));
@tpai
tpai / index.jsx
Created May 27, 2018 16:13
React component with Google API integration
/* global document, gapi, Promise */
import React, { PureComponent } from 'react';
class App extends PureComponent {
constructor(props) {
super(props);
this.state = { gapiReady: false, values: {} };
}
initGoogleAPI = () => {
@tpai
tpai / fillParamsIntoPath.js
Last active June 6, 2018 04:14
Replace route placeholder with actual params.
function fillParamsIntoPath (path, ...params) {
let i = -1;
return path.replace(/\/\:\w{1,}/ig, () => {
i += 1;
return `\/${params[i]}`;
});
}
console.log(fillParamsIntoPath('https://localhost:3000/api/members/:id', 1));
console.log(fillParamsIntoPath('/api/members/:member_id/friends/:friend_id', 1, 2));
日期 不重複瀏覽量
6/2 41,227
6/3 303,348
6/4 193,096
6/5 77,828
6/6 32,123
6/7 16,969
6/8 9,360
@tpai
tpai / pokemon.md
Last active September 14, 2018 09:40
pokemon index
[{"id":1,"jp":"フシギダネ","en":"Bulbasaur","tw":"妙蛙種子"},{"id":2,"jp":"フシギソウ","en":"Ivysaur","tw":"妙蛙草"},{"id":3,"jp":"フシギバナ","en":"Venusaur","tw":"妙蛙花"},{"id":4,"jp":"ヒトカゲ","en":"Charmander","tw":"小火龍"},{"id":5,"jp":"リザード","en":"Charmeleon","tw":"火恐龍"},{"id":6,"jp":"リザードン","en":"Charizard","tw":"噴火龍"},{"id":7,"jp":"ゼニガメ","en":"Squirtle","tw":"傑尼龜"},{"id":8,"jp":"カメール","en":"Wartortle","tw":"卡咪龜"},{"id":9,"jp":"カメックス","en":"Blastoise","tw":"水箭龜"},{"id":10,"jp":"キャタピー","en":"Caterpie","tw":"綠毛蟲"},{"id":11,"jp":"トランセル","en":"Metapod","tw":"鐵甲蛹"},{"id":12,"jp":"バタフリー","en":"Butterfree","tw":"巴大蝴"},{"id":13,"jp":"ビードル","en":"Weedle","tw":"獨角蟲"},{"id":14,"jp":"コクーン","en":"Kakuna","tw":"鐵殼昆"},{"id":15,"jp":"スピアー","en":"Beedrill","tw":"大針蜂"},{"id":16,"jp":"ポッポ","en":"Pidgey","tw":"波波"},{"id":17,"jp":"ピジョン","en":"Pidgeotto","tw":"比比鳥"},{"id":18,"jp":"ピジョット","en":"Pidgeot","tw":"比鵰"},{"id":19,"jp":"コラッタ","en":"Rattata","tw":"小拉達"},{"id":20,"jp":"ラッタ","en":"Raticate","tw":"拉達"},{"id":21,"jp":"オニスズメ","en":"Spearow","
const updateTitle = title => {
return async dispatch => {
dispatch({ type: UPDATE_TITLE });
try {
const res = await fetch(url, {
method: 'PUT',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},