This file contains hidden or 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
interface SingleItemCache<R, A> { | |
cachedArg?: R[] | |
cachedValue?: A | |
} | |
export function cbCacheWrapper<R, A>(cb: Function): (...args: R[]) => A { | |
// create cache in closure | |
let singleItemCache: SingleItemCache<R, A> = {} | |
// close over a cb |
This file contains hidden or 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
// 1. Log blooms: https://web3js.readthedocs.io/en/v1.2.4/web3-utils.html?highlight=bloom#bloom-filters | |
// Specific topic you're looking for, typically topics are: | |
// Contract Event params must not be anonymous | |
// topics array: | |
// 1. topics[0] = keccak256 hashed entire signature of specific Event e.g Deposit(uint amt, address user) | |
// 2. topics[1] = keccak256 hashed 1st param i.e uint amt | |
// 3. topics[2] = keccak256 hashed 2nd param i.e address user |
This file contains hidden or 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
// Add file-loader | |
// in Webpack.dev and .prod | |
// in module.rules[] | |
{ | |
test: /\.(pdf)$/i, | |
use: { | |
loader: 'file-loader', | |
options: { |
This file contains hidden or 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
// this gist is to show how, when using BigNumber JS | |
// one can display numbers in the FE using a set precision | |
// but without the issue of (assuming always precision 4) | |
// Numbers such as e.g 1 being shown as 1.000 or | |
// 1.00001 being show as 1.000 | |
// this gist uses some typescript, just remove the typings in | |
// the function params if you're having problems | |
// using web3 v0.20 |
This file contains hidden or 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
/** | |
* EtherScan Validate Contract API | |
* URL: https://api.etherscan.io/api?module=contract&action=getabi&address=ContractAddressHere&apikey=YourApiKeyToken | |
* Checks contract address against database of approved Contracts | |
*/ | |
const apiKey = 'yourEtherScanAPIKeyHere' | |
const checkContract = (addr, ak) => | |
fetch(`https://api.etherscan.io/api?module=contract&action=getabi&address=${addr}&apikey=${ak}`) |
This file contains hidden or 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
// thanks Dmitry ^.^ | |
let dynamicIdx = 15 | |
const indexes = Array.from({ length: dynamicIdx }, (v, i) => dynamicIdx - i) | |
// spits out: | |
// [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1] |
This file contains hidden or 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
var json = { | |
heading: 'Welcome to the app!', | |
modal: { | |
message: { | |
alternate: 'Do you want to continue?', | |
default: 'Are you sure?' | |
}, | |
no: 'Cancel', | |
yes: 'Continue', | |
}, |
This file contains hidden or 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
/** Use NumGen to create a randomly sorted and filled Array to pass to quickSorter to test | |
* Can call quickSorter with numGen(<Number>) directly | |
* e.g quickSorter(numGen(500)); | |
*/ | |
/** numGen | |
* @param {number} - length | |
* @param {limit} - limit | |
* @returns {array} | |
*/ |
This file contains hidden or 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
/** Use arrGen to create a randomly sorted and filled Array to pass to quickSorter to test | |
* Can call quickSorter with numGen(<Number>) directly | |
* e.g quickSorter(numGen(500)); | |
*/ | |
/** arrGen | |
* @param {number} - length | |
* @returns {array} | |
*/ | |
const arrGen = (length, limit) => { |