Skip to content

Instantly share code, notes, and snippets.

@Calvin-Huang
Calvin-Huang / axios-validatestatus.js
Created September 16, 2022 04:41
simple example to show how to not throw the error when expected status code
const {
status,
} = await axios.get(`/foo/${id}`, {
validateStatus: status => status === 200 || status === 404,
})
@Calvin-Huang
Calvin-Huang / axios-interceptor-1.js
Created September 16, 2022 04:35
simple example to transform response from underscore to camelCase in axios interceptor
// Add a response interceptor
axios.interceptors.response.use(function (response) {
// Any status code that lie within the range of 2xx cause this function to trigger
// Do something with response data
return {
...response,
data: humps.camelizeKeys(response.data),
}
})
import { takeEvery } from 'redux-saga';
import { call, put } from 'redux-saga/effects';
// Watcher
function* watchFetchData() {
yield* takeEvery('FETCH_REQUESTED', fetchData);
}
// Worker
function* fetchData(action) {
const axios = require('axios');
async function getCycPool(address) {
const obj = {};
const resultList = await Promise.allSettled([
await axios.get('https://api.bscscan.com/api?module=proxy&action=eth_call&to=0x9634cfd96f1499990695ebbc081b4ee8d63d2e12&data=0902f1ac&tag=latest'),
await axios.get('https://api.bscscan.com/api?module=proxy&action=eth_call&to=0x9634cfd96f1499990695ebbc081b4ee8d63d2e12&data=18160ddd&tag=latest'),
await axios.get(`https://api.bscscan.com/api?module=proxy&action=eth_call&to=0x567da514637cfd7f9e1f185ae4aa163b3ebb5363&data=0xf40f0f52000000000000000000000000${address.replace(/^0x/, '')}&tag=latest`),
await axios.get(` https://api.bscscan.com/api?module=proxy&action=eth_call&to=0x567da514637cfd7f9e1f185ae4aa163b3ebb5363&data=0x1959a002000000000000000000000000${address.replace(/^0x/, '')}&tag=latest`),
await axios.get('https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&ids=cyclone-protocol'),
@Calvin-Huang
Calvin-Huang / iptables
Created March 30, 2018 03:03
Minecraft Anti-DDoS iptables configuration
*raw
:PREROUTING ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A PREROUTING -p tcp -m tcp --dport 25565 -j CT --notrack
COMMIT
*mangle
:PREROUTING ACCEPT [0:0]
:INPUT ACCEPT [0:0]
@Calvin-Huang
Calvin-Huang / nextjs_SSR_bug_sample_home_page.jsx
Last active October 2, 2020 03:17
Get user's credential before rendering to prevent showing empty username.
/* /page/home.jsx */
import axios from '@util/axios'
const Home = ({ user }) => {
return (
<h1>{user.name}</h1>
)
}
Home.getServerSideProps = async ({ req }) => {
@Calvin-Huang
Calvin-Huang / nextjs_SSR_sample_home_page.jsx
Created October 2, 2020 03:15
The sample which works fine without any shared state problems.
/* /page/home.jsx */
import { getAxios } from '@util/axios'
const Home = ({ user }) => {
return (
<h1>{user.name}</h1>
)
}
Home.getServerSideProps = async ({ req }) => {
@Calvin-Huang
Calvin-Huang / nextjs_SPA_sample_home_page.jsx
Last active October 1, 2020 12:44
The most simple and common implementation for login and request user's data with credential.
/* /page/home.jsx */
import { useState, useEffect } from 'react'
import axios from '@util/axios'
const Home = () => {
const [user, setUser] = useState({})
useEffect(async () => {
const { data } = await axios.get('https://mock.bugfree.app/api/me')
setUser(data)
})
@Calvin-Huang
Calvin-Huang / AccountKit-Comparsion.md
Last active September 10, 2019 03:58
Account Kit 優缺點整理

Account Kit - Pros & Cons

Pros

  • 不需要重新實作簡訊/Email註冊流程(PhoneNumber / Email 可擇一)
  • 集成 iOS/Android/Web SDK
  • 沒有與 Facebook 帳號做綁定(實測過沒問題) 測試用 App
  • 支援國家包含中國,詳細可見 支援 SMS 國碼一覽

Cons

  • 只能拿到 PhoneNumber/Email & AccountKit ID, 所以其他會員資料需要後補
@interface VIGP2API()
{
AnGooGeneralCallbackBlock _callBack;
}
@property AnGooGeneralCallbackBlock PushMsgCallbackBlock;
@end
static TIAESCipher *_sgAesEngineObj = nil;
@implementation VIGP2API