This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
# goal | |
- 在不修改 node-fetch 原始參數格式下新增兩功能 | |
1. 新增 timeout 設定且逾時自動重試 | |
2. 新增 retry 模式可指定重試次數 | |
- 所有 config{} 皆有預設值因此使用上與原始 fetch() 相同 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$$('*').forEach(e => {e.style.outline = "1px solid #" + (~~(Math.random()*(1<<24))).toString(16);e.style.outlineOffset='-1px'} ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// sample code copied from the blog: | |
// https://blog.axlight.com/posts/you-might-not-need-react-query-for-jotai/ | |
const idAtom = atom(1) | |
const dataAtom = atom( | |
// read | |
async (get) => { | |
const id = get(idAtom) | |
const res = await fetch(`https://reqres.in/api/posts/${id}`) | |
const data = await res.json() | |
return data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function foo() { | |
// throw new Error('bb') | |
return new Promise((res, rej) => { | |
setTimeout(_ => { | |
// throw new Error('bb') | |
rej('cc') | |
}, 1000) | |
}) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 前情提要:async/await 只是 Promise 的語法糖 | |
// 只要精熟 Promise 則使用 async/await 就心無罣礙 | |
// 範例 1 - 錯誤示範 | |
// main 為同步執行,不會等待 forEach 內三件 async 工作完成即先結束 | |
async function async_log(time) { | |
// 模擬這支 fn 經過 300ms 後才回應,因此是非同步函式 | |
// 想像成是 fetch() 就行 | |
return new Promise((resolve, reject) => { | |
setTimeout(_ => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let arr = [ | |
['a1', 'a2'], | |
['b1', 'b2', 'b3'] | |
] | |
let result = arr.reduce( | |
// ----------- | |
// 最外層 reduce 會依序遍歷 | |
// ['a1', 'a2'] 與 ['b1', 'b2', 'b3'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fetch = require('node-fetch') | |
const fs = require('fs-extra') | |
const { execSync } = require('child_process') | |
const main = async () => { | |
const query = `nasa,cycling,surfing,underwater,swimming` | |
const size = `1` | |
const order = `latest` | |
const orientation=`landscape` | |
const photoName = 'photo.png' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
useHotkey(['Meta', 'c'], () => { | |
console.log( `要跑 1`, ) | |
}) | |
useHotkey(['ctrl', 'c'], () => { | |
console.log( `要跑 2`, ) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
PixelRatio, | |
Dimensions, | |
useWindowDimensions | |
} from 'react-native' | |
const to = n => Number(n.toFixed(2)) | |
const { width, height } = Dimensions.get('window') | |
// 將短的那邊視為 width |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function matrixArrayToCssMatrix(array) { | |
return "matrix3d(" + array.join(',') + ")"; | |
} | |
function multiplyMatrixAndPoint(matrix, point) { | |
//Give a simple variable name to each part of the matrix, a column and row number | |
var c0r0 = matrix[0], | |
c1r0 = matrix[1], | |
c2r0 = matrix[2], |
NewerOlder