Skip to content

Instantly share code, notes, and snippets.

View hungdoansy's full-sized avatar
📺

Hung Doan hungdoansy

📺
View GitHub Profile

Summary

eth_estimateGas failed, eth_call (to simulate) failed but tx succeeded 🤷

eth_estimateGas (to estimate gas)

[
    {
        "jsonrpc": "2.0",
        "id": 9,
@hungdoansy
hungdoansy / shuffle.ts
Created July 24, 2023 01:47
Shuffle a list
// Source: https://stackoverflow.com/a/2450976/6812545
const shuffle = <T>(array: T[]): T[] => {
let currentIndex = array.length, randomIndex;
// While there remain elements to shuffle.
while (currentIndex != 0) {
// Pick a remaining element.
randomIndex = Math.floor(Math.random() * currentIndex);
@hungdoansy
hungdoansy / Lib.md
Created April 20, 2023 02:23
Một số thư viện có ích cho tối ưu re-renders

Nọ đội Dwarves Foundation mới đăng 1 bài viết về cấu trúc cũng như các thư viện họ dùng trong các dự án React. Có 1 cái khá thú vị là họ bảo éo thèm chơi state management lib, ví dụ như Redux, mà chỉ cần dùng Context là đủ. Bất ngờ vãi nồi. Hệ thống lớn mà ko có thằng như Redux thì phải tự optimize re-renders bằng tay. Xong hoá ra có lý do cả, họ dùng mấy thằng lib ở bên dưới đây. Cái danh sách này có thêm 1-2 cái của cùng tác giả, tiện em viết luôn.

  1. https://github.com/dai-shi/use-context-selector Khi mình có 1 context, ví dụ như:
const contextValue = {
  count: 0,
  text: "hehe"

File package.json

    {
    "main": "index.js",
    "script": {
        "build": "babel src -d build --copy-files",
        "start": "rm -rf build && yarn build && node build/index.js"
    },
 "dependencies": {
@hungdoansy
hungdoansy / Dockerfile
Last active October 20, 2022 03:45
Setting up a custom domain for your local apps, with port-forwarding
FROM nginx
COPY ./nginx.conf /etc/nginx/conf.d/default.conf
@hungdoansy
hungdoansy / renew-gpgkey.md
Created August 16, 2022 08:11 — forked from krisleech/renew-gpgkey.md
Renew Expired GPG key

Renew GPG key

Given that your key has expired.

$ gpg --list-keys
$ gpg --edit-key KEYID

Use the expire command to set a new expire date:

@hungdoansy
hungdoansy / main.ts
Created July 5, 2022 06:02
Call a contract method at a specific block using ethers.js
// Example of using ethers.js to interact with a smart contract
// Call a contract method at a specific block
// This example is to get rate of a token at a block
import { ethers } from "ethers"
import BigNumber from "bignumber.js"
// prettier-ignore
const oracleABI = '[{"inputs":[{"internalType":"contract MultiWrapper","name":"_multiWrapper","type":"address"},{"internalType":"contract IOracle[]","name":"existingOracles","type":"address[]"},{"internalType":"enum OffchainOracle.OracleType[]","name":"oracleTypes","type":"uint8[]"},{"internalType":"contract IERC20[]","name":"existingConnectors","type":"address[]"},{"internalType":"contract IERC20","name":"wBase","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"contract IERC20","name":"connector","type":"address"}],"name":"ConnectorAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"contract IERC20","name":"connector","type":"address"}],"name":"
@hungdoansy
hungdoansy / normalize_string.go
Created June 29, 2022 08:43 — forked from nvtuan305/normalize_string.go
golang: normalize string (include Vietnamese)
package main
import (
"fmt"
"golang.org/x/text/runes"
"golang.org/x/text/transform"
"golang.org/x/text/unicode/norm"
"strings"
"unicode"
)
@hungdoansy
hungdoansy / GUIDE.md
Last active June 16, 2022 03:40
Deploy a subgraph guide

Deploy Subgraph guide (on hosted service)

  1. Go to https://thegraph.com/hosted-service/, register a new account using your Github account
  2. Go to https://thegraph.com/hosted-service/dashboard, -> Add Subgraph, then fill the information. Use: Test Uniswap Graph for name
  3. Grab your subgraph id. If it is https://thegraph.com/hosted-service/subgraph/hungdoansy/uniswap-v2-experiment, grab hungdoansy/uniswap-v2-experiment
  4. Clone an example repo or create a new one from CLI git clone [email protected]:hungdoansy/test-the-graph.git test-uniswap-graph
  5. cd test-uniswap-graph
  6. yarn to install all dependencies
@hungdoansy
hungdoansy / index.js
Last active January 17, 2022 03:38
Display built time in front end projects (I use React to illustrate)
console.log(`Built time: %c${new Date(Number(process.env.REACT_APP_BUILT_TIME) * 1000)}`, "color: #bada55");