Skip to content

Instantly share code, notes, and snippets.

View heri16's full-sized avatar

heri16 heri16

View GitHub Profile
@heri16
heri16 / slice.go
Created July 26, 2021 10:50
Golang - convert slice such as []string to []interface{}
module slice
func InterfaceSlice(slice interface{}) []interface{} {
switch slice := slice.(type) {
case []string:
new := make([]interface{}, len(slice))
for i, v := range slice {
new[i] = v
}
return new
@heri16
heri16 / yup.ts
Last active June 29, 2021 05:39
Yup validate input for too many decimals to prevent ethers.js BigNumber / BigInt underflow
let decimals = 4;
const regexpDecimals = new RegExp(`^\\d*\\.{0,1}\\d{0,${decimals}}$`);
const SignupSchema = Yup.object().shape({
decimal: Yup.number().test(
'is-decimal',
'too many decimals',
value => (value + "").match(regexpDecimals),
),
});
@heri16
heri16 / ethersjs-token-bridge.ts
Last active June 29, 2021 05:39
Trigger Polygon / MATIC Token Bridge via ethers.js
// See: https://github.com/maticnetwork/matic.js/blob/master/examples/POS-client/config.js
const posRootChainManager = '0xBbD7cBFA79faee899Eaf900F13C9065bF03B1A74';
const posERC20Predicate = '0xdD6596F2029e6233DEFfaCa316e6A95217d4Dc34';
const accounts = useAccounts();
const userAddress = accounts?.[0]
const rootDaiContract = useContractContext(DAIDummyContext, 0);
const { send: approve } = useContractFunc(rootDaiContract, "approve");
@heri16
heri16 / button.tsx
Created June 29, 2021 05:30
Add network or switch network button for Metamask
interface AddEthereumChainParameter {
chainId: string; // A 0x-prefixed hexadecimal string
chainName: string;
nativeCurrency: {
name: string;
symbol: string; // 2-6 characters long
decimals: 18;
};
rpcUrls: string[];
blockExplorerUrls?: string[];
@heri16
heri16 / Structs.md
Created June 21, 2021 05:21
WIP: Solidity Object Structures for Insured Finance

Enums

  enum CoverType { SMART_PROTOCOL_FAILURE, STABLECOIN_DEVALUATION, CUSTODIAN_FAILURE, RUGPULL_LIQUIDITY_SCAM }
  enum CurrencyType { USDT, DAI, USDC }
  enum InsuredSumRule { PARTIAL, FULL }
  // enum ChainType { NON_EVM , EVM }

CoinId Decimals & CurrencyDecimals

@heri16
heri16 / .eslintrc.js
Created May 5, 2021 08:57
Example eslint config
const path = require('path')
const { readFileSync } = require('fs')
const schemaString = readFileSync(`${__dirname}/data/schema.graphql`, 'utf8')
module.exports = {
root: true,
plugins: [
// 'jest',
'@typescript-eslint',
@heri16
heri16 / .README.md
Last active April 21, 2021 08:20
Install & init terraform
# Install pgp
brew install gnupg

# Write out the hashicorp public pgp key
cat <<EOF > hashicorp.asc
-----BEGIN PGP PUBLIC KEY BLOCK-----

mQENBFMORM0BCADBRyKO1MhCirazOSVwcfTr1xUxjPvfxD3hjUwHtjsOy/bT6p9f
W2mRPfwnq2JB5As+paL3UGDsSRDnK9KAxQb0NNF4+eVhr/EJ18s3wwXXDMjpIifq
@heri16
heri16 / README.md
Last active March 9, 2025 07:55
Openwrt: Uses CAKE's diffserv4 classifications: Bulk, Best Effort, Video, Voice in combination with act_ctinfo and CONNMARK --set-dscpmark to restore DSCP classifications on ingress.

Smart Queue

Initial Setup

opkg update
opkg install luci-app-sqm kmod-sched-ctinfo iptables-mod-hashlimit ipset nano

# Install modified layer_cake to sqm-scripts
wget https://gist.githubusercontent.com/heri16/06c94b40f0d30f11e3a82166eca718f3/raw/layer_cake_ct.qos -O /usr/lib/sqm/layer_cake_ct.qos
@heri16
heri16 / upload.js
Last active February 20, 2021 10:41
Upload with cloudfront signature
const bucketName = "";
const bucketEnpoint = "";
const s3 = new AWS.S3({
params: { Bucket: bucketName },
endpoint: bucketEndpoint,
s3BucketEndpoint: true,
// s3DisableBodySigning: false,
computeChecksums: true,
correctClockSkew: true,
@heri16
heri16 / App.jsx
Last active November 12, 2020 13:10
Lightweight Authenticator Component for Aws-Amplify
import React from 'react'
import { Switch, Route } from 'react-router-dom'
import { Amplify } from '@aws-amplify/core'
import { amplifyConfig } from './config'
import { AllContextProvider } from './context'
import {